Skip to content
OAuth / SSO Write-up Advanced

Duo Finds SAML Vulnerabilities Affecting Multiple Implementations

A vulnerability class in SAML single sign-on systems allows an authenticated attacker to modify their own SAML assertion to impersonate another user by exploiting inconsistent XML comment handling during text extraction. The attacker can change the NameID to a victim's identifier without invalidating the signature.

Kelby Ludwig Follow

Published on duo.com

This blog post describes a new vulnerability class that affects SAML-based single sign-on (SSO) systems. This vulnerability can allow an attacker with authenticated access to trick SAML systems into authenticating as a different user without knowledge of the victim user’s password.

Kelby Ludwig (@kelbyludwig), on duo.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

SAML (Security Assertion Markup Language) is a widely used standard for single sign-on. In a typical flow, a user authenticates to an Identity Provider (IdP) such as Duo or GSuite, which produces a signed SAML Response. The user's browser forwards that response to a Service Provider (SP) such as Slack or Github. The SP validates the signature on the Response, and if it is valid, a string identifier inside the response (for example the NameID) tells the SP which user to authenticate.

Duo Labs, the research team at Duo Security, identified a new vulnerability class affecting SAML-based SSO systems. It lets an attacker who already has authenticated access trick a SAML system into authenticating them as a different user, without knowing that user's password. The affected vendors and identifiers were:

Vendor Library / product CVE
OneLogin python-saml CVE-2017-11427
OneLogin ruby-saml CVE-2017-11428
Clever saml2-js CVE-2017-11429
OmniAuth-SAML CVE-2017-11430
Shibboleth CVE-2018-0489
Duo Duo Network Gateway CVE-2018-7340
From the original on duo.com

Setup

The attack requires an attacker with authenticated access and the ability to modify their own SAML assertion. The report does not describe a specific lab setup, tooling or versions beyond the libraries named above.

Finding it

The researcher starts from a simplified SAML Response:

XML
<SAMLResponse>
    <Issuer>https://idp.com/</Issuer>
    <Assertion ID="_id1234">
        <Subject>
            <NameID>[redacted]</NameID>
        </Subject>
    </Assertion>
    <Signature>
        <SignedInfo>
            <CanonicalizationMethod Algorithm="xml-c14n11"/>
            <Reference URI="#_id1234"/>
        </SignedInfo>
        <SignatureValue>
            some base64 data that represents the signature of the assertion
        </SignatureValue>
    </Signature>
</SAMLResponse>

The two essential elements are the Assertion and the Signature. The Assertion says that the IdP authenticated [redacted]. The signature is generated over that Assertion and, if done correctly, prevents modification of the NameID. Since the SP uses the NameID to decide which user to authenticate, the signature stops an attacker from changing their own assertion from [redacted] to [redacted].

The next relevant aspect is XML canonicalization, which lets two logically equivalent XML documents share the same byte representation. For example:

XML
<A X="1" Y="2">some text<!-- and a comment --></A>

and

XML
< A Y="2" X="1" >some text</ A >

convey the same information despite different byte representations. Canonicalization is applied before signing, so multiple different-but-similar XML documents can have the same exact signature. The CanonicalizationMethod element specifies which algorithm is applied. The most common in practice is http://www.w3.org/2001/10/xml-exc-c14n# (shortened to exc-c14n). A variant, http://www.w3.org/2001/10/xml-exc-c14n#WithComments, does not omit comments, so the two documents above would not share a canonical representation under it. That distinction matters later.

The other ingredient is a subtle behaviour of XML libraries such as Python's lxml and Ruby's REXML. Given:

XML
<NameID>kludwig</NameID>

extracting the identifier in Python might look like:

Python
from defusedxml.lxml import fromstring
payload = "<NameID>kludwig</NameID>"
data = fromstring(payload)
return data.text # should return 'kludwig'

That returns kludwig, as expected. Now add a comment:

Python
from defusedxml.lxml import fromstring
doc = "<NameID>klud<!-- a comment? -->wig</NameID>"
data = fromstring(payload)
return data.text # should return ‘kludwig’?

