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,35 +1,8 @@
1
1
  import { IdpMetadata as IdpMetadataConstructor } from './metadata-idp';
2
2
  import { SpMetadata as SpMetadataConstructor } from './metadata-sp';
3
- import { MetadataIdpConstructor, MetadataSpConstructor, EntitySetting } from './types';
4
- import { FlowResult } from './flow';
5
- export interface ESamlHttpRequest {
6
- query?: any;
7
- body?: any;
8
- octetString?: string;
9
- }
10
- export interface BindingContext {
11
- context: string;
12
- id: string;
13
- }
14
- export interface PostBindingContext extends BindingContext {
15
- relayState?: string;
16
- entityEndpoint: string;
17
- type: string;
18
- }
19
- export interface SimpleSignBindingContext extends PostBindingContext {
20
- sigAlg?: string;
21
- signature?: string;
22
- keyInfo?: string;
23
- }
24
- export interface SimpleSignComputedContext extends BindingContext {
25
- sigAlg?: string;
26
- signature?: string;
27
- }
28
- export interface ParseResult {
29
- samlContent: string;
30
- extract: any;
31
- sigAlg: string;
32
- }
3
+ import type { MetadataIdpConstructor, MetadataSpConstructor, EntitySetting, ESamlHttpRequest, BindingContext, PostBindingContext, SimpleSignBindingContext, RequestInfo, SAMLUser, CreateLogoutRequestOptions, CreateLogoutResponseOptions, CustomTagReplacement } from './types';
4
+ export type { ESamlHttpRequest, BindingContext, PostBindingContext, SimpleSignBindingContext, SimpleSignComputedContext, ParseResult, } from './types';
5
+ /** Constructor argument shared by both SP and IdP factories. */
33
6
  export type EntityConstructor = (MetadataIdpConstructor | MetadataSpConstructor) & {
34
7
  metadata?: string | Buffer;
35
8
  };
