samlify 2.12.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +1 -1
  2. package/build/src/api.js +41 -3
  3. package/build/src/api.js.map +1 -1
  4. package/build/src/binding-post.js +236 -182
  5. package/build/src/binding-post.js.map +1 -1
  6. package/build/src/binding-redirect.js +303 -215
  7. package/build/src/binding-redirect.js.map +1 -1
  8. package/build/src/binding-simplesign.js +285 -137
  9. package/build/src/binding-simplesign.js.map +1 -1
  10. package/build/src/entity-idp.js +130 -47
  11. package/build/src/entity-idp.js.map +1 -1
  12. package/build/src/entity-sp.js +81 -39
  13. package/build/src/entity-sp.js.map +1 -1
  14. package/build/src/entity.js +100 -62
  15. package/build/src/entity.js.map +1 -1
  16. package/build/src/extractor.js +118 -151
  17. package/build/src/extractor.js.map +1 -1
  18. package/build/src/flow.js +100 -96
  19. package/build/src/flow.js.map +1 -1
  20. package/build/src/libsaml.js +315 -259
  21. package/build/src/libsaml.js.map +1 -1
  22. package/build/src/metadata-idp.js +60 -30
  23. package/build/src/metadata-idp.js.map +1 -1
  24. package/build/src/metadata-sp.js +51 -41
  25. package/build/src/metadata-sp.js.map +1 -1
  26. package/build/src/metadata.js +47 -43
  27. package/build/src/metadata.js.map +1 -1
  28. package/build/src/options.js +73 -0
  29. package/build/src/options.js.map +1 -0
  30. package/build/src/urn.js +28 -1
  31. package/build/src/urn.js.map +1 -1
  32. package/build/src/utility.js +140 -85
  33. package/build/src/utility.js.map +1 -1
  34. package/build/src/validator.js +27 -10
  35. package/build/src/validator.js.map +1 -1
  36. package/package.json +16 -5
  37. package/types/src/api.d.ts +33 -3
  38. package/types/src/binding-post.d.ts +67 -34
  39. package/types/src/binding-redirect.d.ts +58 -31
  40. package/types/src/binding-simplesign.d.ts +77 -21
  41. package/types/src/entity-idp.d.ts +40 -31
  42. package/types/src/entity-sp.d.ts +37 -27
  43. package/types/src/entity.d.ts +71 -77
  44. package/types/src/extractor.d.ts +31 -22
  45. package/types/src/flow.d.ts +24 -2
  46. package/types/src/libsaml.d.ts +172 -118
  47. package/types/src/metadata-idp.d.ts +27 -11
  48. package/types/src/metadata-sp.d.ts +29 -19
  49. package/types/src/metadata.d.ts +59 -34
  50. package/types/src/options.d.ts +37 -0
  51. package/types/src/types.d.ts +250 -24
  52. package/types/src/urn.d.ts +7 -0
  53. package/types/src/utility.d.ts +139 -90
  54. package/types/src/validator.d.ts +21 -0
  55. package/.circleci/config.yml +0 -98
  56. package/.editorconfig +0 -19
  57. package/.github/FUNDING.yml +0 -1
  58. package/.github/workflows/deploy-docs.yml +0 -56
  59. package/.pre-commit.sh +0 -15
  60. package/.snyk +0 -4
  61. package/Makefile +0 -25
  62. package/index.ts +0 -28
  63. package/samlify-2.11.0.tgz +0 -0
  64. package/src/api.ts +0 -48
  65. package/src/binding-post.ts +0 -336
  66. package/src/binding-redirect.ts +0 -335
  67. package/src/binding-simplesign.ts +0 -231
  68. package/src/entity-idp.ts +0 -145
  69. package/src/entity-sp.ts +0 -114
  70. package/src/entity.ts +0 -243
  71. package/src/extractor.ts +0 -399
  72. package/src/flow.ts +0 -469
  73. package/src/libsaml.ts +0 -779
  74. package/src/metadata-idp.ts +0 -146
  75. package/src/metadata-sp.ts +0 -203
  76. package/src/metadata.ts +0 -166
  77. package/src/types.ts +0 -127
  78. package/src/urn.ts +0 -210
  79. package/src/utility.ts +0 -259
  80. package/src/validator.ts +0 -44
  81. package/tsconfig.json +0 -41
  82. package/tslint.json +0 -35
  83. package/types.d.ts +0 -2
  84. package/vitest.config.ts +0 -12