The .text API in lxml returns klud. The researcher considers this technically correct but unintuitive: as a tree, the document is

Text
element: NameID
|_ text: klud
|_ comment: a comment?
|_ text: wig

and lxml simply does not read text after the first text node ends. The uncommented node is a single text node, kludwig, so stopping at the first text node makes sense there.

Ruby's REXML behaves similarly. Its get_text documentation hints at why:

Text
[get_text] returns the first child Text node, if any, or nil otherwise. This method returns the actual Text node, rather than the String content.

Other libraries differ. With Python's xml.etree.ElementTree:

Python
import xml.etree.ElementTree as et
doc = "<NameID>klud<!-- a comment? -->wig</NameID>"
data = et.fromstring(payload)
return data.text # returns 'kludwig'

The researcher also saw implementations that do not use an XML API at all but extract the inner text of a node's first child manually, which produces the same substring behaviour.

Exploitation

Step 1: Combine the three ingredients

The vulnerability needs three things:

  1. SAML Responses contain strings that identify the authenticating user.
  2. XML canonicalization (in most cases) removes comments during signature validation, so adding comments to a SAML Response does not invalidate the signature.
  3. XML text extraction may return only a substring of the text within an element when comments are present.

Step 2: Modify your own assertion

As an attacker with access to the account [redacted], you modify your own SAML assertion so that the NameID becomes [redacted] when the SP processes it. A seven-character addition to the toy response produces the payload:

XML
<SAMLResponse>
    <Issuer>https://idp.com/</Issuer>
    <Assertion ID="_id1234">
        <Subject>
            <NameID>[redacted]<!---->.evil.com</NameID>
        </Subject>
    </Assertion>
    <Signature>
        <SignedInfo>
            <CanonicalizationMethod Algorithm="xml-c14n11"/>
            <Reference URI="#_id1234"/>
        </SignedInfo>
        <SignatureValue>
            some base64 data that represents the signature of the assertion
        </SignatureValue>
    </Signature>
</SAMLResponse>

The empty comment <!----> splits the text node. A parser that stops at the first text node reads [redacted], while canonicalization, in most cases, drops the comment and the signature stays valid.

Root cause

The mistake is the mismatch between how the signature is computed and how the identifier is read. Canonicalization removes comments before signing, so an attacker can insert comments without invalidating the signature. Text extraction APIs such as lxml's .text and REXML's get_text return only the first text node, so the value the SP reads differs from the value the IdP signed. Libraries that extract inner text manually from the first child produce the same result. The XML signature, if done correctly, should prevent modification of the NameID, but here the modification is invisible to the canonicalized form that was signed.

Impact

An attacker with authenticated access can trick a SAML system into authenticating as a different user without knowing that user's password. The impact varies greatly. SAML IdPs and SPs are generally very configurable, so there is room to increase or decrease it. SPs that use email addresses and validate the domain against a whitelist are much less likely to be exploitable than SPs that allow arbitrary strings as user identifiers. On the IdP side, openly allowing users to register accounts increases impact; a manual user provisioning process adds a barrier that makes exploitation less feasible. If the SP enforces two-factor authentication, that helps a lot, because the vulnerability only bypasses the first factor. If the IdP is responsible for both first and second factor, the vulnerability likely bypasses both.

Fix

For users of Duo's software, Duo released updates for the Duo Network Gateway in version 1.2.10. If the DNG is used as a SAML Service Provider and is not at 1.2.10 or higher (the latest at the time of writing), upgrade. Duo's Product Security Advisory covers the details.

For those running or maintaining an IdP or SP, the best remediation is to ensure SAML processing libraries are not affected. The researcher identified several libraries that either leveraged these unintuitive XML APIs or did faulty manual text extraction, and is sure there are more libraries that do not handle comments in XML nodes well. Another possible remediation is defaulting to a canonicalization algorithm such as http://www.w3.org/2001/10/xml-exc-c14n#WithComments, which does not omit comments, so attacker-added comments invalidate the signature. The canonicalization algorithm identifier itself must not be subject to tampering, and this change requires IdP and SP support, which may not be universal.