@@ -38,62 +11,83 @@ export default class Entity {
38
11
  entityType: string;
39
12
  entityMeta: IdpMetadataConstructor | SpMetadataConstructor;
40
13
  /**
41
- * @param entitySetting
42
- * @param entityMeta is the entity metadata, deprecated after 2.0
43
- */
14
+ * Build an entity, merging the provided configuration with defaults and
15
+ * hydrating the metadata abstraction for its role.
16
+ *
17
+ * @param entitySetting IdP or SP settings (metadata XML or options)
18
+ * @param entityType `idp` or `sp`
19
+ */
44
20
  constructor(entitySetting: EntityConstructor, entityType: 'idp' | 'sp');
45
21
  /**
46
- * @desc Returns the setting of entity
47
- * @return {object}
48
- */
22
+ * Return the effective entity settings (defaults merged with overrides).
23
+ */
49
24
  getEntitySetting(): EntitySetting;
50
25
  /**
51
- * @desc Returns the xml string of entity metadata
52
- * @return {string}
53
- */
26
+ * Return the serialized metadata XML for this entity.
27
+ */
54
28
  getMetadata(): string;
55
29
  /**
56
- * @desc Exports the entity metadata into specified folder
57
- * @param {string} exportFile indicates the file name
58
- */
30
+ * Persist the metadata XML to disk.
31
+ *
32
+ * @param exportFile absolute file path
33
+ */
59
34
  exportMetadata(exportFile: string): void;
60
- /** * @desc Verify fields with the one specified in metadata
61
- * @param {string/[string]} field is a string or an array of string indicating the field value in SAML message
62
- * @param {string} metaField is a string indicating the same field specified in metadata
63
- * @return {boolean} True/False
64
- */
35
+ /**
36
+ * Equality check between a field value extracted from a SAML message and
37
+ * the value declared in the peer's metadata. Arrays must match on every
38
+ * entry.
39
+ *
40
+ * @param field value(s) from the inbound SAML message
41
+ * @param metaField value from peer metadata
42
+ * @returns true when every provided value equals `metaField`
43
+ */
65
44
  verifyFields(field: string | string[], metaField: string): boolean;
66
- /** @desc Generates the logout request for developers to design their own method
67
- * @param {ServiceProvider} sp object of service provider
68
- * @param {string} binding protocol binding
69
- * @param {object} user current logged user (e.g. user)
70
- * @param {string} relayState the URL to which to redirect the user when logout is complete
71
- * @param {function} customTagReplacement used when developers have their own login response template
72
- */
73
- createLogoutRequest(targetEntity: any, binding: any, user: any, relayState?: string, customTagReplacement?: any): BindingContext | PostBindingContext;
74
45
  /**
75
- * @desc Generates the logout response for developers to design their own method
76
- * @param {IdentityProvider} idp object of identity provider
77
- * @param {object} requestInfo corresponding request, used to obtain the id
78
- * @param {string} relayState the URL to which to redirect the user when logout is complete.
79
- * @param {string} binding protocol binding
80
- * @param {function} customTagReplacement used when developers have their own login response template
81
- */
82
- createLogoutResponse(target: any, requestInfo: any, binding: any, relayState?: string, customTagReplacement?: any): BindingContext | PostBindingContext;
46
+ * Build a logout request targeting `targetEntity`. The return type depends
47
+ * on the binding: `redirect` produces a URL; `post` and `simpleSign`
48
+ * produce a base64 envelope (the latter with a detached signature).
49
+ *
50
+ * The fourth parameter accepts either a string (legacy `relayState`
51
+ * positional shape) or an options bag `{ relayState?, customTagReplacement? }`.
52
+ * Per `saml-bindings §3.4.3 / §3.5.3`, RelayState is request-scoped — pass
53
+ * it via the options bag instead of `entitySetting.relayState`.
54
+ *
55
+ * @param targetEntity peer to receive the logout request
56
+ * @param binding `redirect`, `post`, or `simpleSign`
57
+ * @param user currently authenticated user
58
+ * @param optionsOrRelayState per-request options or legacy RelayState string
59
+ * @param legacyCustomTagReplacement optional custom template transformer (legacy positional form)
60
+ */
61
+ createLogoutRequest(targetEntity: Entity, binding: string, user: SAMLUser, optionsOrRelayState?: CreateLogoutRequestOptions | string, legacyCustomTagReplacement?: CustomTagReplacement): BindingContext | PostBindingContext | SimpleSignBindingContext;
62
+ /**
63
+ * Build a logout response to the peer that initiated logout.
64
+ *
65
+ * The fourth parameter accepts either a string (legacy `relayState`
66
+ * positional shape) or an options bag `{ relayState?, customTagReplacement? }`.
67
+ * Per `saml-bindings §3.4.3 / §3.5.3`, RelayState is request-scoped — pass
68
+ * it via the options bag instead of `entitySetting.relayState`.
69
+ *
70
+ * @param target peer that sent the corresponding logout request
71
+ * @param requestInfo parsed request used to link `InResponseTo`
72
+ * @param binding `redirect`, `post`, or `simpleSign`
73
+ * @param optionsOrRelayState per-request options or legacy RelayState string
74
+ * @param legacyCustomTagReplacement optional custom template transformer (legacy positional form)
75
+ */
76
+ createLogoutResponse(target: Entity, requestInfo: RequestInfo, binding: string, optionsOrRelayState?: CreateLogoutResponseOptions | string, legacyCustomTagReplacement?: CustomTagReplacement): BindingContext | PostBindingContext | SimpleSignBindingContext;
83
77
  /**
84
- * @desc Validation of the parsed the URL parameters
85
- * @param {IdentityProvider} idp object of identity provider
86
- * @param {string} binding protocol binding
87
- * @param {request} req request
88
- * @return {Promise}
89
- */
90
- parseLogoutRequest(from: any, binding: any, request: ESamlHttpRequest): Promise<FlowResult>;
78
+ * Parse, validate and verify an inbound logout request.
79
+ *
80
+ * @param from peer entity that produced the request
81
+ * @param binding `redirect`, `post`, or `simpleSign`
82
+ * @param request HTTP request envelope
83
+ */
84
+ parseLogoutRequest(from: Entity, binding: string, request: ESamlHttpRequest): Promise<import("./flow").FlowResult>;
91
85
  /**
92
- * @desc Validation of the parsed the URL parameters
93
- * @param {object} config config for the parser
94
- * @param {string} binding protocol binding
95
- * @param {request} req request
96
- * @return {Promise}
97
- */
98
- parseLogoutResponse(from: any, binding: any, request: ESamlHttpRequest): Promise<FlowResult>;
86
+ * Parse, validate and verify an inbound logout response.
87
+ *
88
+ * @param from peer entity that produced the response
89
+ * @param binding `redirect`, `post`, or `simpleSign`
90
+ * @param request HTTP request envelope
91
+ */
92
+ parseLogoutResponse(from: Entity, binding: string, request: ESamlHttpRequest): Promise<import("./flow").FlowResult>;
99
93
  }
