Skip to content
OAuth / SSO Write-up Advanced

SAML roulette: the hacker always wins

The ruby-saml library used by GitLab parses SAML responses with two different XML parsers (REXML and Nokogiri), and inconsistencies between them allow an attacker to forge a signed assertion and bypass signature validation. This enables unauthenticated admin access to GitLab Enterprise.

portswigger.net

Published on portswigger.net

While researching this, GitHub independently discovered and patched our vulnerabilities. However, their disclosure omits key technical details, including the specific mutation and how to exploit it without authentication.

The author, on portswigger.net

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.

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

How it worked

Root cause

Likely the use of two different XML parsers (REXML and Nokogiri) for validation and attribute extraction, combined with parser differentials in handling namespace declarations and round-trip mutations, allows signature bypass.

Impact

An attacker could gain unauthenticated administrator access to GitLab Enterprise, leading to full account takeover.

What the attacker needed

GitLab using ruby-saml; Ruby < 3.4.2 (for combined attack); Access to signed WS-Federation metadata; No authentication required

The fix

The vulnerabilities were fixed in GitLab versions 17.9.2, 17.8.5, and 17.7.7; the underlying issue should be fixed by using the same library for parsing and validating signed XML documents and avoiding marshaling/unmarshaling untrusted data.

How it was found

  1. Create a SAML response with a forged assertion and a valid signature element extracted from publicly available WS-Federation metadata.
  2. Use a DOCTYPE with an ATTLIST to define conflicting namespace attributes for the Signature element, causing REXML to read a fake digest while Nokogiri reads the real one.
  3. Exploit REXML's truncation of ATTLIST strings in Ruby < 3.4.2 to make the attack work on GitLab.
  4. Submit the crafted SAML response to GitLab to bypass authentication and gain admin access.

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 write-up 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 library that checks the login response used two different XML parsers, and they disagreed on what the document said. An attacker could craft a response that looked valid to one parser but contained a fake assertion, letting them log in as any user, including an admin.

What is OAuth / SSO?

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.

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.