For maintainers of SAML processing libraries, the most obvious fix is to ensure the library extracts the full text of an element when comments are present. Most SAML libraries the researcher found had unit tests, and it was fairly easy to update tests that extracted properties like NameIDs by adding comments to pre-signed documents. If the tests still pass, that is a good sign; otherwise the library may be vulnerable. Another option is to use the canonicalized XML document after signature validation for any processing such as text extraction, which could prevent this and other canonicalization-related issues.

For maintainers of XML parsing libraries, the number of affected libraries suggests many users assume inner text APIs are not affected by comments, which could motivate changing an API's behaviour. The researcher does not think there is a clear right answer, and keeping the APIs as they are while improving documentation is a reasonable action. Improving the XML standards is another path: no standards identified during the research specified the correct behaviour, and it may be worth specifying how these related standards should interoperate.

  • Other SAML libraries. Add a comment inside a NameID in a pre-signed test document and check whether the extracted value is truncated. A positive result is a NameID that reads as the victim's identifier while the signature still validates.
  • Manual text extraction. Look for code that reads the inner text of a node's first child rather than using an XML API. A positive result is the same substring behaviour with comments present.
  • Canonicalization algorithm. Check whether the SP accepts exc-c14n (which drops comments) rather than exc-c14n#WithComments. A positive result is a signed response whose comment insertion does not invalidate the signature.
  • Identifier policy. Check whether the SP allows arbitrary strings as user identifiers or validates email domains against a whitelist. A positive result is an SP that accepts arbitrary identifiers, widening the set of accounts an attacker can impersonate.
  • Registration policy. Check whether the IdP allows open registration. A positive result is self-service account creation, which lowers the barrier to obtaining an account to modify.

Disclosure timeline

Due to the vulnerability impacting multiple vendors, Duo worked with CERT/CC to coordinate disclosure.

Date Activity
2017-12-18 CERT/CC contacted and provided vulnerability information.
2017-12-20 CERT/CC follows up with questions about the issue.
2017-12-22 Response to questions from CERT/CC.
2018-01-02 to 2018-01-09 Additional email discussion with CERT/CC about the issue.
2018-01-24 CERT/CC completes internal analysis and contacts impacted vendors.
2018-01-25 Vendors acknowledge CERT/CC report. Additional communication with CERT/CC and vendors to further explain the issue and other attack vectors.
2018-01-29 Additional vendor that is potentially impacted identified and contacted by CERT/CC.
2018-02-01 Duo Labs reserves CVE numbers for each impacted vendor.
2018-02-06 Draft of CERT/CC vulnerability technical note reviewed and approved by Duo.
2018-02-20 Final confirmation that all impacted vendors are ready for disclosure date.
2018-02-27 Disclosure.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 20 min read.

What happened, in plain words

Many websites let you sign in with an account you already have somewhere else, for example your work account or your Google account. This is called single sign-on, or SSO. You click "Sign in with...", you log in once at the place that holds your account, and the website you wanted to use trusts that login and lets you in.

A research team at Duo Security, called Duo Labs, found a flaw in the way many of these systems are built. The flaw lets someone who already has authenticated access trick a SAML system into thinking they are a different person, without ever knowing that person's password. The researcher who wrote this up is Kelby Ludwig, and the write-up was published on 27 February 2018.

The trick is small and clever. It relies on a tiny piece of text that is normally ignored, a comment, being handled differently by two parts of the same system. One part checks the signature that proves the login is genuine, and in most cases it ignores the comment. The other part reads the username, and it stops reading at the comment. So the signature stays valid while the username the website sees is not the one that was signed.

This is not one bug in one product. It is a pattern, a whole class of bug, that showed up in several different pieces of software. The affected vendors and their identifiers were:

Vendor Library / product CVE
OneLogin python-saml CVE-2017-11427
OneLogin ruby-saml CVE-2017-11428
Clever saml2-js CVE-2017-11429
OmniAuth-SAML CVE-2017-11430
Shibboleth CVE-2018-0489
Duo Duo Network Gateway CVE-2018-7340

