Repository navigation
fix(audit): redact cookie, credential, and private-key audit keys - #2620
Conversation
Spec 09 section 6 requires audit keys matching token, secret, password, API key, authorization, cookie, credential, private key, and client secret to be redacted. The key predicate only covered a subset, so payloads keyed `cookie`, `credentials`, or `privateKey` fell through to string redaction, which does not catch a raw cookie jar or a PEM body. Extend the predicate and add a regression test for the missing key shapes plus a negative control.
vastsa
left a comment
There was a problem hiding this comment.
Independently verified the reported defect and the minimal fix against current main af9856a54.
- Baseline Host built in the prior #2619 run: real
audit.appendRPC writes raw cookie, credentials, privateKey, private_key and nested uppercase COOKIE values to SQLite. - Integration candidate
db74258a04e17311a983b64b64a6598d8bf01a00: the same real RPC/SQLite probe redacts all five values while retaining sessionId and numeric metadata. cargo test -p host-core --locked audit::: 5 passed; locked Host build, cargo fmt and diff check passed. Clippy passed with two warnings in unchanged code.- Updated this PR branch through GitHub's non-destructive update-branch operation to include current main. New head
29991a12aand current PR merge ref both have executable treed8d4b172d3e09265e1a353fbcd2c365f205dc6fd, identical to the tested candidate.
The production change is confined to the existing centralized key predicate; it preserves prior redaction and storage contracts. Relevant end-to-end validation exercised the actual Host RPC-to-SQLite boundary with isolated temporary data. Full crate tests and Electron UI journeys were not run locally; hosted CI is still running and must pass before landing.
There was a problem hiding this comment.
AIUO CodePilot · Preliminary review
Diff-only preliminary review of the audit redaction predicate change in `crates/host-core/src/audit.rs`: the new key substrings (`cookie`, `credential`, `private_key`, `privatekey`) match the stated spec keys and the accompanying unit test covers the four named shapes plus a `sessionId` negative control. No verified defect is evidenced on the added lines themselves. Verification limits: no repository access or test execution, so the reported `cargo`/`clippy`/base-branch results and the pre-existing 21 full-suite failures are unverified; behavior of the pre-existing fallbacks and non-matching producers (e.g. a bare `jar` key) is outside what this diff proves.
No evidenced findings in the supplied diff.
Head: 29991a1
Base: af9856a
CI: pending; mergeable: true.
Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.
来源:上游 vastsa#2620 的 03e19e0 与 vastsa#2550 的 2857aee。
Summary / 概要
Audit records can carry cookies, credential blobs, and private keys, and the redaction rules are written down in
docs/spec/03-runtime/09-logging-and-observability.mdsection 6. The key list incrates/host-core/src/audit.rscoveredsecret,api_key,apikey,authorization,token, andpassword, but notcookie,credential, orprivate key. A payload keyedcookie,credentials,privateKey, orprivate_keytherefore fell through to string-level redaction.That fallback only catches assignment-shaped text such as
cookie=...ortoken: ..., plus a few known provider prefixes. A raw cookie jar string or a PEM body matches neither pattern, so it reachedaudit_lognearly verbatim, bounded only by the 2 KiB string cap.audit.appendandappend_txare shared by plan approval, plan execution, migration bookkeeping, tool execution, computer use, and theaudit.appendRPC, so the gap applied to every producer.Requirement link / 需求关联
No tracking issue exists for this fix. The requirement is the checked-in spec:
docs/spec/03-runtime/09-logging-and-observability.mdsection 6 already namescookie,credential, andprivate keyamong the keys that must be redacted. This change makes the implementation match it.What changed
crates/host-core/src/audit.rs: the key predicate now also matchescookie,credential,private_key, andprivatekey.crates/host-core/src/audit.rs: addedredacts_spec_named_credential_keys, which covers the four missing key shapes and keeps a negative control sosessionIdstays intact.client_secretwas already caught by thesecretsubstring, so it needed no separate branch. The change is additive: no key that was redacted before stops being redacted, and keys that match nothing keep their value. Payloads that use one of the new substrings now lose that field's value in the audit record, which is the intended trade for a diagnostics surface.Validation
cargo fmt --checkpasses.cargo test -p host-core --locked audit::passes (5 tests, including the new one).cargo clippy -p host-core --all-targetsreports nothing in the changed file. The crate has five pre-existing warnings elsewhere.node scripts/check-pr-base-main.mjspasses, andorigin/mainis an ancestor of the head.Full
cargo test -p host-core --lockedreports 1340 passed and 21 failed on this machine. The failures are the CRLF versus LF worktree and path tests such assession_worktrees::mergeandrpc::worktree_rpc. They reproduce on an unmodifiedmaincheckout, and none touchaudit.E2E:
NOT RUN, for two reasons.docs/spec/06-delivery/04-e2e-test-plan.mdhas no scenario for audit-table redaction; E2E-034 covers NDJSON log files, which this change does not modify, and the audit table is internal host state rather than user-visible or protocol-visible output. The machine also has nonode_modulesor Electron install. The unit test above is the alternative evidence. The remaining risk is a producer that names a credential field with none of these substrings, for example a barejarfield, which the current spec does not list either.Notes
cookieorcredentialis accepted here, because the spec keys on the field name rather than the value type, and audit records are not consumed for control flow.