Skip to main content
Menu
Advisories

XML signature verification bypass in 6.0.0: non-base64 SignatureValue is accepted

GHSA-RM7M-7JQ4-GW46Published Updated GitHub

Description

Affected: litesaml/lightsaml 6.0.0 (with robrichards/xmlseclibs 4.0.0). 5.1.0 with xmlseclibs 3.1.5 is not affected.

Severity: Critical: an unauthenticated attacker can forge a SAML Response that passes signature validation.

Summary

SignatureXmlReader::validate() treats a return value of -1 from XMLSecurityDSig::verify() as success:

// src/Model/XmlDSig/SignatureXmlReader.php:69
if (false == $this->signature->verify($key)) {

xmlseclibs documents verify() as returning 1 on success, 0 on failure, and -1 on error, and warns that it must be checked with === 1. In xmlseclibs 4.0, verify() base64-decodes the SignatureValue in strict mode and returns -1 if the decoding fails. It also returns -1 from XMLSecurityKey::verifySignature() whenever phpseclib throws or the key can't be loaded. Because false == -1 is false, lightsaml doesn't throw, and validate() returns true.

Reproduction

  1. Take any Response signed by the IdP.
  2. Change the signed content, for example set the NameID to admin.
  3. Recompute the Reference DigestValue (exclusive C14N of the Response without its Signature, then SHA-256). This needs no key.
  4. Replace SignatureValue with !!!!.
  5. Deserialize the Response and call $response->getSignature()->validate(KeyHelper::createPublicKey($idpCert)).

Result: validateReference() passes because the digest was recomputed, verify() returns -1, and validate() returns true. The forged NameID is then trusted. With a random but valid-base64 SignatureValue, verify() returns 0 and the Response is correctly rejected. On 5.1.0 every variant is rejected.

Suggested fix

Check the result strictly in both readers:

// SignatureXmlReader::validate()
if (1 !== $this->signature->verify($key)) {

// SignatureStringReader::validate() (line 63): same pattern, not exploitable via a
// non-base64 value in my testing, but it has the same -1 handling
if (1 !== $key->verifySignature($this->getData(), $signature)) {

A regression test with a non-base64 SignatureValue after a recomputed digest would cover this.

Patches

Fixed in 6.0.1 (#129): both SignatureXmlReader::validate() and SignatureStringReader::validate() now only accept a strict 1 result. Users of 6.0.0 should upgrade to ^6.0.1.

Workarounds

If upgrading is not possible, stay on (or downgrade to) ^5.1.0, which uses xmlseclibs 3.x and is not affected.

Affected versions

References

GitHub · litesaml/lightsaml