Skip to content

Conversation

@bcoe
Copy link

@bcoe bcoe commented Dec 12, 2015

It's valid for a SAML response to contain multiple signatures (I ran into this problem with a major SAML SSO provider)

  • this patch validates each signature.
  • I also fixed up a test that failed on post iojs versions of Node.

@brettkiefer
Copy link

We're seeing an issue with an IdP sending multiple signatures, and this patch seems to do the trick for our use case.

@brettkiefer
Copy link

Is this something that is likely to be merged, or might this library cover multiple sigs in a different way?

@brettkiefer
Copy link

This is not something that was handled by #58, right? Is this something that might be merged into a future release?

@brettkiefer
Copy link

@cozmo Is this something I could help get into a future release? It's still definitely affecting us with some IdPs, and I'd love to get it into a saml2-js release.

@brettkiefer
Copy link

@cozmo It looks like #67 would also fix this, but it looks like that PR was deleted without being merged? I'm probably missing something there. Would it be helpful to integrate these tests into that PR?

@cozmo
Copy link
Contributor

cozmo commented Aug 30, 2016

Hey @brettkiefer - multiple signatures is tricky to support securely/without edge cases. Take for example the bug that #48 uncovered. Do you have an example of the response you're trying to support? Also it's possible that if/when #74 is merged it could fix your use case, depending on the details.

@brettkiefer
Copy link

@cozmo Thanks! @mgduk tells me that #74 won't do the trick for us, because we're trying to deal with a response where both the Response and the Assertion are signed. An example of that would be the "SAML Response with Signed Message & Assertion" from the OneLogin docs at https://developers.onelogin.com/saml/examples/response (included below).

<?xml version="1.0"?>
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="pfxe4335d5f-f67f-589d-43fb-67f3cab5c04a" Version="2.0" IssueInstant="2014-07-17T01:01:48Z" Destination="http://sp.example.com/demo1/index.php?acs" InResponseTo="ONELOGIN_4fee3b046395c4e751011e97f8900b5273d56685">
  <saml:Issuer>http://idp.example.com/metadata.php</saml:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  <ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
  <ds:Reference URI="#pfxe4335d5f-f67f-589d-43fb-67f3cab5c04a"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>owMd0M3lh+g/FdDW/dBcJns24og=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>lXdMWdPz9BQTCXiGujaCvKcBK+1cD9q/gVildc1mi29KUamFfTBBjwgdGK/peW2F2QS6HwmYwF1+j8PNlBei7RCn+EtqFv71XJUDC3GMiQ+m1MSDYLAK9wp2noXFV107+r/ZTRfVKRWPVD70mpAR6unFqJtRCCdFY1eGSl0M0lk=</ds:SignatureValue>
<ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIICajCCAdOgAwIBAgIBADANBgkqhkiG9w0BAQ0FADBSMQswCQYDVQQGEwJ1czETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMT25lbG9naW4gSW5jMRcwFQYDVQQDDA5zcC5leGFtcGxlLmNvbTAeFw0xNDA3MTcxNDEyNTZaFw0xNTA3MTcxNDEyNTZaMFIxCzAJBgNVBAYTAnVzMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQKDAxPbmVsb2dpbiBJbmMxFzAVBgNVBAMMDnNwLmV4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZx+ON4IUoIWxgukTb1tOiX3bMYzYQiwWPUNMp+Fq82xoNogso2bykZG0yiJm5o8zv/sd6pGouayMgkx/2FSOdc36T0jGbCHuRSbtia0PEzNIRtmViMrt3AeoWBidRXmZsxCNLwgIV6dn2WpuE5Az0bHgpZnQxTKFek0BMKU/d8wIDAQABo1AwTjAdBgNVHQ4EFgQUGHxYqZYyX7cTxKVODVgZwSTdCnwwHwYDVR0jBBgwFoAUGHxYqZYyX7cTxKVODVgZwSTdCnwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQ0FAAOBgQByFOl+hMFICbd3DJfnp2Rgd/dqttsZG/tyhILWvErbio/DEe98mXpowhTkC04ENprOyXi7ZbUqiicF89uAGyt1oqgTUCD1VsLahqIcmrzgumNyTwLGWo17WDAa1/usDhetWAMhgzF/Cnf5ek0nK00m0YZGyc4LzgD0CROMASTWNg==</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature>
  <samlp:Status>
    <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
  </samlp:Status>
  <saml:Assertion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" ID="pfx68a93eb2-8360-336d-9522-1e3f40a110ee" Version="2.0" IssueInstant="2014-07-17T01:01:48Z">
    <saml:Issuer>http://idp.example.com/metadata.php</saml:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  <ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
  <ds:Reference URI="#pfx68a93eb2-8360-336d-9522-1e3f40a110ee"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>eMYdLp7xtCjSiejSZYpXx3OgRVc=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>SovFPmBHJv+JV4JhThvhBc/0vLDjfZTmHrpQ1cQDhJW2xX/6r2gBi+7tRSHWLQPcSKQNEafhPXzYcoYpG6iQsb0C375CFjfdLtaUo9vG4vwfyBp2MjgkhcWZd1DloR7Vhg97dggV516OdjGsP6WdK1Tq63PuyV6Xj9rja9uvu3I=</ds:SignatureValue>
<ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIICajCCAdOgAwIBAgIBADANBgkqhkiG9w0BAQ0FADBSMQswCQYDVQQGEwJ1czETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMT25lbG9naW4gSW5jMRcwFQYDVQQDDA5zcC5leGFtcGxlLmNvbTAeFw0xNDA3MTcxNDEyNTZaFw0xNTA3MTcxNDEyNTZaMFIxCzAJBgNVBAYTAnVzMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQKDAxPbmVsb2dpbiBJbmMxFzAVBgNVBAMMDnNwLmV4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZx+ON4IUoIWxgukTb1tOiX3bMYzYQiwWPUNMp+Fq82xoNogso2bykZG0yiJm5o8zv/sd6pGouayMgkx/2FSOdc36T0jGbCHuRSbtia0PEzNIRtmViMrt3AeoWBidRXmZsxCNLwgIV6dn2WpuE5Az0bHgpZnQxTKFek0BMKU/d8wIDAQABo1AwTjAdBgNVHQ4EFgQUGHxYqZYyX7cTxKVODVgZwSTdCnwwHwYDVR0jBBgwFoAUGHxYqZYyX7cTxKVODVgZwSTdCnwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQ0FAAOBgQByFOl+hMFICbd3DJfnp2Rgd/dqttsZG/tyhILWvErbio/DEe98mXpowhTkC04ENprOyXi7ZbUqiicF89uAGyt1oqgTUCD1VsLahqIcmrzgumNyTwLGWo17WDAa1/usDhetWAMhgzF/Cnf5ek0nK00m0YZGyc4LzgD0CROMASTWNg==</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature>
    <saml:Subject>
      <saml:NameID SPNameQualifier="http://sp.example.com/demo1/metadata.php" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">_ce3d2948b4cf20146dee0a0b3dd6f69b6cf86f62d7</saml:NameID>
      <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
        <saml:SubjectConfirmationData NotOnOrAfter="2024-01-18T06:21:48Z" Recipient="http://sp.example.com/demo1/index.php?acs" InResponseTo="ONELOGIN_4fee3b046395c4e751011e97f8900b5273d56685"/>
      </saml:SubjectConfirmation>
    </saml:Subject>
    <saml:Conditions NotBefore="2014-07-17T01:01:18Z" NotOnOrAfter="2024-01-18T06:21:48Z">
      <saml:AudienceRestriction>
        <saml:Audience>http://sp.example.com/demo1/metadata.php</saml:Audience>
      </saml:AudienceRestriction>
    </saml:Conditions>
    <saml:AuthnStatement AuthnInstant="2014-07-17T01:01:48Z" SessionNotOnOrAfter="2024-07-17T09:01:48Z" SessionIndex="_be9967abd904ddcae3c0eb4189adbe3f71e327cf93">
      <saml:AuthnContext>
        <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
      </saml:AuthnContext>
    </saml:AuthnStatement>
    <saml:AttributeStatement>
      <saml:Attribute Name="uid" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
        <saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
      </saml:Attribute>
      <saml:Attribute Name="mail" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
        <saml:AttributeValue xsi:type="xs:string">test@example.com</saml:AttributeValue>
      </saml:Attribute>
      <saml:Attribute Name="eduPersonAffiliation" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
        <saml:AttributeValue xsi:type="xs:string">users</saml:AttributeValue>
        <saml:AttributeValue xsi:type="xs:string">examplerole1</saml:AttributeValue>
      </saml:Attribute>
    </saml:AttributeStatement>
  </saml:Assertion>
</samlp:Response>

@mgduk
Copy link
Contributor

mgduk commented Sep 7, 2016

Hi @cozmo

When handling a response that has a signed Response and Assertion, there are two bugs at play.

parse_authn_response calls check_saml_signature for the Assertion (in the result variable there) and the whole response document (saml_response_str).

  1. When the Assertion element is namespaced — <saml:Assertion> rather than <Assertion xmlns="…"> and there is no <InclusiveNamespaces> element in the document (or it's empty), the signed DOM cannot be extracted from the Assertion. More explanation, tests & fix on Don't rely on InclusiveNamespaces for namespace declarations #81
  2. When there is a <Signature> within the Assertion and the Response, the Response cannot be validated as check_saml_signature finds two Signatures (the child and grandchild of <Response>) when it expects only one.

(2) is the bug that this PR (#47) is addressing, however I think it is safer and cleaner to take a slightly different approach to resolve this: more info, tests & fix are on #82

Hopefully there's enough info in #81 and #82 to clarify the problems and my solutions to them. Let me know if you need anything more! Thanks.

@mgduk
Copy link
Contributor

mgduk commented Sep 13, 2016

@jefff/@Cosmo FWIW, this PR can be closed now as its issue is resolved by #82

@cozmo
Copy link
Contributor

cozmo commented Sep 13, 2016

Sounds good

@cozmo cozmo closed this Sep 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants