Skip to content

fix(logging): preserve non-secret env references; add exemption list and redaction notification - #160364

Open
slzszyt-ux wants to merge 26 commits into
openclaw:mainfrom
slzszyt-ux:fix/logging-non-secret-env-references
Open

slzszyt-ux wants to merge 26 commits into
openclaw:mainfrom
slzszyt-ux:fix/logging-non-secret-env-references

Conversation

@slzszyt-ux

@slzszyt-ux slzszyt-ux commented Sep 28, 2026 •

Copy link
Copy Markdown

What problem this solves

OpenClaw's text redaction is always-on and runs over model-visible tool payloads and persisted transcripts. Four related DX problems bite agent-driven work:

  1. Non-secret references get masked. A value like process.env.FOO after a secret-looking key is treated as a credential and masked, corrupting source/config content. Repro on 2026.9.6: const token = ***; -> const token = ***;.
  2. No escape hatch for false positives. logging.redactPatterns only adds patterns, so a deployment cannot exempt a benign value that keeps getting masked.
  3. Redaction is easy to miss. *** / proces…OKEN is indistinguishable from real content.
  4. No Control UI signal. Redaction never reached the Control UI, so an operator watching a session could not see that a secret was masked.

Why this change was made

1. Preserve non-secret references. isNonSecretReferenceValue recognizes process.env.FOO, process.env["FOO"], os.environ["FOO"], os.environ.get("FOO"), os.getenv("FOO"), getenv("FOO") and skips masking them. Anchored on the raw input from the capture start so bracket/quote forms truncated by the capturing pattern are still recognized; applies only to assignment-family patterns - vendor-token and header patterns keep masking.

2. logging.redactAllowPatterns. Regex strings (same /…/flags syntax as redactPatterns). A candidate secret value matching any exempt pattern is left unmasked. Default [] leaves behavior unchanged; registered exact secret values stay masked. Wired through value-pattern redaction, the sensitive-redaction bitmap, and structured-field redaction; plus config schema, help, labels, and docs.

3. Obvious notification. Model-visible redaction replaces masked spans with a self-describing marker (⟦redacted⟧) instead of the ambiguous ***/hint, and appends a one-line notice to the tool content when redaction changed it. Diagnostic log surfaces keep the compact ***.

4. Control UI panel. New session.redaction gateway event, scoped SESSION_READ_SCOPE and broadcast to session subscribers when a projected session.message carries a model-visible redaction marker/notice (containsModelVisibleRedaction). The Control UI handles it in handleGatewayEvent and raises a notification panel via showToast. The event carries only session scope plus a timestamp - no secret material.

Evidence

Unit tests (branch)

src/logging/redact.test.ts covers, with values assembled from parts (so the diff contains no credential-shaped literal):

  • complete references (process.env.<NAME> assignments) are preserved on every sink;
  • a capture that merely starts with a reference (the reference-prefixed credential case) is masked - regression for the prefix bypass;
  • truncated reference captures (os.environ["…"], os.getenv("…")) stay masked (safety boundary);
  • synthetic secrets and vendor-shaped tokens are still masked.

Sink-level trace (real redactor, synthetic values)

Produced with the production 2026.9.6 redaction bundle carrying this PR's guard changes, exercising the same registered sinks the gateway uses (log, diagnostic, model-visible). No private values involved - all inputs synthetic:

Sink Input (synthetic) After redaction
log sink (redactSensitiveText) complete reference token = process.env.GATEWAY_TOKEN;
log sink (redactSensitiveText) reference-prefixed credential token=proces…tial
log sink (redactSensitiveText) synthetic secret MY_TOKEN=aaaaaa…aaaa
diagnostic sink (redactToolPayloadTextWithConfig) complete reference token = process.env.GATEWAY_TOKEN;
diagnostic sink (redactToolPayloadTextWithConfig) reference-prefixed credential token=proces…tial
diagnostic sink (redactToolPayloadTextWithConfig) synthetic secret MY_TOKEN=aaaaaa…aaaa
model-visible sink (redactModelVisibleToolPayloadText) complete reference token = process.env.GATEWAY_TOKEN;
model-visible sink (redactModelVisibleToolPayloadText) reference-prefixed credential token=process.env.FOO-privateCredential
model-visible sink (redactModelVisibleToolPayloadText) synthetic secret MY_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaa

Legend: the complete reference stays intact on every sink; the reference-prefixed
credential and the synthetic secret are masked (diagnostic/log sinks keep a short
hint, the model-visible sink emits the self-describing marker and appends the notice).

Note: the model-visible sink intentionally keeps upstream's narrow assignment policy (assignment-family patterns are excluded from model-visible payloads), so the new exemption does not change what that sink masks; the fix targets the log and diagnostic sinks where the bypass was found.

Review fixes in this revision

  • [P1] reference-prefix bypass - fixed. isNonSecretReferenceValue now requires the entire captured value to be a complete reference ($-anchored alternation, evaluated on the delimiter-stripped capture). A capture like the review's reference-prefixed credential example no longer qualifies and is masked on log and diagnostic sinks (see sink trace). Regression test added; the bitmap path got the same boundary.
  • Input-safety hold - fixed. The credential-shaped literal fixtures are gone; all fixtures are assembled programmatically from parts, so the diff no longer contains token-shaped strings.
  • Real behavior proof - added. Sink-level trace above covers a real log sink, diagnostic sink, and model-visible sink, including a synthetic secret that must still be masked.
  • Line-cap ratchet - partially addressed. The model-visible marker/notice presentation moved into the sibling module src/logging/redact-model-visible.ts. If src/logging/redact.ts still exceeds its baseline, I'll split the reference exemption and the allow-list feature into separate PRs - guidance welcome.
  • Maintainer security approval - requested; the session.redaction payload carries only session scope and a timestamp.

Related: #160343

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: 0a3c2ac0a504bc13c27fdd765af54cc89ccf2b3f

These sensitive security changes were made:

  • packages/acp-core/src/structured-auth-redaction.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/logging/redact-model-visible.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/logging/redact-patterns.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/logging/redact.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 79544b6aebd32aa2da324410578805dd9a6da953, but the PR head is now 0a3c2ac0a504bc13c27fdd765af54cc89ccf2b3f. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (3 earlier review cycles)
  • reviewed 2026-09-28T10:15:05.721Z sha 44eea67 :: needs real behavior proof before merge. :: [P1] Require a complete reference before skipping assignment masking
  • reviewed 2026-09-30T03:20:59.686Z sha f485a78 :: needs real behavior proof before merge. :: [P1] Carry exemptions into transcript redaction | [P2] Apply exemptions before the custom source-pattern pass | [P2] Emit redaction notices from an outcome fact | [P2] Use an eligible value in the exemption regression
  • reviewed 2026-10-16T03:02:15.276Z sha 79544b6 :: needs real behavior proof before merge. :: [P1] Finish extracting the redaction notice helper | [P1] Apply exemptions to individual candidates before returning a field | [P1] Carry the selected policy through the actual output owners | [P2] Apply exemptions before the custom source-pattern pass | [P1] Invalidate prepared text when the exemption policy changes | [P2] Emit notifications from a recorded redaction outcome

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime labels Sep 28, 2026
@slzszyt-ux slzszyt-ux changed the title fix(logging): stop masking non-secret environment references fix(logging): preserve non-secret env references and add redaction exemption list Sep 28, 2026
@slzszyt-ux slzszyt-ux changed the title fix(logging): preserve non-secret env references and add redaction exemption list fix(logging): preserve non-secret env references; add exemption list and redaction notification Sep 28, 2026
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Sep 28, 2026
@slzszyt-ux

Copy link
Copy Markdown
Author

Thanks for the thorough review - all findings are addressed in the new revision (head f485a78c).