@@ -1,125 +1,174 @@
1
1
  /**
2
- * @desc Mimic lodash.zipObject
3
- * @param arr1 {string[]}
4
- * @param arr2 {[]}
2
+ * Build an object by zipping two parallel arrays of keys and values.
3
+ * When `skipDuplicated` is false, colliding keys are aggregated into arrays
4
+ * so duplicate keys do not clobber earlier values.
5
+ *
6
+ * @param arr1 key array
7
+ * @param arr2 value array (same index as keys)
8
+ * @param skipDuplicated when true (default) later writes overwrite earlier ones
9
+ * @returns object composed from key/value pairs
5
10
  */
6
- export declare function zipObject(arr1: string[], arr2: any[], skipDuplicated?: boolean): {};
11
+ export declare function zipObject<T>(arr1: string[], arr2: T[], skipDuplicated?: boolean): Record<string, T | T[]>;
7
12
  /**
8
- * @desc Alternative to lodash.flattenDeep
9
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_flattendeep
10
- * @param input {[]}
13
+ * Recursively flatten a nested array into a single-level array.
14
+ *
15
+ * @param input nested array input
16
+ * @returns flattened array
11
17
  */
12
- export declare function flattenDeep(input: any[]): any;
18
+ export declare function flattenDeep<T>(input: T | T[]): T[];
13
19
  /**
14
- * @desc Alternative to lodash.last
15
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_last
16
- * @param input {[]}
20
+ * Return the last element of an array.
21
+ *
22
+ * @param input source array
23
+ * @returns the final element, or undefined when the array is empty
17
24
  */
18
- export declare function last(input: any[]): any;
25
+ export declare function last<T>(input: T[]): T;
19
26
  /**
20
- * @desc Alternative to lodash.uniq
21
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_uniq
22
- * @param input {string[]}
27
+ * Return a copy of a string array with duplicates removed.
28
+ *
29
+ * @param input array with possible duplicates
30
+ * @returns array in original order without duplicates
23
31
  */
24
32
  export declare function uniq(input: string[]): string[];
25
33
  /**
26
- * @desc Alternative to lodash.get
27
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
28
- * @param obj
29
- * @param path
30
- * @param defaultValue
34
+ * Safely read a dotted path from an object, returning `defaultValue` when
35
+ * any segment is missing.
36
+ *
37
+ * @param obj source object
38
+ * @param path dotted path expression (e.g. "a.b.c")
39
+ * @param defaultValue fallback when the path does not resolve
40
+ * @returns resolved value or the default
31
41
  */
32
- export declare function get(obj: any, path: any, defaultValue: any): any;
42
+ export declare function get<T = unknown>(obj: Record<string, unknown> | null | undefined, path: string, defaultValue?: T | null): T | null;
33
43
  /**
34
- * @desc Check if the input is string
35
- * @param {any} input
44
+ * Type guard for strings.
45
+ *
46
+ * @param input value to test
47
+ * @returns true when the input is a string primitive
36
48
  */
37
- export declare function isString(input: any): input is string;
49
+ export declare function isString(input: unknown): input is string;
38
50
  /**
39
- * @desc Encode string with base64 format
40
- * @param {string} message plain-text message
41
- * @return {string} base64 encoded string
42
- */
51
+ * Encode a string or byte array as base64.
52
+ *
53
+ * @param message plain text or raw bytes
54
+ * @returns base64 encoded string
55
+ */
43
56
  declare function base64Encode(message: string | number[]): string;
44
57
  /**
45
- * @desc Decode string from base64 format
46
- * @param {string} base64Message encoded string
47
- * @param {boolean} isBytes determine the return value type (True: bytes False: string)
48
- * @return {bytes/string} decoded bytes/string depends on isBytes, default is {string}
49
- */
58
+ * Decode a base64 message. Returns either the decoded string or the raw
59
+ * Buffer depending on `isBytes`.
60
+ *
61
+ * @param base64Message base64 encoded payload
62
+ * @param isBytes when true, return a Buffer instead of a string
63
+ * @returns decoded string or Buffer
64
+ */
50
65
  export declare function base64Decode(base64Message: string, isBytes?: boolean): string | Buffer;
