# RFC-0035: Blind Adversarial Review - **Status:** Accepted; every finding below is fixed or recorded as a residual risk. - **Owner:** Security owner. - **Last updated:** 2026-11-30 This is the second internal review, after RFC-0031. It is **not** the independent audit that RFC-0010 requires before 4.0.0: the reviewers were model instances run by the maintainers, and the fixes were made by the same maintainers. It reduces what an independent auditor will find; it does not replace one. ## Method Six reviewers worked in parallel, each on one area of `docs/v4/security/audit-scope.md`: the envelope core, the providers, COSE and the audit chain, the file system with the CLI and policy, the v3 migration, and the JavaScript implementation with the release pipeline. To keep the review independent of the maintainers' reasoning: - each started without this project's history and was told not to read RFC-0031 or later RFCs; its sources were the code, the normative specification, and the public standards; - the threat model was given only as a list of claims to break; - the repository was read-only to it, and it could not reach the network; - a finding counted only with a proof of concept that fails on the reviewed code. Every proof of concept was run again by the maintainers before any fix, and each fix has a regression test in the repository that fails without it. The review found no break of suite 1, of the key commitment, MAC, or context binding, of HPKE (RFC 9180 vectors and differential tests in all 36 classical suite combinations), or of the audit chain. Fuzzing of about 480,000 COSE inputs, 35,000 audit trails, and 3,000 envelope mutations found no undocumented exception beyond those listed here. ## Findings Severity is the reviewer's, confirmed by the maintainers. ### High | ID | Finding | Fix | Regression test | | --- | --- | --- | --- | | PROV-1 | A hierarchical provider unwrapped any branch-key record with whatever root key the record named, so a co-tenant could plant a branch key wrapped under its own key and read everything a tenant sealed afterwards. | A record is used only if the configured root key wrapped it: provider, key (directly or through the alias the root resolves), and version when pinned. | `test_hierarchical_keys.py::test_branch_keys_must_come_from_the_configured_root_key`, `::test_a_root_key_named_by_alias_or_pinned_version` | | PROV-2 | Custodians released their share to whatever coordinator key a request named, so anyone who could alter or originate requests recovered the data key. | `release_share(..., coordinator=fingerprint)`: the custodian verifies the ceremony fingerprint received out of band; the request token is bound to the coordinator key. Schemas `cs-quorum-share-request/2` and `cs-quorum-share-response/2`. | `test_quorum_ceremony.py::test_custodians_release_only_to_the_coordinator_they_were_told` | ### Medium | ID | Finding | Fix | Regression test | | --- | --- | --- | --- | | PROV-3 | Releases were unauthenticated: anyone could overwrite an honest release, block recovery, or have an absent custodian blamed. | Each request carries a token encrypted to its custodian; a release carries a MAC under it and is refused unless it verifies, before decryption. The first release for a share stands. | `test_quorum_ceremony.py::test_only_the_custodian_can_answer_a_request`, `::test_a_release_racing_a_duplicate_keeps_the_first` | | JS-1 | The JavaScript reader let the envelope choose the unwrapping key (the RFC-0031 F-1 defect, in the second implementation). | `openEnvelope` requires `trustedKeys`; untrusted recipients never reach `unwrap`; each key version is tried once; policy refusals are final. | `interop/javascript/test/review.test.mjs` (JS-1 tests), `test_javascript_interop.py` | | CORE-1 | A primary key service that hung until the deadline left no time for the escrow recipient. | The remaining deadline is shared among untried candidates; the operation's deadline is never extended. | `test_escrow_fallback.py` | | CORE-5 | Rewrap without `replace` replaced the recipient that happened to unwrap, so a migration during a primary outage dropped the escrow recipient. | Spec 8.4 rule 3 now replaces the first recipient, the sealer's primary; the choice does not depend on availability. | `test_escrow_fallback.py::test_a_migration_during_an_outage_keeps_the_escrow_recipient` | | CORE-2, MIG-6 | Streaming operations published before recording their required audit event; an audit failure was reported after the output existed. | The success event is recorded before the sink commits; if it cannot be, the sink is aborted. | `test_audit_before_publish.py` | | SYS-1 | On Windows, parent directories were held with no access, so another user could rename one and put a junction in its place, redirecting or overwriting output. | Parents are held with traverse access and without `FILE_SHARE_DELETE`, so no held component can be renamed. A live race of 1,621 attempts placed nothing outside the directory. | `test_filesystem_windows.py::test_held_parent_directories_cannot_be_swapped` | | SYS-2 | `--status-file` followed links and overwrote existing files. | It is published like any output: atomically, never over a file, never through a link. | `test_cli.py::test_the_status_file_never_replaces_a_file` | | MIG-1 | Loading a crafted unencrypted RSA key ran OpenSSL's primality checks on huge "primes": hours of CPU per inventory entry or import. | Only cheaply loaded algorithms are loaded, identified from the DER first; RSA keys load without the consistency check (only their public key is used). | `test_legacy_keys.py::test_a_crafted_rsa_key_costs_no_more_than_any_other` | | SC-1 | The release job ran unhashed tools before uploading what it built. | The build job installs only the hashed `requirements-build.txt` and builds without isolation; its artifact digests become its output, and every later job verifies them; checks and the SBOM run in a separate job. | `.github/workflows/release.yml` (reviewed, not executable locally) | | SC-3 | A tag on a commit outside `main` could release. | The verify job requires the tagged commit to be on `main`; the repository settings this relies on are listed in the workflow. | `.github/workflows/release.yml` | ### Low | ID | Finding | Fix | | --- | --- | --- | | JS-2 | A non-numeric limit disabled the JavaScript reader's limits. | Limits must be non-negative safe integers; unknown names are refused. | | JS-3 | The two readers differed: no plaintext limit for streaming, no CBOR item budget, a stack overflow joining many records, and suite identifiers above 2^53. | The JavaScript reader mirrors Python's checks and their order; a differential test covers the limit. | | JS-4 | Lone surrogates in a context became U+FFFD, so two contexts shared one encoding. | Contexts must be well-formed Unicode in both reader and sealer. | | JS-5 | The JavaScript sealer could emit envelopes no reader accepts. | Provider identifiers and metadata are validated, and the sealer parses its own output before returning it. | | SC-2 | Wheels carried the build machine's file modes and setuptools version. | The wheel is normalized like the sdist; setuptools is pinned; builds on Linux, Windows, and macOS are compared. | | SC-4 | The documentation, deployed with write access, installed unpinned dependencies. | `requirements-docs.txt`, hashed, from `tools/update_docs_lock.py`. | | COSE-1 | One message could cause 32 full-content decryptions. | At most two per message. | | COSE-2 | Each protected header had its own 65,536-item budget. | 256 items per protected header. | | AUDIT-1, SYS-4 | Deep JSON raised `RecursionError` in the audit verifier, policy and configuration parsers, branch-key records, and share messages. | Each reports its documented error. Configuration key identifiers are validated. | | PROV-4 | Azure's key fetch and unwrap each received the whole remaining time. | Each receives half. | | PROV-5 | A thread waiting for another's branch-key fetch ignored its own deadline and cancellation. | The wait observes both. | | PROV-6 | HPKE public key text accepted compressed P-384 points and low-order X25519 keys. | One spelling per key; low-order keys are refused when loaded or registered. | | PROV-7 | Cloud KMS symmetric unwrap accepted any version label. | Labels must be versions of the key (residual below). | | CORE-3 | Rewrap walked every record before checking recipients. | Recipients are verified first (residual below). | | CORE-4 | A stale size smaller than the prefix produced a negative record layout. | Refused as `FORMAT_INVALID` before any key is used. | | SYS-3, SYS-5 | JSON status carried raw control characters and could crash on a lone surrogate after a receipt was committed. | Status JSON is ASCII-escaped. | | SYS-6 | A recipient listed twice in a configuration silently replaced the first. | Duplicate key identifiers and providers are refused. | | MIG-2 | Failures before sealing left the destination's staging file. | Every failure aborts the destination without hiding the original error. | | MIG-3 | Cancellation did not reach the verifier thread. | It does, and a writer waiting on the verifier polls it. | | MIG-4 | Migration permission was checked only at the start. | It is checked again at publication. | | MIG-5 | Keystore timestamps accepted any separator character. | A strict ASCII timestamp. | | MIG-7 | Short reads of a `password-aes-v3` value cost quadratic time. | Linear. | Every finding fixed in code has a regression test whose docstring names its identifier; SC-2 and SC-4 are checked by the reproducibility and documentation workflows. ### Found after the review The automated Codex review of the pull requests that carry this work (#197 to #204) reported seven findings after this review closed. Two had already been fixed: the success event is recorded before publication (CORE-2), and the record walk of `inspect` and `rewrap` enforces the plaintext limit. The other five are fixed here, each with a test that fails on the code the review saw (`tests/integration/test_codex_review.py` unless named). | ID | Finding | Fix | Regression test | | --- | --- | --- | --- | | PROV-8 | Codex, #204 (P1). On a cache miss, a hierarchical provider copied the branch key for its caller only after releasing the cache lock; a concurrent eviction or `clear_cache()` could overwrite the cached buffer with zeros first, and the wrap then used 32 zero bytes, a publicly known key. | The caller's copy is taken before the buffer enters the cache. | `test_hierarchical_keys.py::test_a_branch_key_is_copied_before_the_cache_shares_it` | | SYS-7 | Codex, #197 (P1). Two sinks overwriting one file could both pass the identity check before either replaced it; both reported success and the second silently replaced the first's output. | Within a process, the check and the replacement of one file are serialized, so the second finds the file changed and fails. Across processes no portable rename replaces only a file of a given identity; this is a residual risk below. | `test_concurrent_overwrites_of_one_file_cannot_both_succeed` | | SYS-8 | Codex, #197 (P2). On POSIX a root spelled with a trailing `/` or `/.` made its last component an intermediate one, so a linked root was followed despite `O_NOFOLLOW`. | Trailing separators are dropped; `.` and `..` components are refused. | `test_a_linked_root_is_refused_however_it_is_spelled`, `test_trailing_separators_are_dropped_and_dot_components_refused` | | CORE-6 | Codex, #198 (P2). An exception raised by a caller's own sink reached the caller unchanged: outside `CryptographySuiteError`, and with whatever the sink put in its message. | SDK errors pass unchanged; anything else becomes a redacted `OperationalError(IO_FAILED)`. | `test_a_sinks_own_failure_is_typed_and_redacted` | | SC-5 | Codex, #199 (P2). The release workflow accepted a changelog entry for `4.0.0rc1` or `4.0.01` as one for `4.0.0`. | The version must end where the entry's version ends. | `test_release_changelog_check_needs_the_exact_version` | ## Residual risks - **Record-count work (CORE-3).** An envelope author chooses the chunk size, and the format allows 1 byte, so opening costs time linear in the number of records, bounded by `max_plaintext_bytes` and `max_stream_bytes`. A reader-side minimum chunk size would refuse valid envelopes and needs a format decision; until then, lower the limits for untrusted senders. - **Cloud KMS symmetric versions (PROV-7).** The service picks a symmetric key's version from the ciphertext and does not report it, so a version pin is not enforced for those keys. Every version belongs to the same trusted key. - **Planting with wrap rights (PROV-1).** A party that can both wrap under the root key and write to the branch-key store can still plant a branch key it knows. Keep store writes with key administrators, and prefer a root whose wrap needs authorization over a public HPKE key. - **COSE content attempts (COSE-1).** Two content decryptions per message remain allowed, so one lifted recipient can be passed over. - **Repository and release settings (SC-3).** The tag ruleset, the `pypi` environment's reviewers and tag rule, and the PyPI trusted publisher's binding to that environment are settings outside the repository and must be applied by an owner. The check job's tooling is pinned by version, not hash; it cannot change what is published. - **Windows ancestors (SYS-1).** Components above the configured output root are the caller's choice and are not pinned. - **Overwrites across processes (SYS-7).** Two processes that overwrite the same file at the same moment can both succeed, the later one replacing the earlier's output; within one process the second fails. Give each writer its own destination, or coordinate writers that share one. ## Changes to other documents - Specification section 8.4, rule 3 (CORE-5). - Threat model claims C-3, C-12, C-13, C-14, C-17, C-18, C-21, C-22, and C-24. - `docs/guide/quorum-recovery.md` and `examples/quorum_ceremony.py` for the ceremony fingerprint; `interop/javascript/README.md` for `trustedKeys`.