@@ -1,25 +1,34 @@
1
- interface ExtractorField {
2
- key: string;
3
- localPath: string[] | string[][];
4
- attributes: string[];
5
- index?: string[];
6
- attributePath?: string[];
7
- context?: boolean;
8
- }
9
- export type ExtractorFields = ExtractorField[];
1
+ import type { ExtractorField, ExtractorFields, ExtractorResult } from './types';
2
+ export type { ExtractorField, ExtractorFields, ExtractorResult } from './types';
3
+ /** Default extractor fields for an inbound `AuthnRequest` (login request). */
10
4
  export declare const loginRequestFields: ExtractorFields;
11
- export declare const loginResponseStatusFields: {
12
- key: string;
13
- localPath: string[];
14
- attributes: string[];
15
- }[];
16
- export declare const logoutResponseStatusFields: {
17
- key: string;
18
- localPath: string[];
19
- attributes: string[];
20
- }[];
21
- export declare const loginResponseFields: ((assertion: any) => ExtractorFields);
5
+ /** Two-tier status code extractor for login responses. */
6
+ export declare const loginResponseStatusFields: ExtractorFields;
7
+ /** Two-tier status code extractor for logout responses. */
8
+ export declare const logoutResponseStatusFields: ExtractorFields;
9
+ /**
10
+ * Build the login-response extractor bound to a particular assertion XML.
11
+ * Assertion-scoped fields are re-rooted at the assertion fragment via the
12
+ * `shortcut` mechanism so that wrapping attacks can't redirect extraction.
13
+ *
14
+ * @param assertion XML string of the (verified) assertion node
15
+ * @returns extractor fields ready for `extract`
16
+ */
17
+ export declare const loginResponseFields: (assertion: string) => ExtractorFields;
18
+ /** Default extractor fields for an inbound `LogoutRequest`. */
22
19
  export declare const logoutRequestFields: ExtractorFields;
20
+ /** Default extractor fields for an inbound `LogoutResponse`. */
23
21
  export declare const logoutResponseFields: ExtractorFields;
24
- export declare function extract(context: string, fields: any): any;
25
- export {};
22
+ /**
23
+ * Evaluate the given extractor fields against an XML document and return
24
+ * a flat object keyed by `field.key`. Handles:
25
+ * - multi-path localPaths (`string[][]`) collected with `|`
26
+ * - parent/child attribute aggregation (`index` + `attributePath`)
27
+ * - whole-subtree extraction (`context: true`)
28
+ * - single/multiple/zero-attribute text extraction
29
+ *
30
+ * @param context XML string to parse
31
+ * @param fields extractor field definitions
32
+ * @returns extracted SAML values keyed by field name
33
+ */
34
+ export declare function extract(context: string, fields: ExtractorField[]): ExtractorResult;
@@ -1,6 +1,28 @@
1
+ import type { ESamlHttpRequest, ExtractorResult } from './types';
2
+ import type Entity from './entity';
3
+ import { ParserType } from './urn';
4
+ /** Result emitted by the flow dispatcher for successful inbound messages. */
1
5
  export interface FlowResult {
2
6
  samlContent: string;
3
- extract: any;
7
+ extract: ExtractorResult;
4
8
  sigAlg?: string | null;
5
9
  }
