Skip to content
Account takeover Disclosed report Advanced

SAML authentication bypass

The SAML authentication code verifies the first XML signature found anywhere in the response, but then reads assertions from the first Response element, without checking that the signature covers that element. An attacker can prepend an unsigned malicious Response element to a valid signed response, so the signature check passes on the original while the malicious assertions are used, allowing login as any user including administrator.

tomp1 Follow

Originally disclosed on HackerOne

High 8.8 View original
  • Triaged in 6 days
  • Fixed in 2 months
  • Disclosed after 3 months

Summary

When using SAML authentication, responses are not checked properly. This allows attacker to inject/modify any assertions in the SAML response and thus, for example, authenticate as administrator.

Description

Following code snippets are from app/meteor-accounts-saml/server/saml_utils.js When checking the signature, the first Signature element which is found in the whole response XML is used:

316 const signature = xmlCrypto.xpath(doc, '//*[local-name(.)=\'Signature\' and namespace-uri(.)=\'http://www.w3.org/2000/09/xmldsig#\']')[0];

After the XML signature has been verified, the code proceeds to use the first Response element found in the whole XML to get assertions and attributes.

516 const response = doc.getElementsByTagNameNS('urn:oasis:names:tc:SAML:2.0:protocol', 'Response')[0];

However there is no check that the signature that was checked relates to the response element that is being used. Thus attacker can take a valid SAML response, with some valid signature, and add Response element, that has no signatures, in the beginning of the XML. The code finds the original signature and validates that, but proceeds to use the malicious Response element, which is found first in the document.

Also the validating the status from the response happens before signature validation

501 const statusValidateObj = self.validateStatus(doc);

Releases Affected:

Tested on 3.0.3 but appears to affect all versions based on the history of saml_utils.js file.

Steps To Reproduce (from initial installation to vulnerability):

  1. Configure the application to use SAML authentication
  2. When logging in, intercept the POST request with a proxy tool
  3. Use the attached samlbypasspoc.py file to create a new value for the parameter SAMLResponse. Run the script in python3 with the URL encoded SAMLResponse as argument.
  4. Replace the parameter value with the one given by the POC script and forward the request

This requires altering the POC to suite the configuration. Beginning from the line 25, you can alter the response elements as needed to desired values.

In the sample POC file, attributes OrganizationName and Email and the element NameID are changed. In the setup I tested this resulted in login as a newly created admin.

Supporting Material/References:

  • samlbypasspoc.py

Suggested mitigation

  • Refactor the code so that the same elements (references) are used when checking the signature and when reading the attributes
  • Do not use hard coded indexes when selecting the elements

Impact

SAML authentication can be bypassed and attacker can log in as any user (e.g. admin user)

The original report as published on HackerOne, by tomp1. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

SAML authentication can be bypassed and an attacker can log in as any user, such as an administrator.

What the attacker needed

SAML authentication enabled; ability to intercept and modify login request; valid signed SAML response

The fix

The code should be refactored so that the same element references are used for signature verification and attribute reading, and hard-coded indexes should be avoided.

How it was found

  1. Configure the application to use SAML authentication.
  2. Intercept the login POST request with a proxy tool.
  3. Use the provided script to generate a new SAMLResponse value.
  4. Replace the SAMLResponse parameter with the generated value and forward the request.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

SAML is a way for websites to let you log in using an external identity provider. The website receives a signed message (a 'response') saying who you are. This report shows the website checked a signature on one part of the message but then used a different, unsigned part to decide who you are, so an attacker could pretend to be anyone.

What is Account takeover?

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.

More from Rocket.Chat

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.