A CVE is a public catalogue number for a known security flaw, so that everyone can refer to the same issue unambiguously. If you rely on SAML-based SSO, the advice is to update any affected software to a patched version. Duo customers running the Duo Network Gateway should read Duo's Product Security Advisory.

From the original on duo.com

The background you need: what SAML is

SAML stands for Security Assertion Markup Language. Despite the name, it is not really a programming language. It is an agreed format, a standard, for passing a statement about who you are from one system to another. It is one of the most common ways SSO is built.

There are two roles in every SAML login:

  • The Identity Provider, or IdP. This is the system that holds your account and checks your password. Examples given in the write-up are Duo and GSuite.
  • The Service Provider, or SP. This is the website or app you actually want to use. Examples given are Slack and Github.

A simple everyday comparison: the IdP is like a passport office, and the SP is like a hotel reception desk. The passport office checks who you are and issues you a document. The hotel does not phone the passport office every time; it looks at the document, checks it is genuine, and trusts what it says.

Here is the flow, step by step:

  1. You go to the SP and choose to sign in with your IdP account.
  2. You log in at the IdP. The IdP creates a signed SAML Response, a small block of text that says who you are.
  3. Your browser carries that response over to the SP.
  4. The SP checks the signature on the response.
  5. If the signature is valid, the SP reads a string inside the response, for example the NameID, and uses it to decide which user you are. Then it logs you in as that user.

A signature here works like a wax seal on a letter. The IdP stamps the response with a value that only it can produce. If anyone changes the letter afterwards, the seal no longer matches and the SP rejects it. That is the whole point: it stops you from editing the response to claim to be someone else.

A really simplified SAML Response looks like this:

XML
<SAMLResponse>
    <Issuer>https://idp.com/</Issuer>
    <Assertion ID="_id1234">
        <Subject>
            <NameID>[redacted]</NameID>
        </Subject>
    </Assertion>
    <Signature>
        <SignedInfo>
            <CanonicalizationMethod Algorithm="xml-c14n11"/>
            <Reference URI="#_id1234"/>
        </SignedInfo>
        <SignatureValue>
            some base64 data that represents the signature of the assertion
        </SignatureValue>
    </Signature>
</SAMLResponse>

Line by line, in plain words:

  • <SAMLResponse> and </SAMLResponse> wrap the whole message. Everything between them is the response.
  • <Issuer>https://idp.com/</Issuer> says which IdP produced this response.
  • <Assertion ID="_id1234"> opens the actual statement about the user. The ID is a label so other parts of the document can point at this exact block.
  • <Subject> and <NameID>[redacted]</NameID> are the heart of it: the statement that the IdP authenticated the user [redacted].
  • <Signature> opens the seal. Inside it, <SignedInfo> describes what was signed and how, and <Reference URI="#_id1234"/> says the signed thing is the block labelled _id1234, which is the assertion above.
  • <CanonicalizationMethod Algorithm="xml-c14n11"/> names the method used to tidy the text before signing. We will come back to this, because it is central to the bug.
  • <SignatureValue> holds the actual signature data, described in the write-up as some base64 data that represents the signature of the assertion. Base64 is just a way of writing binary data as ordinary letters and digits.

The write-up notes that this example leaves out a lot of information, but that the omitted parts are not important for this vulnerability. The two essential elements are the Assertion and the Signature. The Assertion is the IdP saying "I authenticated [redacted]". The signature is generated over that assertion and, if done correctly, prevents anyone from modifying the NameID.

Why does that matter? Because the SP uses the NameID to decide who to log in. The signature is what stops an attacker from taking their own assertion, which says [redacted], and editing it to say [redacted]. If an attacker could change the NameID without breaking the signature, that would be bad. The write-up adds a hint, hint, because that is exactly what this vulnerability allows.

XML canonicalization, explained slowly

Before we can see the trick, we need one more idea: XML canonicalization. The write-up spells it, jokingly, as canononononicalizizization, because it is a mouthful.

XML is a way of writing structured text with tags, like the SAML response above. The same information can be written in slightly different ways. Extra spaces, a different order of attributes, a comment: all of these change the exact characters on the page but not the meaning.

