File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -738,6 +738,8 @@ class SAML {
738
738
if ( totalReferencedNodes . length > 1 ) {
739
739
return false ;
740
740
}
741
+ // normalize XML to replace XML-encoded carriage returns with actual carriage returns
742
+ fullXml = this . normalizeXml ( fullXml ) ;
741
743
fullXml = this . normalizeNewlines ( fullXml ) ;
742
744
return sig . checkSignature ( fullXml ) ;
743
745
}
@@ -1465,6 +1467,12 @@ class SAML {
1465
1467
// https://github.com/node-saml/passport-saml/issues/431#issuecomment-718132752
1466
1468
return xml . replace ( / \r \n ? / g, "\n" ) ;
1467
1469
}
1470
+
1471
+ normalizeXml ( xml : string ) : string {
1472
+ // we can use this utility to parse and re-stringify XML
1473
+ // `DOMParser` will take care of normalization tasks, like replacing XML-encoded carriage returns with actual carriage returns
1474
+ return new xmldom . DOMParser ( { } ) . parseFromString ( xml ) . toString ( ) ;
1475
+ }
1468
1476
}
1469
1477
1470
1478
export { SAML } ;
Original file line number Diff line number Diff line change @@ -279,4 +279,26 @@ describe("Signatures", function () {
279
279
await testOneResponseBody ( body , false , 1 ) ;
280
280
} ) ;
281
281
} ) ;
282
+
283
+ describe ( "Signature on saml:Response with XML-encoded carriage returns" , ( ) => {
284
+ const samlResponseXml = fs
285
+ . readFileSync (
286
+ __dirname + "/../static/signatures/valid/response.root-unsigned.assertion-signed.xml"
287
+ )
288
+ . toString ( ) ;
289
+ const makeBody = ( str : string ) => ( { SAMLResponse : Buffer . from ( str ) . toString ( "base64" ) } ) ;
290
+
291
+ const insertChars = ( str : string , where : string , chars : string ) =>
292
+ str . replace ( new RegExp ( `(<ds:${ where } >)(.{10})(.{10})` ) , `$1$2${ chars } $3` ) ;
293
+
294
+ it ( "SignatureValue with " , async ( ) => {
295
+ const body = makeBody ( insertChars ( samlResponseXml , "SignatureValue" , " " ) ) ;
296
+ await testOneResponseBody ( body , false , 2 ) ;
297
+ } ) ;
298
+
299
+ it ( "SignatureValue with 
" , async ( ) => {
300
+ const body = makeBody ( insertChars ( samlResponseXml , "SignatureValue" , "
" ) ) ;
301
+ await testOneResponseBody ( body , false , 2 ) ;
302
+ } ) ;
303
+ } ) ;
282
304
} ) ;
You can’t perform that action at this time.
0 commit comments