6
- export declare function flow(options: any): Promise<FlowResult>;
10
+ /** Options consumed by {@link flow} and its internal dispatch helpers. */
11
+ export interface FlowOptions {
12
+ request: ESamlHttpRequest;
13
+ parserType: ParserType | string;
14
+ self: Entity;
15
+ from: Entity;
16
+ checkSignature?: boolean;
17
+ type: 'login' | 'logout';
18
+ binding: string;
19
+ supportBindings?: string[];
20
+ }
21
+ /**
22
+ * Entry point: dispatch an inbound SAML message to the matching binding
23
+ * handler based on `options.binding`.
24
+ *
25
+ * @param options flow inputs (request, parserType, entities, binding)
26
+ * @returns resolved {@link FlowResult} on success
27
+ */
28
+ export declare function flow(options: FlowOptions): Promise<FlowResult>;
@@ -1,9 +1,13 @@
1
1
  /**
2
- * @file SamlLib.js
3
- * @author tngan
4
- * @desc A simple library including some common functions
5
- */
2
+ * @file libsaml.ts
3
+ * @author tngan
4
+ * @desc SAML primitives: templates, XML signing/verification, assertion
5
+ * encryption/decryption, and XPath helpers used by the higher-level flows.
6
+ */
6
7
  import { MetadataInterface } from './metadata';
