{"id":"HSEC-2026-0019","summary":"Signed-byte malleability and deferred exception in decodeSignedObject","details":"# Signed-byte malleability and deferred exception in decodeSignedObject\n\n`decodeSignedObject` (and so `decodeSignedCertificate` and `decodeSignedCRL`)\ndecoded a signed object with BER and rebuilt the bytes covered by the\nsignature by re-serialising the decoded ASN.1 events with\n`Data.ASN1.BinaryEncoding.Raw.toByteString`, lazily. It did not take them\nfrom the input. This had two consequences.\n\n## Differently encoded copies of a certificate keep a valid signature\n\nThe re-serialisation writes long-form lengths with the fewest octets, writes\ntags in their short form, and writes nothing for end-of-contents, so several\nencodings of the same `tbsCertificate` produce the same signed bytes. Other\nparts that the signature does not cover were accepted in non-DER form too.\nStarting from a genuine certificate, each of the following produced a\ncertificate whose `getSignedData` and signature were identical to the\noriginal's, so signature verification succeeded, while the encoding and\n`getFingerprint` differed:\n\n* a non-minimal long-form length, or a high-tag-number tag, on the\n  `tbsCertificate` SEQUENCE;\n* the outer Certificate SEQUENCE made indefinite-length, given a\n  high-tag-number tag, or preceded by an end-of-contents header;\n* a non-minimal length or high-tag-number tag on the `signatureAlgorithm`\n  SEQUENCE;\n* a non-minimal length on the signature BIT STRING, or an unused-bits octet\n  of `0x30` (ASCII `'0'`) instead of `0x00`.\n\nAnyone holding a certificate can therefore make copies with new fingerprints\nthat pass signature verification. This can defeat fingerprint denylists and\ndeduplication or caching keyed on the encoding. It does not allow changing\nany signed field (subject, key, validity, extensions, serial number), it does\nnot get past a fingerprint allowlist, SPKI pinning or serial-based\nrevocation, and TLS authentication still needs the private key. RFC 5280\nrequires DER for certificates for this reason.\n\n## A successfully decoded certificate can throw later\n\nA certificate containing a malformed long-form length inside an\nindefinite-length construction decoded as `Right`, but the re-serialisation\ncould not encode the decoded length. Forcing the signed bytes\n(`getSignedData`, or `show` of the `SignedExact`) then threw the pure\nexception `putLength: long length is negative`. No valid signature is needed\nto trigger it.\n\nThis is an availability issue for programs that force the value outside an\nexception handler, for example when logging a received certificate or\nloading a certificate store. `crypton-x509-validation` evaluates signature\nverification under `tryPure` and reports `SignatureInvalid`, and `tls`\ncatches handshake failures, so default TLS clients and servers are not known\nto be affected.\n\n## Fix\n\ncrypton-x509 1.11.1 takes the signed bytes from the input as received, so\nan altered `tbsCertificate` header now fails signature verification and\n`getSignedData` no longer throws. It also requires everything the signature\ndoes not cover (the outer SEQUENCE, which must span the whole input, the\n`signatureAlgorithm` and its contents, and the signature BIT STRING) to be\nin DER, with an unused-bits octet of `0x00`; such variants are now rejected\nwhen decoding.\n\nThe unmaintained `x509` package has the same code since at least 1.4.0 and\nhas no fixed release; users should move to `crypton-x509` \u003e= 1.11.1.\n\nReported by José Lorenzo Rodríguez (Kronor). Fixed by Kazu Yamamoto.\n","modified":"2026-12-06T21:45:02.876790114Z","published":"2026-12-06T21:29:17Z","database_specific":{"home":"https://github.com/haskell/security-advisories","osvs":"https://raw.githubusercontent.com/haskell/security-advisories/refs/heads/generated/osv-export","repository":"https://github.com/haskell/security-advisories"},"references":[{"type":"PACKAGE","url":"https://hackage.haskell.org/package/crypton-x509"},{"type":"FIX","url":"https://github.com/kazu-yamamoto/crypton-certificate/commit/92181cd43f16d4200ded832ea64fdd57b1ed9ce8"},{"type":"FIX","url":"https://github.com/kazu-yamamoto/crypton-certificate/commit/6ee5635a1e36e1e63aedbdc1e26e7650d565a1f8"}],"affected":[{"package":{"name":"crypton-x509","ecosystem":"Hackage","purl":"pkg:hackage/crypton-x509"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"1.7.6"},{"fixed":"1.11.1"}]}],"versions":["1.10.0","1.10.1","1.10.2","1.10.3","1.11.0","1.7.6","1.7.7","1.8.0","1.9.0","1.9.1","1.9.2"],"ecosystem_specific":{"affected_api":[{"module":"Data.X509","name":"decodeSignedObject"},{"module":"Data.X509","name":"decodeSignedCertificate"},{"name":"decodeSignedCRL","module":"Data.X509"}]},"database_specific":{"human_link":"https://github.com/haskell/security-advisories/tree/main/advisories/published/2026/HSEC-2026-0019.md","osv":"https://raw.githubusercontent.com/haskell/security-advisories/refs/heads/generated/osv-export/2026/HSEC-2026-0019.json","source":"https://github.com/haskell/security-advisories/blob/generated/osv-export/2026/HSEC-2026-0019.json"},"severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L"}]},{"package":{"name":"x509","ecosystem":"Hackage","purl":"pkg:hackage/x509"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"1.4.0"}]}],"versions":["1.4.0","1.4.1","1.4.10","1.4.11","1.4.12","1.4.13","1.4.2","1.4.3","1.4.4","1.4.5","1.4.6","1.4.7","1.4.8","1.4.9","1.5.0","1.5.0.1","1.5.1","1.6.0","1.6.1","1.6.2","1.6.3","1.6.4","1.6.5","1.7.0","1.7.1","1.7.2","1.7.3","1.7.4","1.7.5","1.7.6","1.7.7"],"ecosystem_specific":{"affected_api":[{"module":"Data.X509","name":"decodeSignedObject"},{"module":"Data.X509","name":"decodeSignedCertificate"},{"module":"Data.X509","name":"decodeSignedCRL"}]},"database_specific":{"human_link":"https://github.com/haskell/security-advisories/tree/main/advisories/published/2026/HSEC-2026-0019.md","osv":"https://raw.githubusercontent.com/haskell/security-advisories/refs/heads/generated/osv-export/2026/HSEC-2026-0019.json","source":"https://github.com/haskell/security-advisories/blob/generated/osv-export/2026/HSEC-2026-0019.json"},"severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L"}]}],"schema_version":"1.9.2"}