Canonicalization is the process of rewriting an XML document into one standard, agreed form, so that two documents that mean the same thing end up looking exactly the same, character for character. The write-up calls this having the same byte representation: the same sequence of bytes, the raw units a computer stores.

Here is the example given:

XML
<A X="1" Y="2">some text<!-- and a comment --></A>

and

XML
< A Y="2" X="1" >some text</ A >

These two documents have different byte representations, but they convey the same information. In the first, the attributes X and Y come in one order and there is a comment inside. In the second, the attributes are swapped, there are extra spaces, and the comment is gone. Logically, both say the same thing: an element A with attributes X and Y containing some text.

Why does this matter for signatures? Because canonicalization is applied to the XML before it is signed. That way, practically meaningless differences, like a stray space, do not produce a different signature. The write-up emphasises the consequence: multiple different-but-similar XML documents can have the same exact signature. That is fine, for the most part, because the canonicalization algorithm specifies which differences matter and which do not.

In the toy SAML response, the CanonicalizationMethod element names the algorithm to use. The write-up mentions that the XML Signature specification outlines a couple of algorithms, and that the most common in practice seems to be http://www.w3.org/2001/10/xml-exc-c14n#, shortened to exc-c14n.

There is a variant of exc-c14n with the identifier http://www.w3.org/2001/10/xml-exc-c14n#WithComments. The difference is in the name: this variant does not omit comments. So under it, the two documents above would not have the same canonical representation, because one has a comment and the other does not. Keep that distinction in mind; it comes back later, both in the attack and in the fix.

How XML libraries read text, and the surprise

The other ingredient is a subtle, and arguably unexpected, behaviour of XML libraries. A library here means a bundle of ready-made code that programmers reuse instead of writing everything from scratch. Python's lxml and Ruby's REXML are two such libraries, for the Python and Ruby programming languages respectively.

An API is the set of commands a library offers to the programmer. When you call an API, you ask the library to do something and it hands back a result. Think of it as a menu of services: you do not need to know how the kitchen works, you just order.

Consider this XML element, NameID:

XML
<NameID>kludwig</NameID>

If you wanted to extract the user identifier from that element in Python, you might write:

Python
from defusedxml.lxml import fromstring
payload = "<NameID>kludwig</NameID>"
data = fromstring(payload)
return data.text # should return 'kludwig'

Line by line:

  • from defusedxml.lxml import fromstring brings in a function called fromstring from a library. Its job is to turn a piece of XML text into a structured object the program can work with.
  • payload = "<NameID>kludwig</NameID>" stores the XML text in a variable called payload.
  • data = fromstring(payload) parses that text and gives back an object representing the element.
  • return data.text asks for the text inside the element. The comment says it should return kludwig, and it does.

That makes sense. The .text method extracts the text of the NameID element.

Now the surprise. Add a comment inside the element:

Python
from defusedxml.lxml import fromstring
doc = "<NameID>klud<!-- a comment? -->wig</NameID>"
data = fromstring(payload)
return data.text # should return ‘kludwig’?

Line by line:

  • The import is the same as before.
  • doc = "<NameID>klud<!-- a comment? -->wig</NameID>" stores an element whose text is split in two by a comment. <!-- ... --> is how a comment is written in XML. Comments are notes for humans; they are not meant to be displayed or to change meaning.
  • data = fromstring(payload) parses the text. Note that this line still refers to payload, the earlier variable, exactly as written in the write-up.
  • return data.text asks for the text again. The comment in the code asks whether it should return kludwig.

It does not. The .text API in lxml returns klud. The write-up's author says he would have expected the same result regardless of the comment, and thinks many others are in the same boat.

Why does it happen? The write-up explains that lxml is technically correct, if a bit unintuitive. Think of the XML document as a tree, with the element at the top and its contents as branches:

Text
element: NameID
|_ text: klud
|_ comment: a comment?
|_ text: wig

Reading this tree: the NameID element has three children in a row. First a piece of text, klud. Then a comment, a comment?. Then another piece of text, wig. The .text API only reads the first text child and stops. It does not read text after the first text node ends.

Compare that with the uncommented node, which is represented by:

Text
element: NameID
|_ text: kludwig

Here there is only one text child, kludwig, so stopping at the first text node gives the whole thing. In that case it makes perfect sense.

Ruby's REXML behaves in a similar way. The write-up quotes the documentation for its get_text method, which hints at why:

Text
[get_text] returns the first child Text node, if any, or nil otherwise. This method returns the actual Text node, rather than the String content.

In plain words: get_text gives you the first child that is a piece of text, or nothing if there is none. It gives you that node itself, not the combined text of the element. So if a comment sits in the middle, the text after it is simply not part of the first text node, and you do not get it.

The write-up notes that stopping text extraction after the first child, while unintuitive, might be fine if all XML APIs behaved this way. Unfortunately they do not. Some libraries have nearly identical APIs but handle text extraction differently:

Python
import xml.etree.ElementTree as et
doc = "<NameID>klud<!-- a comment? -->wig</NameID>"
data = et.fromstring(payload)
return data.text # returns 'kludwig'

Line by line:

  • import xml.etree.ElementTree as et brings in a different XML library, part of Python's standard toolkit, under the short name et.
  • doc = "<NameID>klud<!-- a comment? -->wig</NameID>" is the same commented element as before.
  • data = et.fromstring(payload) parses it with this library, again referring to payload as written.
  • return data.text asks for the text. This time the comment says it returns kludwig, the full text, comment or no comment.

So two libraries, similar-looking commands, different answers. That mismatch is the seed of the whole problem.

The write-up also mentions having seen implementations that do not use an XML API at all, but extract text manually by taking the inner text of a node's first child. That is just another path to the same substring behaviour: you get only part of the text.

The vulnerability itself

Now we can put the pieces together. The write-up lists three ingredients:

  1. SAML Responses contain strings that identify the authenticating user.
  2. XML canonicalization, in most cases, removes comments as part of signature validation, so adding comments to a SAML Response does not invalidate the signature.
  3. XML text extraction may return only a substring of the text within an XML element when comments are present.

A substring is just a piece of a longer string. If the full text is kludwig, then klud is a substring.

Here is the attack. Suppose you have an account on the SP with the address [redacted]. That is your own account, and you can log in to it normally. You take your own SAML assertion, the one the IdP signed for you, and you edit the NameID so that it reads [redacted] when the SP processes it. The write-up calls this a simple seven-character addition to the previous toy response. The payload is:

XML
<SAMLResponse>
    <Issuer>https://idp.com/</Issuer>
    <Assertion ID="_id1234">
        <Subject>
            <NameID>[redacted]<!---->.evil.com</NameID>
        </Subject>
    </Assertion>
    <Signature>
        <SignedInfo>
            <CanonicalizationMethod Algorithm="xml-c14n11"/>
            <Reference URI="#_id1234"/>
        </SignedInfo>
        <SignatureValue>
            some base64 data that represents the signature of the assertion
        </SignatureValue>
    </Signature>
</SAMLResponse>

Line by line, focusing on what changed:

  • The outer SAMLResponse, the Issuer, the Assertion with its ID, the Subject, the Signature block and the SignatureValue are all the same as the toy example.
  • The one difference is the NameID line: <NameID>[redacted]<!---->.evil.com</NameID>. The <!----> is an empty comment, a comment with nothing inside it. It sits right after [redacted] and before .evil.com.

Why does that work? The empty comment splits the text into two pieces. A parser that stops at the first text node reads only [redacted]. Meanwhile, canonicalization, in most cases, drops the comment, so the signed form is unchanged and the signature stays valid. The SP sees the victim's identifier, but the seal still matches.

An everyday comparison: imagine a form where a clerk reads only the first line of an address and ignores everything after a sticky note. You write the real address on line one, stick a note on line two with your own details, and the clerk reads the first line while the official stamp, which ignores sticky notes, still looks valid.

Why it works: the root cause

