Skip to content

Commit 1ecc1fa

Browse files
authored
Adjust deprecation to better reflect real-world usage (#498)
1 parent cc24755 commit 1ecc1fa

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/signed-xml.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export class SignedXml {
323323
valid(ated). Put simply: if one fails, they are all not trustworthy.
324324
*/
325325
this.signedReferences = [];
326+
// TODO: add this breaking change here later on for even more security: `this.references = [];`
326327
if (callback) {
327328
callback(new Error("Could not validate all references"), false);
328329
return;
@@ -357,6 +358,7 @@ export class SignedXml {
357358
// but that may cause some breaking changes, so we'll handle that in v7.x.
358359
// If we were validating `signedInfoCanon` first, we wouldn't have to reset this array.
359360
this.signedReferences = [];
361+
// TODO: add this breaking change here later on for even more security: `this.references = [];`
360362

361363
if (callback) {
362364
callback(
@@ -539,14 +541,14 @@ export class SignedXml {
539541
}
540542
}
541543

542-
ref.getValidatedNode = (xpathSelector?: string) => {
544+
ref.getValidatedNode = deprecate((xpathSelector?: string) => {
543545
xpathSelector = xpathSelector || ref.xpath;
544546
if (typeof xpathSelector !== "string" || ref.validationError != null) {
545547
return null;
546548
}
547549
const selectedValue = xpath.select1(xpathSelector, doc);
548550
return isDomNode.isNodeLike(selectedValue) ? selectedValue : null;
549-
};
551+
}, "`ref.getValidatedNode()` is deprecated and insecure. Use `ref.signedReference` or `this.getSignedReferences()` instead.");
550552

551553
if (!isDomNode.isNodeLike(elem)) {
552554
const validationError = new Error(
@@ -573,6 +575,7 @@ export class SignedXml {
573575
// thus the `canonXml` and _only_ the `canonXml` can be trusted.
574576
// Append this to `signedReferences`.
575577
this.signedReferences.push(canonXml);
578+
ref.signedReference = canonXml;
576579

577580
return true;
578581
}
@@ -821,13 +824,18 @@ export class SignedXml {
821824
}
822825

823826
/**
824-
* @deprecated Use `.getSignedReferences()` instead.
825827
* Returns the list of references.
826828
*/
827-
getReferences = deprecate(
828-
() => this.references,
829-
"getReferences() is deprecated. Use `.getSignedReferences()` instead.",
830-
);
829+
getReferences() {
830+
// TODO: Refactor once `getValidatedNode` is removed
831+
/* Once we completely remove the deprecated `getValidatedNode()` method,
832+
we can change this to return a clone to prevent accidental mutations,
833+
e.g.:
834+
return [...this.references];
835+
*/
836+
837+
return this.references;
838+
}
831839

832840
getSignedReferences() {
833841
return [...this.signedReferences];

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export interface Reference {
133133
validationError?: Error;
134134

135135
getValidatedNode(xpathSelector?: string): Node | null;
136+
137+
signedReference?: string;
136138
}
137139

138140
/** Implement this to create a new CanonicalizationOrTransformationAlgorithm */

0 commit comments

Comments
 (0)