8
+ import { SigningSchemeHash } from 'node-rsa';
9
+ import type { EntitySetting, SignatureConfig, TagReplacementMap, XmlElementArray } from './types';
10
+ /** Options accepted by {@link LibSamlInterface.constructSAMLSignature}. */
7
11
  export interface SignatureConstructor {
8
12
  rawSamlMessage: string;
9
13
  referenceTagXPath?: string;
@@ -12,22 +16,28 @@ export interface SignatureConstructor {
12
16
  signatureAlgorithm: string;
13
17
  signingCert: string | Buffer;
14
18
  isBase64Output?: boolean;
15
- signatureConfig?: any;
19
+ signatureConfig?: SignatureConfig;
16
20
  isMessageSigned?: boolean;
17
21
  transformationAlgorithms?: string[];
18
22
  }
23
+ /** Options accepted by {@link LibSamlInterface.verifySignature}. */
19
24
  export interface SignatureVerifierOptions {
20
25
  metadata?: MetadataInterface;
21
26
  keyFile?: string;
22
27
  signatureAlgorithm?: string;
23
28
  }
29
+ /**
30
+ * Generic extracted SAML result shape retained for backwards compatibility.
31
+ * Prefer {@link import('./types').ExtractorResult} in new code.
32
+ */
24
33
  export interface ExtractorResult {
25
- [key: string]: any;
34
+ [key: string]: unknown;
26
35
  signature?: string | string[];
27
36
  issuer?: string | string[];
28
37
  nameID?: string;
29
38
  notexist?: boolean;
30
39
  }
40
+ /** Attribute configuration used when building an AttributeStatement. */
31
41
  export interface LoginResponseAttribute {
32
42
  name: string;
33
43
  nameFormat: string;
@@ -36,10 +46,12 @@ export interface LoginResponseAttribute {
36
46
  valueXmlnsXs?: string;
37
47
  valueXmlnsXsi?: string;
38
48
  }
49
+ /** Overridable templates used when building a LoginResponse. */
39
50
  export interface LoginResponseAdditionalTemplates {
40
51
  attributeStatementTemplate?: AttributeStatementTemplate;
41
52
  attributeTemplate?: AttributeTemplate;
42
53
  }
54
+ /** Shared shape for all SAML document templates. */
43
55
  export interface BaseSamlTemplate {
44
56
  context: string;
45
57
  }
@@ -57,26 +69,53 @@ export interface LogoutRequestTemplate extends BaseSamlTemplate {
57
69
  }
58
70
  export interface LogoutResponseTemplate extends BaseSamlTemplate {
59
71
  }
72
+ /** Valid certificate `use` attribute values in metadata KeyDescriptor. */
60
73
  export type KeyUse = 'signing' | 'encryption';
74
+ /** Shape of a KeyDescriptor element assembled by `createKeySection`. */
61
75
  export interface KeyComponent {
62
- [key: string]: any;
76
+ [key: string]: unknown;
77
+ KeyDescriptor: XmlElementArray;
78
+ }
79
+ /** Structural shape of an Entity (IdP or SP) consumed by libsaml. */
80
+ export interface EntityLike {
81
+ entitySetting: EntitySetting & {
82
+ isAssertionEncrypted?: boolean;
83
+ dataEncryptionAlgorithm?: string;
84
+ keyEncryptionAlgorithm?: string;
85
+ tagPrefix?: {
86
+ protocol?: string;
87
+ assertion?: string;
88
+ encryptedAssertion?: string;
89
+ [key: string]: string | undefined;
90
+ };
91
+ encPrivateKey?: string | Buffer;
92
+ encPrivateKeyPass?: string | Buffer;
93
+ };
94
+ entityMeta: MetadataInterface;
63
95
  }
96
+ /** Public surface exposed by the libsaml singleton. */
64
97
  export interface LibSamlInterface {
65
98
  getQueryParamByType: (type: string) => string;
66
- createXPath: (local: any, isExtractAll?: boolean) => string;
67
- replaceTagsByValue: (rawXML: string, tagValues: any) => string;
99
+ createXPath: (local: string | {
100
+ name: string;
101
+ attr: string;
102
+ }, isExtractAll?: boolean) => string;
103
+ replaceTagsByValue: (rawXML: string, tagValues: TagReplacementMap) => string;
68
104
  attributeStatementBuilder: (attributes: LoginResponseAttribute[], attributeTemplate: AttributeTemplate, attributeStatementTemplate: AttributeStatementTemplate) => string;
69
105
  constructSAMLSignature: (opts: SignatureConstructor) => string;
70
- verifySignature: (xml: string, opts: SignatureVerifierOptions) => [boolean, any];
71
- createKeySection: (use: KeyUse, cert: string | Buffer) => {};
72
- constructMessageSignature: (octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string) => string;
73
- verifyMessageSignature: (metadata: any, octetString: string, signature: string | Buffer, verifyAlgorithm?: string) => boolean;
74
- getKeyInfo: (x509Certificate: string, signatureConfig?: any) => void;
75
- encryptAssertion: (sourceEntity: any, targetEntity: any, entireXML: string) => Promise<string>;
76
- decryptAssertion: (here: any, entireXML: string) => Promise<[string, any]>;
77
- getSigningScheme: (sigAlg: string) => string | null;
106
+ verifySignature: (xml: string, opts: SignatureVerifierOptions) => [boolean, string | null];
107
+ createKeySection: (use: KeyUse, cert: string | Buffer) => KeyComponent;
108
+ constructMessageSignature: (octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string) => string | Buffer;
109
+ verifyMessageSignature: (metadata: MetadataInterface, octetString: string, signature: string | Buffer, verifyAlgorithm?: string) => boolean;
110
+ getKeyInfo: (x509Certificate: string, signatureConfig?: SignatureConfig) => {
111
+ getKeyInfo: () => string;
112
+ getKey: () => string;
113
+ };
114
+ encryptAssertion: (sourceEntity: EntityLike, targetEntity: EntityLike, entireXML: string) => Promise<string>;
115
+ decryptAssertion: (here: EntityLike, entireXML: string) => Promise<[string, string]>;
116
+ getSigningScheme: (sigAlg: string) => SigningSchemeHash | null;
78
117
  getDigestMethod: (sigAlg: string) => string | null;
79
- nrsaAliasMapping: any;
118
+ nrsaAliasMapping: Record<string, SigningSchemeHash>;
80
119
  defaultLoginRequestTemplate: LoginRequestTemplate;
81
120
  defaultLoginResponseTemplate: LoginResponseTemplate;
82
121
  defaultAttributeStatementTemplate: AttributeStatementTemplate;
@@ -85,125 +124,140 @@ export interface LibSamlInterface {
85
124
  defaultLogoutResponseTemplate: LogoutResponseTemplate;
86
125
  }
87
126
  declare const _default: {
88
- createXPath: (local: any, isExtractAll?: boolean) => string;
89
- getQueryParamByType: (type: string) => "SAMLRequest" | "SAMLResponse";
90
- defaultLoginRequestTemplate: {
91
- context: string;
92
- };
93
- defaultLoginResponseTemplate: {
94
- context: string;
95
- attributes: never[];
96
- additionalTemplates: {
97
- attributeStatementTemplate: {
98
- context: string;
99
- };
100
- attributeTemplate: {
101
- context: string;
102
- };
103
- };
104
- };
105
- defaultAttributeStatementTemplate: {
106
- context: string;
107
- };
108
- defaultAttributeTemplate: {
109
- context: string;
110
- };
111
- defaultLogoutRequestTemplate: {
112
- context: string;
113
- };
114
- defaultLogoutResponseTemplate: {
115
- context: string;
116
- };
127
+ createXPath: (local: string | {
128
+ name: string;
129
+ attr: string;
130
+ }, isExtractAll?: boolean) => string;
131
+ getQueryParamByType: (type: string) => string;
132
+ defaultLoginRequestTemplate: LoginRequestTemplate;
133
+ defaultLoginResponseTemplate: LoginResponseTemplate;
134
+ defaultAttributeStatementTemplate: AttributeStatementTemplate;
135
+ defaultAttributeTemplate: AttributeTemplate;
136
+ defaultLogoutRequestTemplate: LogoutRequestTemplate;
137
+ defaultLogoutResponseTemplate: LogoutResponseTemplate;
117
138
  /**
118
- * @desc Replace the tag (e.g. {tag}) inside the raw XML
119
- * @param {string} rawXML raw XML string used to do keyword replacement
120
- * @param {array} tagValues tag values
121
- * @return {string}
122
- */
123
- replaceTagsByValue(rawXML: string, tagValues: Record<string, unknown>): string;
139
+ * Substitute `{Tag}` placeholders inside an XML template with the given
140
+ * replacement map. Replacement text is XML-escaped in both attribute and
141
+ * element-text positions to prevent SAML element/attribute injection.
142
+ *
143
+ * When a tag's value is `null` or `undefined`:
144
+ * - in **attribute position** (`name="{Tag}"`) the entire attribute is
145
+ * omitted from the rendered XML, per `saml-core §3.4.1` (every
146
+ * `<AuthnRequest>` attribute is `use="optional"`); previously samlify
147
+ * emitted `name=""` or the literal `name="undefined"`, which is
148
+ * invalid for typed attributes (e.g. `AssertionConsumerServiceURL`
149
+ * declared as `xs:anyURI`).
150
+ * - in **element-only-body position** (`<X>{Tag}</X>` or
151
+ * `<X attr="...">{Tag}</X>`) the entire element is dropped — per
152
+ * `saml-core §3.7.1` for `<samlp:SessionIndex>` and any other
153
+ * `minOccurs="0"` element where the body is solely a placeholder.
154
+ * - in **mixed-text position** (`<X>prefix{Tag}suffix</X>`) the
155
+ * placeholder is replaced with the empty string (legacy behaviour).
156
+ *
157
+ * @param rawXML template with `{Tag}` placeholders
158
+ * @param tagValues replacement map keyed by tag name
159
+ * @returns XML with placeholders resolved
160
+ */
161
+ replaceTagsByValue(rawXML: string, tagValues: TagReplacementMap): string;
124
162
  /**
125
- * @desc Helper function to build the AttributeStatement tag
126
- * @param {LoginResponseAttribute} attributes an array of attribute configuration
127
- * @param {AttributeTemplate} attributeTemplate the attribute tag template to be used
128
- * @param {AttributeStatementTemplate} attributeStatementTemplate the attributeStatement tag template to be used
129
- * @return {string}
130
- */
163
+ * Build a serialized `<AttributeStatement>` from attribute descriptors
164
+ * by applying the attribute and statement templates.
165
+ *
166
+ * @param attributes attribute descriptors (name, format, value)
167
+ * @param attributeTemplate per-attribute template
168
+ * @param attributeStatementTemplate wrapping statement template
169
+ * @returns serialized XML fragment
170
+ */
131
171
  attributeStatementBuilder(attributes: LoginResponseAttribute[], attributeTemplate?: AttributeTemplate, attributeStatementTemplate?: AttributeStatementTemplate): string;
132
172
  /**
133
- * @desc Construct the XML signature for POST binding
134
- * @param {string} rawSamlMessage request/response xml string
135
- * @param {string} referenceTagXPath reference uri
136
- * @param {string} privateKey declares the private key
137
- * @param {string} passphrase passphrase of the private key [optional]
138
- * @param {string|buffer} signingCert signing certificate
139
- * @param {string} signatureAlgorithm signature algorithm
140
- * @param {string[]} transformationAlgorithms canonicalization and transformation Algorithms
141
- * @return {string} base64 encoded string
142
- */
173
+ * Compute an XML-DSig signature over the supplied SAML message. Can
174
+ * sign the message root (`isMessageSigned`), a referenced subtree
175
+ * (`referenceTagXPath`), or both.
176
+ *
177
+ * @param opts signature inputs and layout options
178
+ * @returns base64 (default) or raw signed XML string
179
+ */
143
180
  constructSAMLSignature(opts: SignatureConstructor): string;
144
181
  /**
145
- * @desc Verify the XML signature
146
- * @param {string} xml xml
147
- * @param {SignatureVerifierOptions} opts cert declares the X509 certificate
148
- * @return {[boolean, string | null]} - A tuple where:
149
- * - The first element is `true` if the signature is valid, `false` otherwise.
150
- * - The second element is the cryptographically authenticated assertion node as a string, or `null` if not found.
182
+ * Verify an XML-DSig signature on a SAML payload and, on success, return
183
+ * the cryptographically authenticated assertion node.
184
+ *
185
+ * Defends against classic wrapping attacks by rejecting assertions that
186
+ * appear inside a `SubjectConfirmationData` subtree.
187
+ *
188
+ * @param xml SAML message XML
189
+ * @param opts metadata or key file plus signature algorithm
190
+ * @returns tuple `[verified, authenticatedAssertion | null]`
151
191
  */
152
192
  verifySignature(xml: string, opts: SignatureVerifierOptions): [boolean, string | null];
153
193
  /**
154
- * @desc Helper function to create the key section in metadata (abstraction for signing and encrypt use)
155
- * @param {string} use type of certificate (e.g. signing, encrypt)
156
- * @param {string} certString declares the certificate String
157
- * @return {object} object used in xml module
158
- */
194
+ * Build the metadata `<KeyDescriptor>` fragment for a certificate use.
195
+ *
196
+ * @param use `signing` or `encryption`
197
+ * @param certString PEM certificate body or Buffer
198
+ * @returns element tree consumable by the `xml` module
199
+ */
159
200
  createKeySection(use: KeyUse, certString: string | Buffer): KeyComponent;
160
201
  /**
161
- * @desc Constructs SAML message
162
- * @param {string} octetString see "Bindings for the OASIS Security Assertion Markup Language (SAML V2.0)" P.17/46
163
- * @param {string} key declares the pem-formatted private key
164
- * @param {string} passphrase passphrase of private key [optional]
165
- * @param {string} signingAlgorithm signing algorithm
166
- * @return {string} message signature
167
- */
168
- constructMessageSignature(octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string): string | Buffer<ArrayBufferLike>;
202
+ * Produce a detached RSA signature over a SAML redirect-binding octet
203
+ * string. See SAML bindings spec §3.4.4.1.
204
+ *
205
+ * @param octetString canonical query-string to sign
206
+ * @param key PEM private key
207
+ * @param passphrase optional passphrase for the key
208
+ * @param isBase64 when true (default), base64-encode the signature
209
+ * @param signingAlgorithm signature algorithm URI
210
+ * @returns base64 string (default) or raw Buffer signature
211
+ */
212
+ constructMessageSignature(octetString: string, key: string, passphrase?: string, isBase64?: boolean, signingAlgorithm?: string): string | Buffer;
169
213
  /**
170
- * @desc Verifies message signature
171
- * @param {Metadata} metadata metadata object of identity provider or service provider
172
- * @param {string} octetString see "Bindings for the OASIS Security Assertion Markup Language (SAML V2.0)" P.17/46
173
- * @param {string} signature context of XML signature
174
- * @param {string} verifyAlgorithm algorithm used to verify
175
- * @return {boolean} verification result
176
- */
177
- verifyMessageSignature(metadata: any, octetString: string, signature: string | Buffer, verifyAlgorithm?: string): boolean;
214
+ * Verify a detached RSA signature over a redirect-binding octet string.
215
+ *
216
+ * @param metadata peer metadata carrying the signing certificate
217
+ * @param octetString canonical query-string that was signed
218
+ * @param signature signature bytes
219
+ * @param verifyAlgorithm signature algorithm URI (optional)
220
+ * @returns true when the signature verifies
221
+ */
222
+ verifyMessageSignature(metadata: MetadataInterface, octetString: string, signature: string | Buffer, verifyAlgorithm?: string): boolean;
178
223
  /**
179
- * @desc Get the public key in string format
180
- * @param {string} x509Certificate certificate
181
- * @return {string} public key
182
- */
183
- getKeyInfo(x509Certificate: string, signatureConfig?: any): {
224
+ * Build the KeyInfo XML fragment and PEM public key for a certificate.
225
+ *
226
+ * @param x509Certificate certificate body (no PEM wrappers)
227
+ * @param signatureConfig optional prefix/location for the KeyInfo element
228
+ */
229
+ getKeyInfo(x509Certificate: string, signatureConfig?: SignatureConfig): {
184
230
  getKeyInfo: () => string;
185
231
  getKey: () => string;
186
232
  };
187
233
  /**
188
- * @desc Encrypt the assertion section in Response
189
- * @param {Entity} sourceEntity source entity
190
- * @param {Entity} targetEntity target entity
191
- * @param {string} xml response in xml string format
192
- * @return {Promise} a promise to resolve the finalized xml
193
- */
194
- encryptAssertion(sourceEntity: any, targetEntity: any, xml?: string): Promise<string>;
234
+ * Encrypt the `<Assertion>` inside a SAML response using the target
235
+ * entity's encryption certificate. Returns the base64-encoded XML
236
+ * containing the `<EncryptedAssertion>` element in place of the plaintext.
237
+ *
238
+ * @param sourceEntity entity initiating the encryption (its settings drive the algorithms)
239
+ * @param targetEntity entity whose certificate is used
240
+ * @param xml response XML containing a single `<Assertion>`
241
+ * @returns promise resolving to base64-encoded XML
242
+ */
243
+ encryptAssertion(sourceEntity: EntityLike, targetEntity: EntityLike, xml?: string): Promise<string>;
195
244
  /**
196
- * @desc Decrypt the assertion section in Response
197
- * @param {string} type only accept SAMLResponse to proceed decryption
198
- * @param {Entity} here this entity
199
- * @param {Entity} from from the entity where the message is sent
200
- * @param {string} entireXML response in xml string format
201
- * @return {function} a promise to get back the entire xml with decrypted assertion
202
- */
203
- decryptAssertion(here: any, entireXML: string): Promise<[string, any]>;
245
+ * Decrypt the `<EncryptedAssertion>` inside a SAML response using the
246
+ * local entity's private key. Returns both the decrypted document XML
247
+ * and the raw assertion fragment for downstream extraction.
248
+ *
249
+ * @param here local entity performing decryption
250
+ * @param entireXML SAML response XML containing `<EncryptedAssertion>`
251
+ * @returns tuple `[decryptedDocumentXml, rawAssertionXml]`
252
+ */
253
+ decryptAssertion(here: EntityLike, entireXML: string): Promise<[string, string]>;
204
254
  /**
205
- * @desc Check if the xml string is valid and bounded
255
+ * Validate the SAML XML against the registered schema validator. Throws
256
+ * when no validator has been configured via {@link setSchemaValidator}
257
+ * so consumers can't silently ship without schema checks.
258
+ *
259
+ * @param input SAML XML string
206
260
  */
207
- isValidXml(input: string): Promise<any>;
261
+ isValidXml(input: string): Promise<unknown>;
208
262
  };
209
263
  export default _default;