OSEC-2026-12

See a problem?
Import Source
https://github.com/ocaml/security-advisories/blob/generated-osv/2026/OSEC-2026-12.json
JSON Data
https://api.osv.dev/v1/vulns/OSEC-2026-12
Published
2026-07-27T19:00:00Z
Modified
2026-08-07T13:30:06.466504252Z
Severity
  • 6.2 (Medium) CVSS_V3 - CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N CVSS Calculator
Summary
AEAD `decrypt_into` functions writes plaintext before checking the tag
Details

On the generic GCM path, AES.GCM.authenticate_decrypt_into (as well as Chacha20.authenticate_decrypt_into and AES.CCM16.authenticate_decrypt_into) writes the decrypted plaintext into the caller's destination buffer and only then compares the tag. On a forged tag the function returns false, but the destination buffer already holds the full plaintext. AEAD decryption is meant to be all-or-nothing: no plaintext should be released until the tag verifies. This is a release of unverified plaintext, and a caller that reads the buffer without first checking the return value sees forged-but-decrypted data. RustCrypto's aes-gcm fixed the same defect in CVE-2023-42811 (rated medium) by re-encrypting the buffer on tag failure.

Solution

The tag is validated first, and only if the tag is valid, the decryption into the provided buffer is done. In the CCM code, the tag is computed over the plaintext - if the tag validation fails, the provided buffer is zeroed.

Reproduction

module GCM = Mirage_crypto.AES.GCM

let () =
  let key = GCM.of_secret (String.make 32 '\x00') in
  let nonce = String.make 12 '\x00' in
  let secret = "let password = 42" in
  let len = String.length secret in
  let blob = GCM.authenticate_encrypt ~key ~nonce secret in
  (* flip one bit of the 16-byte tag (at offset len); the ciphertext is untouched *)
  let forged = Bytes.of_string blob in
  Bytes.set forged len (Char.chr (Char.code (Bytes.get forged len) lxor 1));
  let forged = Bytes.unsafe_to_string forged in
  let dst = Bytes.make len '\x00' in
  let verified =
    GCM.authenticate_decrypt_into ~key ~nonce forged ~src_off:0 ~tag_off:len dst
      ~dst_off:0 len
  in
  Printf.printf "tag verified: %b (the message is rejected as forged)\n" verified;
  Printf.printf "secret left in the output buffer: %S\n" (Bytes.to_string dst)

Timeline

  • June 25th 2026: report to ocaml/security-advisories
  • June 29th: acknowledgement of issue with several questions for the reporter
  • July 6th: answers from reporter, including a patch
  • July 27th: release of mirage-crypto 2.2.0 and security advisory
Database specific
{
    "osv": "https://github.com/ocaml/security-advisories/tree/generated-osv/2026/OSEC-2026-12.json",
    "human_link": "https://github.com/ocaml/security-advisories/tree/main/advisories/2026/OSEC-2026-12.md",
    "cwe": [
        "CWE-347"
    ]
}
References
Credits
    • Thomas Gazagnaire - REPORTER
    • Thomas Gazagnaire - REMEDIATION_DEVELOPER
    • Hannes Mehnert - REMEDIATION_REVIEWER

Affected packages

opam / mirage-crypto

Package

Name
mirage-crypto
Purl
pkg:opam/mirage-crypto

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
2.2.0
Type
GIT
Repo
https://github.com/mirage/mirage-crypto.git
Events
Introduced
0 Unknown introduced commit / All previous commits are affected
Fixed

Affected versions

0.*
0.6.0
0.6.1
0.6.2
0.7.0
0.8.0
0.8.1
0.8.2
0.8.3
0.8.4
0.8.5
0.8.6
0.8.7
0.8.8
0.8.9
0.8.10
0.9.0
0.9.1
0.9.2
0.10.0
0.10.1
0.10.2
0.10.3
0.10.4
0.10.5
0.10.6
0.10.7
0.11.0
0.11.1
0.11.2
0.11.3
1.*
1.0.0
1.1.0
1.2.0
2.*
2.0.0
2.0.1
2.0.2
2.0.3
2.1.0
v2.*
v2.1.0
v2.0.3
v2.0.2
v2.0.1
v2.0.0
v1.*
v1.2.0
v1.1.0
v1.0.1
v1.0.0
v0.*
v0.11.3
v0.11.2
v0.11.1
v0.11.0
v0.10.7
v0.10.6
v0.10.5
v0.10.4
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.2
v0.9.1
v0.9.0
v0.8.10
v0.8.9
v0.8.8
v0.8.7
v0.8.6
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.0
v0.6.2
v0.6.1
v0.6.0

Ecosystem specific

{
    "opam_constraint": "mirage-crypto {< \"2.2.0\"}",
    "affected_bindings": [
        "Mirage_crypto.AES.CCM16.authenticate_decrypt_into",
        "Mirage_crypto.AES.CCM16.unsafe_authenticate_decrypt_into",
        "Mirage_crypto.Chacha20.authenticate_decrypt_into",
        "Mirage_crypto.Chacha20.unsafe_authenticate_decrypt_into",
        "Mirage_crypto.AES.GCM.authenticate_decrypt_into",
        "Mirage_crypto.AES.GCM.unsafe_authenticate_decrypt_into"
    ]
}

Database specific

source
"https://github.com/ocaml/security-advisories/blob/generated-osv/2026/OSEC-2026-12.json"