The mistake is a mismatch between how the signature is computed and how the identifier is read. Canonicalization removes comments before signing, so an attacker can insert comments without invalidating the signature. Text extraction APIs such as lxml's .text and REXML's get_text return only the first text node, so the value the SP reads differs from the value the IdP signed. Libraries that extract inner text manually from the first child produce the same result.

The XML signature, if done correctly, should prevent modification of the NameID, but here the modification is invisible to the canonicalized form that was signed. The seal is intact, but the letter has been read differently.

How much damage it can do

An attacker with authenticated access can trick a SAML system into authenticating as a different user without knowing that user's password. That is the core impact.

Beyond that, the write-up says the impact varies greatly. SAML IdPs and SPs are generally very configurable, so there is room to increase or decrease it. Two examples are given:

  • SPs that use email addresses and validate the domain against a whitelist are much less likely to be exploitable than SPs that allow arbitrary strings as user identifiers. A whitelist is a list of allowed values; if the domain must be on the list, a made-up address like [redacted] is less useful.
  • On the IdP side, openly allowing users to register accounts increases impact. A manual user provisioning process adds a barrier that makes exploitation less feasible. Provisioning means an administrator creates accounts by hand, rather than anyone signing up.

On two-factor authentication: if the SP enforces it, that helps a lot, because the vulnerability only bypasses the first factor. Two-factor authentication means logging in with two different things, typically a password plus a code. If the IdP is responsible for both the first and second factor, the vulnerability likely bypasses both.

How to fix it

Remediation, meaning the fix, depends on your relationship with SAML.

If you use Duo's software

Duo released updates for the Duo Network Gateway in version 1.2.10. If you use the DNG as a SAML Service Provider and are not at version 1.2.10 or higher (at the time of writing, 1.2.10 was the latest), upgrade. Duo's Product Security Advisory covers the details.

If you run or maintain an IdP or SP

The best remediation is to ensure your SAML processing libraries are not affected. The researcher identified several libraries that either used these unintuitive XML APIs or did faulty manual text extraction, and is sure there are more libraries that do not handle comments in XML nodes well.

Another possible remediation is defaulting to a canonicalization algorithm such as http://www.w3.org/2001/10/xml-exc-c14n#WithComments, which does not omit comments. With that algorithm, comments added by an attacker would invalidate the signature. Two caveats are given: the canonicalization algorithm identifier itself must not be subject to tampering, and the change requires IdP and SP support, which may not be universal.

If you maintain a SAML processing library

The most obvious fix is to ensure the library extracts the full text of an element when comments are present. Most SAML libraries the researcher found had unit tests, small automated checks that confirm the code behaves as expected. It was fairly easy to update tests that extracted properties like NameIDs by adding comments to pre-signed documents. If the tests still pass, that is a good sign; otherwise the library may be vulnerable.

Another option is to use the canonicalized XML document after signature validation for any processing such as text extraction. That could prevent this and other issues caused by canonicalization.

If you maintain an XML parsing library

The number of affected libraries suggests many users assume inner text APIs are not affected by comments. That could motivate changing an API's behaviour. The researcher does not think there is a clear right answer, and keeping the APIs as they are while improving documentation is a reasonable action. Improving the XML standards is another path: no standards identified during the research specified the correct behaviour, and it may be worth specifying how these related standards should interoperate.

If you want to look for this pattern yourself, the write-up lists these angles:

  • Other SAML libraries. Add a comment inside a NameID in a pre-signed test document and check whether the extracted value is truncated. A positive result is a NameID that reads as the victim's identifier while the signature still validates.
  • Manual text extraction. Look for code that reads the inner text of a node's first child rather than using an XML API. A positive result is the same substring behaviour with comments present.
  • Canonicalization algorithm. Check whether the SP accepts exc-c14n, which drops comments, rather than exc-c14n#WithComments. A positive result is a signed response whose comment insertion does not invalidate the signature.
  • Identifier policy. Check whether the SP allows arbitrary strings as user identifiers or validates email domains against a whitelist. A positive result is an SP that accepts arbitrary identifiers, widening the set of accounts an attacker can impersonate.
  • Registration policy. Check whether the IdP allows open registration. A positive result is self-service account creation, which lowers the barrier to obtaining an account to modify.