51
66
  /**
52
- * @desc Compress the string
53
- * @param {string} message
54
- * @return {string} compressed string
55
- */
67
+ * Raw-deflate a UTF-8 string and return the compressed bytes.
68
+ *
69
+ * @param message plain text
70
+ * @returns compressed bytes as a number array
71
+ */
56
72
  declare function deflateString(message: string): number[];
57
73
  /**
58
- * @desc Decompress the compressed string
59
- * @param {string} compressedString
60
- * @return {string} decompressed string
61
- */
74
+ * Raw-inflate a base64 string that was produced by {@link deflateString}.
75
+ *
76
+ * @param compressedString base64-encoded raw-deflate payload
77
+ * @returns decompressed UTF-8 string
78
+ */
62
79
  export declare function inflateString(compressedString: string): string;
63
80
  /**
64
- * @desc Parse the .cer to string format without line break, header and footer
65
- * @param {string} certString declares the certificate contents
66
- * @return {string} certificiate in string format
67
- */
81
+ * Normalise a PEM certificate string to its base64 body.
82
+ *
83
+ * @param certString PEM-encoded X.509 certificate
84
+ * @returns certificate body without headers/whitespace
85
+ */
68
86
  declare function normalizeCerString(certString: string | Buffer): string;
69
87
  /**
70
- * @desc Normalize the string in .pem format without line break, header and footer
71
- * @param {string} pemString
72
- * @return {string} private key in string format
73
- */
88
+ * Normalise a PEM RSA private key string to its base64 body.
89
+ *
90
+ * @param pemString PEM-encoded RSA private key
91
+ * @returns key body without headers/whitespace
92
+ */
74
93
  declare function normalizePemString(pemString: string | Buffer): string;
75
94
  /**
76
- * @desc Return the complete URL
77
- * @param {object} req HTTP request
78
- * @return {string} URL
79
- */
80
- declare function getFullURL(req: any): string;
81
- /**
82
- * @desc Parse input string, return default value if it is undefined
83
- * @param {string/boolean}
84
- * @return {boolean}
85
- */
86
- declare function parseString(str: any, defaultValue?: string): any;
87
- /**
88
- * @desc Override the object by another object (rtl)
89
- * @param {object} default object
90
- * @param {object} object applied to the default object
91
- * @return {object} result object
92
- */
93
- declare function applyDefault(obj1: any, obj2: any): any;
94
- /**
95
- * @desc Get public key in pem format from the certificate included in the metadata
96
- * @param {string} x509 certificate
97
- * @return {string} public key fetched from the certificate
98
- */
99
- declare function getPublicKeyPemFromCertificate(x509Certificate: string): string;
100
- /**
101
- * @desc Read private key from pem-formatted string
102
- * @param {string | Buffer} keyString pem-formatted string
103
- * @param {string} protected passphrase of the key
104
- * @return {string} string in pem format
105
- * If passphrase is used to protect the .pem content (recommend)
106
- */
107
- export declare function readPrivateKey(keyString: string | Buffer, passphrase: string | undefined, isOutputString?: boolean): any;
108
- /**
109
- * @desc Inline syntax sugar
110
- */
111
- declare function convertToString(input: any, isOutputString: any): any;
112
- /**
113
- * @desc Check if the input is an array with non-zero size
114
- */
115
- export declare function isNonEmptyArray(a: any): boolean;
95
+ * Reconstruct the full URL (protocol + host + path) from an Express-style
96
+ * HTTP request.
97
+ *
98
+ * @param req Express-compatible request object
99
+ * @returns absolute URL string
100
+ */
101
+ declare function getFullURL(req: {
102
+ protocol: string;
103
+ get: (name: string) => string | undefined;
104
+ originalUrl: string;
105
+ }): string;
106
+ /**
107
+ * Return `str` when it is truthy, otherwise the provided default.
108
+ */
109
+ declare function parseString(str: string | undefined | null, defaultValue?: string): string;
110
+ /**
111
+ * Shallow-merge `obj2` on top of `obj1`, returning a new object.
112
+ */
113
+ declare function applyDefault<A extends object, B extends object>(obj1: A, obj2: B): A & B;
114
+ /**
115
+ * Extract the SPKI PEM public key from a base64 X.509 certificate body.
116
+ *
117
+ * @param x509Certificate normalised certificate body (no PEM wrappers)
118
+ * @returns PEM-encoded public key
119
+ */
120
+ declare function getPublicKeyPemFromCertificate(x509Certificate: string): string | Buffer;
121
+ /**
122
+ * Read a PEM private key, optionally decrypting it with a passphrase.
123
+ *
124
+ * @param keyString PEM key contents
125
+ * @param passphrase optional passphrase protecting the key
126
+ * @param isOutputString when true, always return a string
127
+ * @returns PEM key as string or Buffer
128
+ */
129
+ export declare function readPrivateKey(keyString: string | Buffer, passphrase: string | undefined, isOutputString?: boolean): string | Buffer;
130
+ /**
131
+ * Coerce a value to a string when `isOutputString` is true, otherwise pass
132
+ * it through untouched.
133
+ */
134
+ declare function convertToString(input: string | Buffer, isOutputString?: boolean): string | Buffer;
135
+ /**
136
+ * Check that the input is an array with at least one element.
137
+ *
138
+ * @param a candidate value
139
+ * @returns true when the argument is a non-empty array
140
+ */
141
+ export declare function isNonEmptyArray<T>(a: unknown): a is T[];
142
+ /**
143
+ * Wrap a single value in an array, or return the array unchanged.
144
+ * An undefined input returns an empty array.
145
+ *
146
+ * @param a scalar, array, or undefined
147
+ * @returns array form of the input
148
+ */
116
149
  export declare function castArrayOpt<T>(a?: T | T[]): T[];
