File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -730,6 +730,8 @@ class SAML {
730
730
if ( totalReferencedNodes . length > 1 ) {
731
731
return false ;
732
732
}
733
+ // normalize XML to replace XML-encoded carriage returns with actual carriage returns
734
+ fullXml = this . normalizeXml ( fullXml ) ;
733
735
fullXml = this . normalizeNewlines ( fullXml ) ;
734
736
return sig . checkSignature ( fullXml ) ;
735
737
}
@@ -1418,6 +1420,12 @@ class SAML {
1418
1420
// https://github.com/node-saml/passport-saml/issues/431#issuecomment-718132752
1419
1421
return xml . replace ( / \r \n ? / g, "\n" ) ;
1420
1422
}
1423
+
1424
+ normalizeXml ( xml : string ) : string {
1425
+ // we can use this utility to parse and re-stringify XML
1426
+ // `DOMParser` will take care of normalization tasks, like replacing XML-encoded carriage returns with actual carriage returns
1427
+ return new xmldom . DOMParser ( { } ) . parseFromString ( xml ) . toString ( ) ;
1428
+ }
1421
1429
}
1422
1430
1423
1431
export { SAML } ;
Original file line number Diff line number Diff line change @@ -100,4 +100,27 @@ describe('Signatures', function() {
100
100
101
101
} ) ;
102
102
103
+ describe ( "Signature on saml:Response with XML-encoded carriage returns" , ( ) => {
104
+ const samlResponseXml = fs
105
+ . readFileSync (
106
+ __dirname + "/static/signatures/valid/response.root-unsigned.assertion-signed.xml"
107
+ )
108
+ . toString ( ) ;
109
+ const makeBody = ( str ) => ( { SAMLResponse : Buffer . from ( str ) . toString ( "base64" ) } ) ;
110
+
111
+ const insertChars = ( str , where , chars ) =>
112
+ str . replace ( new RegExp ( `(<ds:${ where } >)(.{10})(.{10})` ) , `$1$2${ chars } $3` ) ;
113
+
114
+ it ( "SignatureValue with " , async ( ) => {
115
+ const body = makeBody ( insertChars ( samlResponseXml , "SignatureValue" , " " ) ) ;
116
+ await testOneResponseBody ( body , false , 2 ) ;
117
+ } ) ;
118
+
119
+ it ( "SignatureValue with 
" , async ( ) => {
120
+ const body = makeBody ( insertChars ( samlResponseXml , "SignatureValue" , "
" ) ) ;
121
+ await testOneResponseBody ( body , false , 2 ) ;
122
+ } ) ;
123
+
124
+ } ) ;
125
+
103
126
} ) ;
You can’t perform that action at this time.
0 commit comments