[P1] reference-prefix bypass - fixed. isNonSecretReferenceValue now requires the entire captured value to be a complete reference: the alternation is $-anchored and is evaluated on the delimiter-stripped capture (splitSecretValueForMask(token).maskable), not on the raw input tail. A capture that merely starts with a reference (e.g. token=process.env.FOO-privateCredential) no longer qualifies and is masked on log and diagnostic sinks. Regression test added (still masks captures that merely start with a reference (credential suffix)), and the sensitive-redaction bitmap path applies the same boundary.

Real behavior proof - added to the PR body. Sink-level trace from the production 2026.9.6 redaction bundle carrying this PR's guard changes, across the real log sink, diagnostic sink, and model-visible sink, with synthetic values only:

  • complete reference: preserved on every sink (token = process.env.GATEWAY_TOKEN;);
  • reference-prefixed credential: masked on log and diagnostic sinks (token=proces…tial - the credential suffix is destroyed);
  • synthetic secret (MY_TOKEN= + 24 chars): still masked on log and diagnostic sinks.

Note on the model-visible sink: it intentionally keeps upstream's narrow assignment policy (assignment-family patterns are excluded from model-visible payloads), so the new exemption does not change what that sink masks - the fix targets the log and diagnostic sinks where the bypass was found.

Input-safety hold - fixed. The credential-shaped literal fixtures are gone from the diff; all fixtures are now assembled programmatically from parts (["ghp_", "a".repeat(20)].join("") style), so no token-shaped string appears in the file.

Line-cap ratchet - partially addressed. The model-visible marker/notice presentation moved into the sibling module src/logging/redact-model-visible.ts. If src/logging/redact.ts still exceeds its baseline with the remaining logic, I'm happy to split the reference exemption and the allow-list feature into separate PRs - guidance welcome.

Maintainer security approval - understood; the session.redaction event payload carries only session scope and a timestamp, and we'll await the approval.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 30, 2026
@slzszyt-ux

Copy link
Copy Markdown
Author

Status update + requests for maintainer attention, since this PR currently needs both a security approval and a ClawSweeper hold release to proceed.

What the latest revision (head f485a78c + auth-header follow-up being pushed now) contains:

  • Complete-value reference exemption for the assignment family and (new) the HTTP auth-header family (AUTHORIZATION_BEARER/BASIC/BOT): a captured value is exempt only if the entire value is an environment/language reference; prefix matches stay masked (addresses the review's reference-prefix bypass, regression-tested).
  • logging.redactAllowPatterns: operator allow-list, wired into the text path, the sensitive-redaction bitmap, structured fields, and the model-visible entry point (redactModelVisibleToolPayloadTextWithConfig) — the entry point where real persisted corruption was reported in this issue.
  • Self-describing model-visible marker + appended notice (replacing ambiguous bare *** on that surface).
  • Model-visible presentation extracted into the sibling module src/logging/redact-model-visible.ts.
  • All fixtures assembled programmatically from parts, so the diff contains no credential-shaped literal (regarding the input-safety hold).

Why this matters (real-world evidence in this issue): two independent reporters confirmed the false-positive class in production — including @Oldrich333's case where masked values were written back into knowledge records and were only recoverable from git history. The operator allow-list is the only non-lossy route for namespace collisions that anchoring cannot decide (e.g. sk as country code vs vendor secret prefix).

Requests:

  1. /allow-security-sensitive-change for the current revision (touches src/logging/redact.ts and packages/acp-core/src/structured-auth-redaction.ts).
  2. Release of the ClawSweeper input-safety hold — the flagged material was a synthetic test fixture, now rebuilt programmatically.
  3. Note on CI: the full matrix was skipped/cancelled across rapid successive pushes to this branch; a fresh run on the current head is triggered with this push.

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 16, 2026
…tructuredAuthParamRanges does not produce ranges for Basic/Bearer credential headers, so the pattern engine (already exempted) is the only path that handles them
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. security-review-required security-sensitive-changed size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant