elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.71k stars 24.67k forks source link

SAML Assertion decryption fails when the assertion namespace is declared on the Response element #84039

Open jkakavas opened 2 years ago

jkakavas commented 2 years ago

Elasticsearch Version

7.1

Elasticsearch fails to decrypt an encrypted SAML Assertion when it is missing the Assertion namespace declaration.

It's not the decryption itself that fails but rather that we fail to parse the XML document after decrypting it.

Background

See: https://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-decl for more details.

Elasticsearch's behavior when decrypting SAML messages

  1. Elasticsearch gets a SAML message as a base64 string and decodes it.
  2. Elasticsearch then has an XML message that looks like
    <Response>
        <EncryptedAssertion>
        </EncryptedAssertion>
    </Response>    
  3. We detach this Encrypted Assertion and attempt to decrypt it on its own.
  4. After we decrypt the EncryptedAssertion into an Assertion, we parse it and validate it syntactically before we use it. This happens automatically by virtue of org.opensaml.xmlsec.encryption.support.Decrypter#parseInputStream being called.

The manifestation of the issue

We should be able to consume such SAML Responses, AFAICT these are valid and there are a number of SP implementations that can handle them correctly.

elasticmachine commented 2 years ago

Pinging @elastic/es-security (Team:Security)