@@ -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 ] ;
0 commit comments