150
+ /**
151
+ * Type guard removing `null` and `undefined` from a union.
152
+ *
153
+ * @param value value to narrow
154
+ * @returns true when the value is neither null nor undefined
155
+ */
117
156
  export declare function notEmpty<TValue>(value: TValue | null | undefined): value is TValue;
118
157
  /**
119
- * @desc Escape a string for safe use inside an XPath single-quoted string literal.
158
+ * Escape a string for safe use inside an XPath single-quoted string literal.
120
159
  * Prevents XPath injection by splitting on single quotes and using concat().
160
+ *
161
+ * @param value raw string that may contain quotes
162
+ * @returns XPath-safe string expression
121
163
  */
122
164
  export declare function escapeXPathValue(value: string): string;
165
+ /**
166
+ * Convert a string to camelCase, splitting on whitespace, `-`, `_`, `.`,
167
+ * and inferred case boundaries.
168
+ *
169
+ * @param input source string
170
+ * @returns camelCased output
171
+ */
123
172
  export declare function camelCase(input: string): string;
124
173
  declare const utility: {
125
174
  isString: typeof isString;
@@ -1,3 +1,24 @@
1
+ /**
2
+ * @file validator.ts
3
+ * @author tngan
4
+ * @desc Time-window validators for SAML `NotBefore` / `NotOnOrAfter` conditions.
5
+ */
6
+ /** Signed clock-drift tolerance in milliseconds for the two boundaries. */
1
7
  type DriftTolerance = [number, number];
8
+ /**
9
+ * Check whether the current clock falls within the provided SAML time
10
+ * window, applying a symmetric drift tolerance to both ends.
11
+ *
12
+ * Behaviour:
13
+ * - Both bounds missing: logs a warning and returns `true`.
14
+ * - Only `utcNotBefore` given: returns true when now is at or after it.
15
+ * - Only `utcNotOnOrAfter` given: returns true when now is strictly before it.
16
+ * - Both given: returns true only when both individual checks pass.
17
+ *
18
+ * @param utcNotBefore ISO-8601 lower bound (inclusive) or undefined
19
+ * @param utcNotOnOrAfter ISO-8601 upper bound (exclusive) or undefined
20
+ * @param drift tolerance applied to each bound, defaults to `[0, 0]`
21
+ * @returns whether the current time is within the configured window
22
+ */
2
23
  declare function verifyTime(utcNotBefore: string | undefined, utcNotOnOrAfter: string | undefined, drift?: DriftTolerance): boolean;
3
24
  export { verifyTime };
@@ -1,98 +0,0 @@
1
- version: 2.1
2
-
3
- jobs:
4
- test-node-20:
5
- docker:
6
- - image: cimg/node:20.19
7
- environment:
8
- INSTALL_JDK: 1
9
- steps:
10
- - checkout
11
- - run:
12
- name: Install Java JDK 21
13
- command: |
14
- sudo apt-get update
15
- sudo apt-get install -y wget lsb-release
16
- sudo mkdir -p /etc/apt/keyrings
17
- wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
18
- echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
19
- sudo apt-get update
20
- sudo apt-get install -y temurin-21-jdk
21
- java -version
22
- javac -version
23
- - run:
24
- name: Install dependencies
25
- command: yarn install --production=true
26
- - run:
27
- name: Install test dependencies
28
- command: yarn add @authenio/samlify-xsd-schema-validator
29
- - run:
30
- name: Run tests
31
- command: yarn test
32
-
33
- test-node-22:
34
- docker:
35
- - image: cimg/node:22.12
36
- environment:
37
- INSTALL_JDK: 1
38
- steps:
39
- - checkout
40
- - run:
41
- name: Install Java JDK 21
42
- command: |
43
- sudo apt-get update
44
- sudo apt-get install -y wget lsb-release
45
- sudo mkdir -p /etc/apt/keyrings
46
- wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
47
- echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
48
- sudo apt-get update
49
- sudo apt-get install -y temurin-21-jdk
50
- java -version
51
- javac -version
52
- - run:
53
- name: Install dependencies
54
- command: yarn install --production=true
55
- - run:
56
- name: Install test dependencies
57
- command: yarn add @authenio/samlify-xsd-schema-validator
58
- - run:
59
- name: Run tests
60
- command: yarn test
61
-
62
- test-node-24:
63
- docker:
64
- - image: cimg/node:24.0
65
- environment:
66
- INSTALL_JDK: 1
67
- steps:
68
- - checkout
69
- - run:
70
- name: Install Java JDK 21
71
- command: |
72
- sudo apt-get update
73
- sudo apt-get install -y wget lsb-release
74
- sudo mkdir -p /etc/apt/keyrings
75
- wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
76
- echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
77
- sudo apt-get update
78
- sudo apt-get install -y temurin-21-jdk
79
- java -version
80
- javac -version
81
- - run:
82
- name: Install dependencies
83
- command: yarn install --production=true
84
- - run:
85
- name: Install test dependencies
86
- command: yarn add @authenio/samlify-xsd-schema-validator
87
- - run:
88
- name: Run tests
89
- command: yarn test
90
-
91
- workflows:
92
- version: 2
93
- test:
94
- jobs:
95
- - test-node-20
96
- - test-node-22
97
- - test-node-24
98
-
package/.editorconfig DELETED
@@ -1,19 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = tab
5
- end_of_line = lf
6
- charset = utf-8
7
- trim_trailing_whitespace = true
8
- insert_final_newline = true
9
-
10
- [*.{json,js,ts,jsx,html,css}]
11
- indent_style = space
12
- indent_size = 2
13
-
14
- [.eslintrc]
15
- indent_style = space
16
- indent_size = 2
17
-
18
- [*.md]
19
- trim_trailing_whitespace = false
@@ -1 +0,0 @@
1
- github: [tngan]
@@ -1,56 +0,0 @@
1
- name: Deploy VitePress Docs
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
- paths:
8
- - 'docs/**'
9
- - '.github/workflows/deploy-docs.yml'
10
- workflow_dispatch:
11
-
12
- permissions:
13
- contents: read
14
- pages: write
15
- id-token: write
16
-
17
- concurrency:
18
- group: pages
19
- cancel-in-progress: false
20
-
21
- jobs:
22
- build-and-deploy:
23
- runs-on: ubuntu-latest
24
- environment:
25
- name: github-pages
26
- url: ${{ steps.deployment.outputs.page_url }}
27
- steps:
28
- - name: Checkout
29
- uses: actions/checkout@v4
30
- with:
31
- fetch-depth: 0
32
-
33
- - name: Setup Node.js
34
- uses: actions/setup-node@v4
35
- with:
36
- node-version: 18
37
- cache: 'yarn'
38
-
39
- - name: Install dependencies
40
- run: yarn install --frozen-lockfile
41
-
42
- - name: Build VitePress
43
- run: yarn docs:build
44
-
45
- - name: Setup Pages
46
- uses: actions/configure-pages@v4
47
-
48
- - name: Upload artifact
49
- uses: actions/upload-pages-artifact@v3
50
- with:
51
- path: docs/.vitepress/dist
52
-
53
- - name: Deploy to GitHub Pages
54
- id: deployment
55
- uses: actions/deploy-pages@v4
56
-
package/.pre-commit.sh DELETED
@@ -1,15 +0,0 @@
1
- echo "Linting"
2
- npm run lint
3
- LINTRESULT=$?
4
-
5
- echo "Compiling"
6
- $(npm bin)/tsc
7
- BUILDRESULT=$?
8
-
9
- if [[ $LINTRESULT -ne 0 || $BUILDRESULT -ne 0 ]]; then
10
- echo "Fix errors before commit"
11
- exit 1
12
- else
13
- echo "Ok to commit"
14
- exit 0
15
- fi
package/.snyk DELETED
@@ -1,4 +0,0 @@
1
- # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2
- version: v1.25.0
3
- ignore: {}
4
- patch: {}
package/Makefile DELETED
@@ -1,25 +0,0 @@
1
- PROJECT = "samlify"
2
-
3
- install: ;@echo "install ${PROJECT}"; \
4
- npm install;
5
-
6
- clean: ;
7
- rm -rf node_modules
8
-
9
- rebuild: ;
10
- rm -rf build; \
11
- tsc; \
12
-
13
- pretest: ;
14
- mkdir -p build/test; \
15
- cp -a test/key test/misc build/test;
16
-
17
- install_jdk:
18
- sudo add-apt-repository ppa:openjdk-r/ppa -y
19
- sudo apt-get -qq update
20
- sudo apt-get install -y openjdk-9-jdk
21
-
22
- doc: ;@echo "prepare and serve the docs"; \
23
- docsify serve ./docs
24
-
25
- .PHONY: rebuild pretest doc install_jdk
package/index.ts DELETED
@@ -1,28 +0,0 @@
1
- // version <= 1.25
2
- import IdentityProvider, { IdentityProvider as IdentityProviderInstance } from './src/entity-idp';
3
- import ServiceProvider, { ServiceProvider as ServiceProviderInstance } from './src/entity-sp';
4
-
5
- export { default as IdPMetadata } from './src/metadata-idp';
6
- export { default as SPMetadata } from './src/metadata-sp';
7
- export { default as Utility } from './src/utility';
8
- export { default as SamlLib } from './src/libsaml';
9
- // roadmap
10
- // new name convention in version >= 3.0
11
- import * as Constants from './src/urn';
12
- import * as Extractor from './src/extractor';
13
-
14
- // exposed methods for customizing samlify
15
- import { setSchemaValidator, setDOMParserOptions } from './src/api';
16
-
17
- export {
18
- Constants,
19
- Extractor,
20
- // temp: resolve the conflict after version >= 3.0
21
- IdentityProvider,
22
- IdentityProviderInstance,
23
- ServiceProvider,
24
- ServiceProviderInstance,
25
- // set context
26
- setSchemaValidator,
27
- setDOMParserOptions
28
- };
Binary file
package/src/api.ts DELETED
@@ -1,48 +0,0 @@
1
- import { DOMParser as dom, Options as DOMParserOptions } from '@xmldom/xmldom';
2
-
3
- // global module configuration
4
- interface Context extends ValidatorContext, DOMParserContext {}
5
-
6
- interface ValidatorContext {
7
- validate?: (xml: string) => Promise<any>;
8
- }
9
-
10
- interface DOMParserContext {
11
- dom: dom;
12
- }
13
-
14
- const XXE_SAFE_OPTIONS: DOMParserOptions = {
15
- /**
16
- * Treat XML parsing errors as fatal to prevent XXE attacks.
17
- * Entity references (e.g. &xxe;) and malformed XML in SAML messages
18
- * are not expected and may indicate an attack attempt.
19
- */
20
- errorHandler: {
21
- error: (msg: string) => { throw new Error(`XML parsing error: ${msg}`); },
22
- fatalError: (msg: string) => { throw new Error(`XML fatal error: ${msg}`); },
23
- },
24
- };
25
-
26
- const context: Context = {
27
- validate: undefined,
28
- dom: new dom(XXE_SAFE_OPTIONS)
29
- };
30
-
31
- export function getContext() {
32
- return context;
33
- }
34
-
35
- export function setSchemaValidator(params: ValidatorContext) {
36
-
37
- if (typeof params.validate !== 'function') {
38
- throw new Error('validate must be a callback function having one argument as xml input');
39
- }
40
-
41
- // assign the validate function to the context
42
- context.validate = params.validate;
43
-
44
- }
45
-
46
- export function setDOMParserOptions(options: DOMParserOptions = {}) {
47
- context.dom = new dom(options);
48
- }