Disclosure timeline

Because the vulnerability affected multiple vendors, Duo worked with CERT/CC to coordinate disclosure. CERT/CC helped coordinate disclosure of this vulnerability.

Date Activity
2017-12-18 CERT/CC contacted and provided vulnerability information.
2017-12-20 CERT/CC follows up with questions about the issue.
2017-12-22 Response to questions from CERT/CC.
2018-01-02 to 2018-01-09 Additional email discussion with CERT/CC about the issue.
2018-01-24 CERT/CC completes internal analysis and contacts impacted vendors.
2018-01-25 Vendors acknowledge CERT/CC report. Additional communication with CERT/CC and vendors to further explain the issue and other attack vectors.
2018-01-29 Additional vendor that is potentially impacted identified and contacted by CERT/CC.
2018-02-01 Duo Labs reserves CVE numbers for each impacted vendor.
2018-02-06 Draft of CERT/CC vulnerability technical note reviewed and approved by Duo.
2018-02-20 Final confirmation that all impacted vendors are ready for disclosure date.
2018-02-27 Disclosure.

The write-up thanks CERT/CC for helping disclose the vulnerability and appreciates the efforts of everyone contacted by CERT/CC to respond quickly.

Glossary

  • SAML (Security Assertion Markup Language): a standard format for passing a signed statement about who a user is between systems, widely used for single sign-on.
  • SSO (single sign-on): logging in once with one account and being let into several different websites or apps.
  • Identity Provider (IdP): the system that holds your account and checks your password, for example Duo or GSuite.
  • Service Provider (SP): the website or app you want to use, which trusts the IdP's statement, for example Slack or Github.
  • SAML Response: the block of XML the IdP produces, containing the statement about the user and a signature.
  • Assertion: the part of the SAML Response that states which user the IdP authenticated.
  • NameID: the string inside the assertion that identifies the user, such as an email address.
  • Signature: a value produced by the IdP that proves the response has not been altered, like a wax seal on a letter.
  • Signature validation: the SP's check that the signature matches the content.
  • XML: a way of writing structured text using tags, used for SAML messages.
  • Element: one tagged piece of an XML document, such as NameID.
  • Node: one item in the tree structure of an XML document, such as a piece of text or a comment.
  • Comment: a note in XML written between <!-- and -->, meant for humans and not to change meaning.
  • Canonicalization: rewriting an XML document into one standard form so that documents with the same meaning look identical, character for character.
  • Byte representation: the exact sequence of bytes a computer stores for a piece of text.
  • CanonicalizationMethod: the element in a SAML Response that names which canonicalization algorithm is used.
  • exc-c14n: short for http://www.w3.org/2001/10/xml-exc-c14n#, a common canonicalization algorithm that omits comments.
  • exc-c14n#WithComments: the variant http://www.w3.org/2001/10/xml-exc-c14n#WithComments, which does not omit comments.
  • XML Signature specification: the standards document that outlines the canonicalization algorithms.
  • Library: a bundle of ready-made code that programmers reuse.
  • API: the set of commands a library offers to programmers.
  • lxml: a Python library for working with XML.
  • REXML: a Ruby library for working with XML.
  • get_text: a REXML method that returns the first child text node of an element.
  • xml.etree.ElementTree: a Python library for working with XML that handles comments differently from lxml.
  • Substring: a piece of a longer string.
  • Vulnerability class: a whole family of bugs that share the same underlying pattern, rather than one bug in one product.
  • CVE: a public catalogue number for a known security flaw.
  • Whitelist: a list of allowed values, such as approved email domains.
  • Provisioning: creating user accounts, either manually by an administrator or automatically.
  • Two-factor authentication: logging in with two different things, typically a password plus a code.
  • Remediation: the fix for a vulnerability.
  • Unit tests: small automated checks that confirm code behaves as expected.
  • CERT/CC: a publicly funded body that helps researchers and vendors coordinate the disclosure of vulnerabilities.
  • Disclosure: making the details of a vulnerability public.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.