Skip to content

fix(audit): redact cookie, credential, and private-key audit keys - #2620

Merged
vastsa merged 2 commits into
vastsa:mainfrom
DeryFerd:fix/audit-secret-key-redaction
Nov 26, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
DeryFerd:fix/audit-secret-key-redaction

Conversation

@DeryFerd

Copy link
Copy Markdown
Contributor

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.md section 6. The key list in crates/host-core/src/audit.rs covered secret, api_key, apikey, authorization, token, and password, but not cookie, credential, or private key. A payload keyed cookie, credentials, privateKey, or private_key therefore fell through to string-level redaction.

That fallback only catches assignment-shaped text such as cookie=... or token: ..., plus a few known provider prefixes. A raw cookie jar string or a PEM body matches neither pattern, so it reached audit_log nearly verbatim, bounded only by the 2 KiB string cap. audit.append and append_tx are shared by plan approval, plan execution, migration bookkeeping, tool execution, computer use, and the audit.append RPC, 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.md section 6 already names cookie, credential, and private key among 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 matches cookie, credential, private_key, and privatekey.
  • crates/host-core/src/audit.rs: added redacts_spec_named_credential_keys, which covers the four missing key shapes and keeps a negative control so sessionId stays intact.

client_secret was already caught by the secret substring, 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 --check passes.
  • cargo test -p host-core --locked audit:: passes (5 tests, including the new one).
  • cargo clippy -p host-core --all-targets reports nothing in the changed file. The crate has five pre-existing warnings elsewhere.
  • node scripts/check-pr-base-main.mjs passes, and origin/main is an ancestor of the head.

Full cargo test -p host-core --locked reports 1340 passed and 21 failed on this machine. The failures are the CRLF versus LF worktree and path tests such as session_worktrees::merge and rpc::worktree_rpc. They reproduce on an unmodified main checkout, and none touch audit.

E2E: NOT RUN, for two reasons. docs/spec/06-delivery/04-e2e-test-plan.md has 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 no node_modules or 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 bare jar field, which the current spec does not list either.

Notes

  • One file, one predicate, one test. No schema, migration, or protocol change.
  • Redacting a boolean field whose name happens to contain cookie or credential is accepted here, because the spec keys on the field name rather than the value type, and audit records are not consumed for control flow.

DeryFerd and others added 2 commits November 26, 2026 22:22
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 vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently verified the reported defect and the minimal fix against current main af9856a54.

  • Baseline Host built in the prior #2619 run: real audit.append RPC 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 29991a12a and current PR merge ref both have executable tree d8d4b172d3e09265e1a353fbcd2c365f205dc6fd, 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.

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
vastsa merged commit 8d686c2 into vastsa:main Nov 26, 2026
5 checks passed
someone97421 pushed a commit to someone97421/CK-PI-Desktop that referenced this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants