HSEC-2026-0019: Signed-byte malleability and deferred exception in decodeSignedObject
Signed-byte malleability and deferred exception in decodeSignedObject
decodeSignedObject (and so decodeSignedCertificate and decodeSignedCRL) decoded a signed object with BER and rebuilt the bytes covered by the signature by re-serialising the decoded ASN.1 events with Data.ASN1.BinaryEncoding.Raw.toByteString, lazily. It did not take them from the input. This had two consequences.
Differently encoded copies of a certificate keep a valid signature
The re-serialisation writes long-form lengths with the fewest octets, writes tags in their short form, and writes nothing for end-of-contents, so several encodings of the same tbsCertificate produce the same signed bytes. Other parts that the signature does not cover were accepted in non-DER form too. Starting from a genuine certificate, each of the following produced a certificate whose getSignedData and signature were identical to the original's, so signature verification succeeded, while the encoding and getFingerprint differed:
a non-minimal long-form length, or a high-tag-number tag, on the tbsCertificate SEQUENCE; the outer Certificate SEQUENCE made indefinite-length, given a high-tag-number tag, or preceded by an end-of-contents header; a non-minimal length or high-tag-number tag on the signatureAlgorithm SEQUENCE; a non-minimal length on the signature BIT STRING, or an unused-bits octet of 0x30 (ASCII '0') instead of 0x00.
Anyone holding a certificate can therefore make copies with new fingerprints that pass signature verification. This can defeat fingerprint denylists and deduplication or caching keyed on the encoding. It does not allow changing any signed field (subject, key, validity, extensions, serial number), it does not get past a fingerprint allowlist, SPKI pinning or serial-based revocation, and TLS authentication still needs the private key. RFC 5280 requires DER for certificates for this reason.
A successfully decoded certificate can throw later
A certificate containing a malformed long-form length inside an indefinite-length construction decoded as Right, but the re-serialisation could not encode the decoded length. Forcing the signed bytes (getSignedData, or show of the SignedExact) then threw the pure exception putLength: long length is negative. No valid signature is needed to trigger it.
This is an availability issue for programs that force the value outside an exception handler, for example when logging a received certificate or loading a certificate store. crypton-x509-validation evaluates signature verification under tryPure and reports SignatureInvalid, and tls catches handshake failures, so default TLS clients and servers are not known to be affected.
Fix
crypton-x509 1.11.1 takes the signed bytes from the input as received, so an altered tbsCertificate header now fails signature verification and getSignedData no longer throws. It also requires everything the signature does not cover (the outer SEQUENCE, which must span the whole input, the signatureAlgorithm and its contents, and the signature BIT STRING) to be in DER, with an unused-bits octet of 0x00; such variants are now rejected when decoding.
The unmaintained x509 package has the same code since at least 1.4.0 and has no fixed release; users should move to crypton-x509 >= 1.11.1.
Reported by José Lorenzo Rodríguez (Kronor). Fixed by Kazu Yamamoto.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
hackage/crypton-x509to a version that resolves this vulnerability.Fixed in 1.11.1 - Upgrade
Upgrade
crypton-x509to a version that resolves this vulnerability.Fixed in 1.11.1
Event History
Frequently Asked Questions
What must an attacker have to exploit the signature-validation issue?
An attacker needs a genuine certificate or other signed object that they can re-encode. The issue allows multiple encodings of the same signed content to retain a valid signature while producing different raw encodings and fingerprints.
Which encodings are relevant to the malleability issue?
Examples include non-minimal long-form lengths or high-tag-number encoding on the tbsCertificate SEQUENCE. The outer Certificate SEQUENCE could also be encoded with indefinite length, a high-tag-number tag, or other accepted non-DER forms outside the signed portion.
How could this affect systems that identify certificates by fingerprint?
The same signed certificate content can have a different getFingerprint value after re-encoding, even though getSignedData and signature verification remain identical to the original. Systems that rely on fingerprints as a unique identity or allowlist key may therefore treat a re-encoded copy differently.
Which decoding APIs are affected?
The behavior is in decodeSignedObject and therefore also affects decodeSignedCertificate and decodeSignedCRL.