Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] XML-encoded carriage returns are not resolved correctly #575

Closed
mhassan1 opened this issue Mar 25, 2021 · 1 comment · Fixed by #578
Closed

[BUG] XML-encoded carriage returns are not resolved correctly #575

mhassan1 opened this issue Mar 25, 2021 · 1 comment · Fixed by #578
Labels
Milestone

Comments

@mhassan1
Copy link
Contributor

mhassan1 commented Mar 25, 2021

Background

Earlier this week, Google rolled out a change to their GSuite SAML Apps IdP where the SAMLResponse contains XML-encoded carriage returns inside the SignatureValue and X509Certificate blocks.

For example, they started sending this (notice the 
 at the end of each line):

<ds:SignatureValue>nLcgyGLUW61YKksmQ1zc/WlV4/iOVlNWZrT13wUWxMwarc38L0Z1b72gTZjfYwH6t06qm4bNvTKc&#13;
B27ctMgEFvnEBwRuYUluLdhUm1HRPVtKflypI3HDqNtv4wYhbxhL11Yqa/Qhg/cV/VvYA1zMpNax&#13;
SEk10RTllBLmKrQbkmED9vnS1184IkynvpA8rJNqvkwkjVAhQKFIOLr0GVuhgIKP6obTbgtJmXlQ&#13;
Ie2oXsrIegeQqSTk64qsDG5MwG/wm5/26+IBC9Dn8aobLQ798xMZmoXNMyMMfUDK6cbMb2LK3hDR&#13;
NiiwuVSaBboGWTovciv+ui+odUbKHpLhVzJT4g==</ds:SignatureValue>

At first, I thought this must be a bug introduced on their end, but I saw that both samltool.com and SimpleSAMLphp considered that to be a valid SAMLResponse. I also noticed that other Java-based (Apache Santuario) IdPs will provide a SAMLResponse like that when a certain system property is unset (link). I could not find anywhere in the SAML or XML spec that mentions this, but I did notice that DOMParser correctly replaces those &#13; with actual carriage returns. We can confirm it like this:

const { DOMParser } = require('xmldom')
new DOMParser()
  .parseFromString('<abc>123&#13;456</abc>')
  .toString()
  .replace(/\r/g, '\\r') // just for display purposes here
// -> `123\r456`

I believe the root of the problem is that validateSignatureForCert passes raw XML (that has never been passed through a DOMParser) to sig.checkSignature(fullXml).

To Reproduce

Add a &#13; inside the SignatureValue in test/static/signatures/valid/response.root-unsigned.assertion-signed.xml, and run tests. Tests will fail.

Expected behavior
Tests should pass.

Environment

  • Node.js version: 14.15.1
  • passport-saml version: 2.0.6
@mhassan1 mhassan1 added the bug label Mar 25, 2021
@mhassan1 mhassan1 changed the title [BUG] XML-encoded carriage returns are not normalized correctly [BUG] XML-encoded carriage returns are not resolved correctly Mar 25, 2021
@markstos
Copy link
Contributor

Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants