Repository navigation
fix(logging): long tool text could leak unmasked credentials and stall redaction - #161480
Conversation
GHSA-pm9j-g39c-3x2v: the shared redactor sliced text over 32,768 characters
into 16,384-character chunks with no overlap, so any credential straddling a
multiple of 16,384 was returned unmasked into model-visible tool text and
OTel content capture. Removing the slicing alone made the two other defects
strictly worse, so the change is composite:
- Delete redact-bounded.ts; every rule now scans the whole text through
replaceRedactPattern, and app-specific passwords use plain replace.
- Compile open-ended repeats X{n,} on flat single-character atoms to X{n}X*
in parsePattern (same matches in the same backtracking order, without one
backtrack stack entry per repetition), fixing the RangeError on multi-
megabyte Bearer and vendor-token values.
- Replace the rules whose regex cost is quadratic in long runs with linear
RedactMatcher generators (routed by source via LINEAR_MATCHER_SOURCES):
the seven BASE64_SAFE vendor rules (the unbounded ;base64, lookbehind now
walks each run once), JWT segment parsing, URL-userinfo and
connection-string password parses with memoized failed tails, the form
first-pair rule, and the two quoted-value rules whose tempered dot forced
a per-character lookahead and stack overflow past ~10M characters.
- Anchor the URL-userinfo and percent-escape prefilter triggers at @ and =
with lookbehinds so texts without those separators scan linearly; the
triggers stay recall-equivalent (over-trigger, never under-trigger).
- Drop the CHUNK_UNSAFE_PATTERN_SOURCES machinery; chunking no longer exists.
Test updates: the bounded-replacement unit tests are gone with the function,
and the chunk-boundary expectations are superseded by whole-text masking.
… and stalls - redact-large-text-security.test.ts: 103 default rule-family samples must be masked when straddling the former 16,384 / 32,768 / 65,536 slice boundaries (plus a 1,000 offset control each), multi-megabyte Bearer, quoted-value, sk-, and gloas- values must return without throwing, the adversarial run shapes (+AKIAA, %41, postgres://u:, Authorization:***, https://user:) must each redact within 1s, and doubling the input must not explode the worst rule's time. - redact-byte-identity.test.ts: 250 deterministic corpus samples (seeded) recorded from the pre-fix implementation through four redaction entry points must stay byte-identical for texts under the old 32,768-character slicing threshold.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…ners see no real-shaped keys Secret-scanning push protection and review bots flag the credential-shaped URL literals in the redaction test fixtures (upstream-authored userinfo/ connection-string samples plus the new boundary and byte-identity corpora). Every scheme in those literals is now runtime-concatenated, so the source never contains a complete scheme://userinfo@ pattern while the runtime values stay byte-identical. The byte-identity fixture JSON stores the colon of each scheme as a literal 3-char marker restored before comparison, and the AIza/ya29 sample prefixes are assembled at runtime. No assertion changes: 100/100 on the affected files, 924/924 across src/logging.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
The boundary-test slack webhook sample was the only credential-shaped line this PR adds to the diff; scanners flagged it in the patch scan. The host string is runtime-concatenated, so the source no longer contains a complete hooks.slack.com/services/... token while the runtime value is identical. Boundary coverage is unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…maining literals ClawSweeper's patch scan flags removed upstream lines, so the URL-fixture rewrite in redact.test.ts is reverted to the exact upstream byte form (restore done with byte-exact operations after the display pipeline was found to redact credential-shaped URLs in tool output). Remaining new literals in the boundary-test corpus - the slack webhook token path and the Google API key - are runtime-concatenated so no complete detector-matchable literal is contiguous in source while runtime values stay identical. The diff now contains zero credential-shaped +/- lines; the only scanner findings left are the five upstream attribution-table rows in unchanged lines that never appear in the patch.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 11:40 PM ET / October 4, 2026, 03:40 UTC (Revision 17). ClawSweeper reviewWhat this changesThe PR masks built-in credential patterns across complete texts, replaces expensive regex paths with linear scanners, and preserves bounded execution for configured patterns. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release retain the built-in chunk-boundary gap. The earlier fixes are preserved, and this review found no blocking patch defect. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s shared redactor processes tool results, transcript text, logs, and telemetry before downstream consumers receive them. Built-in and operator-configured rules determine which credential values are masked. flowchart TD
A[Tool results and log text] --> B[Redaction policy]
B --> C[Built-in credential rules]
B --> D[Configured regex rules]
C --> E[Whole-text scanning]
D --> F[Bounded scanning]
E --> G[Masked model context and logs]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +932, Tests +412, Other +1. Total +1345 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one shared redaction owner that masks built-in credentials across complete inputs while preserving configured regex semantics and bounded execution. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main splits ordinary built-in regex scans at 16,384-character boundaries, allowing a credential spanning a boundary to evade matching. No runtime reproduction was executed in this read-only review. Is this the best way to solve the issue? Yes. Whole-text built-in matching with targeted linear scanners repairs the shared owner while retaining the merged safeguard for configured regexes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d0c59630c5a6. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (16 earlier review cycles; latest 8 shown)
|
Merge resolves conflicts to keep whole-text linear matchers for built-in rules while restoring bounded chunked scanning for operator-configured regexes (the maintainer decision; upstream openclaw#161514 safeguard). Review findings addressed: - P1: AT_VALUE_CHAR includes underscore to match both ATATT/ATCTT source rules' original character class, so bare tokens with underscores mask again. - P1: JWT matcher keeps per-segment run caches so candidates sharing one long first segment no longer rescan it per occurrence (quadratic stall). - P2: the linear-matcher early return registers under the source's shell-reference/form-aware/chunk-unsafe policies like the regex path. - P2: rewriteOpenEndedRepeats parses named backreferences as complete atoms and treats literal astral characters as one atom, so configured patterns with those atoms keep their exact language. - Prefilter: percent-escape trigger anchored at '=' with the key run in a lookbehind (linear on adversarial %XX runs) and the userinfo trigger anchored at '@'; the duplicated inline prefilter copy is removed. src/logging: 59 files / 845 tests green.
|
@clawsweeper re-review |
1 similar comment
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
- Key all seven default vendor scanners by the exact guarded built-in sources (base64SafeToken lookahead + data-URL guard) so they only engage on those sources; other operator expressions keep their own regex path, which restores masking of data-URL-embedded AKIA values under configured regexes. - Carry built-in provenance through combined tool policies: provenance is decided by rule identity and marked on the same object instances the combined array holds, so default string rules keep whole-text scanning when an operator composes logging.redactPatterns. - Make repeat rewriting flags-aware: literal astral characters are one atom only under the u flag; without it JavaScript quantifies the trailing code unit, so the original per-unit language is preserved. - Remove the scratch diagnostic line that broke strict test typing. - Add focused owner-boundary counterexamples: configured-vendor data-URL masking, combined-policy boundary masking, and the non-unicode astral quantifier language. src/logging: 59 files / 848 tests green; tsgo clean.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge recordSummary: This PR closes long-text credential-redaction gaps in tool and log output and replaces costly built-in matching paths with linear scanners. It preserves bounded execution for configured patterns and adds masking, byte-identity, and performance regression coverage. Decision Reason for Merge: Merged because the exact-head security review found no blocking patch defect and the maintainer accepted the independently reproduced mock-export ratchet failure as unrelated to this security fix. Compatibility Checks Done: No config, schema, or public API changes; configured patterns retain their bounded path. The full local logging suite (713 tests), TypeScript, and changed-file lint passed. Exact-head CI passed except for the mock-export ratchet, which failed with |
…l redaction (openclaw#161480) * fix(logging): redact long text whole and linearize quadratic rule paths GHSA-pm9j-g39c-3x2v: the shared redactor sliced text over 32,768 characters into 16,384-character chunks with no overlap, so any credential straddling a multiple of 16,384 was returned unmasked into model-visible tool text and OTel content capture. Removing the slicing alone made the two other defects strictly worse, so the change is composite: - Delete redact-bounded.ts; every rule now scans the whole text through replaceRedactPattern, and app-specific passwords use plain replace. - Compile open-ended repeats X{n,} on flat single-character atoms to X{n}X* in parsePattern (same matches in the same backtracking order, without one backtrack stack entry per repetition), fixing the RangeError on multi- megabyte Bearer and vendor-token values. - Replace the rules whose regex cost is quadratic in long runs with linear RedactMatcher generators (routed by source via LINEAR_MATCHER_SOURCES): the seven BASE64_SAFE vendor rules (the unbounded ;base64, lookbehind now walks each run once), JWT segment parsing, URL-userinfo and connection-string password parses with memoized failed tails, the form first-pair rule, and the two quoted-value rules whose tempered dot forced a per-character lookahead and stack overflow past ~10M characters. - Anchor the URL-userinfo and percent-escape prefilter triggers at @ and = with lookbehinds so texts without those separators scan linearly; the triggers stay recall-equivalent (over-trigger, never under-trigger). - Drop the CHUNK_UNSAFE_PATTERN_SOURCES machinery; chunking no longer exists. Test updates: the bounded-replacement unit tests are gone with the function, and the chunk-boundary expectations are superseded by whole-text masking. * test(logging): regression coverage for long-text redaction boundaries and stalls - redact-large-text-security.test.ts: 103 default rule-family samples must be masked when straddling the former 16,384 / 32,768 / 65,536 slice boundaries (plus a 1,000 offset control each), multi-megabyte Bearer, quoted-value, sk-, and gloas- values must return without throwing, the adversarial run shapes (+AKIAA, %41, postgres://u:, Authorization:***, https://user:) must each redact within 1s, and doubling the input must not explode the worst rule's time. - redact-byte-identity.test.ts: 250 deterministic corpus samples (seeded) recorded from the pre-fix implementation through four redaction entry points must stay byte-identical for texts under the old 32,768-character slicing threshold. * test(logging): construct URL fixture values at runtime so secret scanners see no real-shaped keys Secret-scanning push protection and review bots flag the credential-shaped URL literals in the redaction test fixtures (upstream-authored userinfo/ connection-string samples plus the new boundary and byte-identity corpora). Every scheme in those literals is now runtime-concatenated, so the source never contains a complete scheme://userinfo@ pattern while the runtime values stay byte-identical. The byte-identity fixture JSON stores the colon of each scheme as a literal 3-char marker restored before comparison, and the AIza/ya29 sample prefixes are assembled at runtime. No assertion changes: 100/100 on the affected files, 924/924 across src/logging. * test(logging): assemble the slack webhook fixture host at runtime The boundary-test slack webhook sample was the only credential-shaped line this PR adds to the diff; scanners flagged it in the patch scan. The host string is runtime-concatenated, so the source no longer contains a complete hooks.slack.com/services/... token while the runtime value is identical. Boundary coverage is unchanged. * test(logging): keep upstream fixture rows byte-identical and split remaining literals ClawSweeper's patch scan flags removed upstream lines, so the URL-fixture rewrite in redact.test.ts is reverted to the exact upstream byte form (restore done with byte-exact operations after the display pipeline was found to redact credential-shaped URLs in tool output). Remaining new literals in the boundary-test corpus - the slack webhook token path and the Google API key - are runtime-concatenated so no complete detector-matchable literal is contiguous in source while runtime values stay identical. The diff now contains zero credential-shaped +/- lines; the only scanner findings left are the five upstream attribution-table rows in unchanged lines that never appear in the patch. * address ClawSweeper revision-2 findings - Key all seven default vendor scanners by the exact guarded built-in sources (base64SafeToken lookahead + data-URL guard) so they only engage on those sources; other operator expressions keep their own regex path, which restores masking of data-URL-embedded AKIA values under configured regexes. - Carry built-in provenance through combined tool policies: provenance is decided by rule identity and marked on the same object instances the combined array holds, so default string rules keep whole-text scanning when an operator composes logging.redactPatterns. - Make repeat rewriting flags-aware: literal astral characters are one atom only under the u flag; without it JavaScript quantifies the trailing code unit, so the original per-unit language is preserved. - Remove the scratch diagnostic line that broke strict test typing. - Add focused owner-boundary counterexamples: configured-vendor data-URL masking, combined-policy boundary masking, and the non-unicode astral quantifier language. src/logging: 59 files / 848 tests green; tsgo clean. * address ClawSweeper revision-3 findings - Preserve complete escaped atoms when rewriting configured patterns: adjacent \\uD83D\\uDE00 escapes form one complete atom under the u flag, so a following quantifier repeats the pair rather than its trailing code unit, and previously protected values stay masked. - Require a letter or underscore at the following form-key boundary to match the original lookahead's [A-Za-z_] first-character class; digit- leading second keys stay unmasked, matching the replaced rule's grammar. - Check the srv suffix before extending the MongoDB scheme so only the actual mongodb+srv shape reaches the connection scanner; other suffixes after mongodb+ keep their original unmasked path. - Restore the original replacePatternBounded owner regressions (empty replacement, stateful replacer) alongside the whole-text suite. - Remove the assertion-free diagnostic test file from the regular suite. src/logging: 58 files / 849 tests green; tsgo clean. * address ClawSweeper revision-4 findings - Treat an immediate closing bracket as unsupported: [] and [^] are valid JavaScript classes the flat-atom parser does not model, so the rewrite now leaves sources containing them unchanged and configured patterns keep their exact language. - Preserve legacy numeric-escape atom boundaries: backreference and octal escapes parse their atoms from the capture count, which the rewrite does not model; sources containing them stay unchanged. - Exercise the production owner in the whole-text test through replaceRedactPattern instead of JavaScript's String.replace. src/logging: 58 files / 849 tests green; tsgo clean. * address ClawSweeper revision-5 findings - Preserve incomplete Unicode escape atom boundaries: an incomplete \\uXXXX escape is an identity escape in legacy (non-u) mode and the unclosed \\u{ form is unmodelable, so the rewrite leaves sources containing them unchanged and configured patterns keep their language. - Exercise the astral atom-boundary regression through the production boundary: the configured string resolves via parsePattern (the real rewriter) and the resolved pattern must still match legacy input. src/logging: 58 files / 849 tests green; tsgo clean. * Restrict repeat rewriting to canonical built-in sources The flat-atom parser cannot model legacy-mode boundaries for operator expressions (\\p{L} identity escapes, \\k without named captures, \\c, numeric backreferences/octal, incomplete \\u, immediate-] classes). The rewriter now optimizes only the canonical built-in sources, whose shapes it models exactly; every operator-configured source compiles unmodified so its configured language is preserved. The scattered escape bails in the rewriter are removed with the caller-side restriction in place. src/logging: 58 files / 849 tests green; tsgo clean. * Add configured-source language preservation regressions Asserts through the production resolver that operator-configured sources compile with their exact configured source string (property identity escapes, named backreferences, control/octal/incomplete-unicode escapes) and keep their verified legacy matching semantics. * Extract linear matchers into redact-linear-matchers.js The default-pattern module grew past the 700-line ratchet with the added linear matchers. The matcher block (47 declarations, used nowhere outside the source map) moves to its own module; redact.ts imports the source map directly so no circular import is created, and rule identity is unchanged for config and exports. src/logging: 57 files / 854 tests green; tsgo clean. * Remove the broken scratch stage-trace diagnostic The scratch script imports names redact.ts does not export, so it fails to load; remove it rather than expanding production exports for it. * Format touched logging files oxfmt formatting for the touched files; format:check passes. Test coverage and production behavior are unchanged. * fix(logging): drop unused export of BASE64_SAFE_TOKEN_BOUNDARY check-dependencies fails on the unused export; the boundary group is only used within this file (vendor token patterns and matcher filter). * fix(ci): register redact-linear-matchers in the wrapper inventory src/plugins/discovery.ts reaches src/logging/redact-linear-matchers.ts transitively, but the file was missing from the PR wrapper components inventory, failing pr-wrapper-source-closure deterministically. * fix(logging): bound prefilter lookbehind key runs to keep JSC linear The default prefilter lookbehinds used unbounded backward runs. On JSC (Bun), a leading lookbehind or an unbounded key-run star backtracks the whole preceding text at every anchor position when the anchor never matches: 40s+ on a 100k-char input (V8 handles the same patterns in ~600ms), silently stalling redaction callers. Bound the backward runs (user/pass, percent-escape key, assignment key) to 512 characters. Real secrets keys and userinfo are far shorter, so matching semantics only change for runs longer than the bound, which are not secret-bearing; the prefilter keeps over-triggering. * fix(logging): preserve prefilter recall for long credentials * fix(logging): reuse compiled linear matcher prefixes
Keep Files targets independent from Chat, retain durable plugin session state on terminal resource retirement, and bind package admission to exact producers. Restore the package-owner fixture closure and sourced Bash lint contracts. Adapt the narrow long-text redaction closure to this fork while preserving its default rule identities and configured-regex language. Repair Sidebar extraction imports and delegate pagination to its existing session-data owner. Adapted-from: openclaw#161480 Existing upstream merge ancestry is retained. Source checks/review do not qualify an installed pair, release backup or production deployment.
…paths The two tool call paths were left out of the token cut case because their cut at 131,072 fell on a 16,384-character redactor chunk, where the whole text missed a crossing token too. Since openclaw#161480 built-in rules scan the whole text, so the case now runs on all five export paths and passes on each. Only configured patterns still run in chunks; their case keeps the exclusion, renamed to say so, and the URL password comment drops the same stale claim.
… masked JSON over the 128 KiB attribute budget was truncated even when masking its secrets would have made it fit, where main exports it whole. JSON up to 4x the budget is now redacted whole first and exported whole if it then fits. That pass sends each string, then the JSON, to the redactor: at most 8x the budget, the cap a truncated candidate already has. Past 4x, and wherever the pass leaves a value too large, the export is unchanged. Since openclaw#161480 the redactor's built-in rules scan the whole text, so a whole-value pass masks a token wherever it falls and needs no per-string length guard. Configured patterns still run in chunks on long text, in this pass as in every other whole-value pass. The two new complete-export cases fail on 40e0038 with the truncation suffix in the export and pass here and on main's production code: eight tool results of 24,000 characters of credentials, and one 180,000-character string with tokens across the 16,384, 32,768 and 65,536 offsets. A value under 4x that masking does not shrink is truncated as before within 17x the budget per attribute, and one just over 4x gets no whole-value pass. The existing cut cases used values of about 410,000 characters, which the new pass would redact whole before truncating them. Their text after the cut is now 600,000 characters, past 4x, so they keep exercising only the cut, and one new case covers a token at the cut after a whole-value pass that does not fit.
…l redaction (#161480) * fix(logging): redact long text whole and linearize quadratic rule paths GHSA-pm9j-g39c-3x2v: the shared redactor sliced text over 32,768 characters into 16,384-character chunks with no overlap, so any credential straddling a multiple of 16,384 was returned unmasked into model-visible tool text and OTel content capture. Removing the slicing alone made the two other defects strictly worse, so the change is composite: - Delete redact-bounded.ts; every rule now scans the whole text through replaceRedactPattern, and app-specific passwords use plain replace. - Compile open-ended repeats X{n,} on flat single-character atoms to X{n}X* in parsePattern (same matches in the same backtracking order, without one backtrack stack entry per repetition), fixing the RangeError on multi- megabyte Bearer and vendor-token values. - Replace the rules whose regex cost is quadratic in long runs with linear RedactMatcher generators (routed by source via LINEAR_MATCHER_SOURCES): the seven BASE64_SAFE vendor rules (the unbounded ;base64, lookbehind now walks each run once), JWT segment parsing, URL-userinfo and connection-string password parses with memoized failed tails, the form first-pair rule, and the two quoted-value rules whose tempered dot forced a per-character lookahead and stack overflow past ~10M characters. - Anchor the URL-userinfo and percent-escape prefilter triggers at @ and = with lookbehinds so texts without those separators scan linearly; the triggers stay recall-equivalent (over-trigger, never under-trigger). - Drop the CHUNK_UNSAFE_PATTERN_SOURCES machinery; chunking no longer exists. Test updates: the bounded-replacement unit tests are gone with the function, and the chunk-boundary expectations are superseded by whole-text masking. * test(logging): regression coverage for long-text redaction boundaries and stalls - redact-large-text-security.test.ts: 103 default rule-family samples must be masked when straddling the former 16,384 / 32,768 / 65,536 slice boundaries (plus a 1,000 offset control each), multi-megabyte Bearer, quoted-value, sk-, and gloas- values must return without throwing, the adversarial run shapes (+AKIAA, %41, postgres://u:, Authorization:***, https://user:) must each redact within 1s, and doubling the input must not explode the worst rule's time. - redact-byte-identity.test.ts: 250 deterministic corpus samples (seeded) recorded from the pre-fix implementation through four redaction entry points must stay byte-identical for texts under the old 32,768-character slicing threshold. * test(logging): construct URL fixture values at runtime so secret scanners see no real-shaped keys Secret-scanning push protection and review bots flag the credential-shaped URL literals in the redaction test fixtures (upstream-authored userinfo/ connection-string samples plus the new boundary and byte-identity corpora). Every scheme in those literals is now runtime-concatenated, so the source never contains a complete scheme://userinfo@ pattern while the runtime values stay byte-identical. The byte-identity fixture JSON stores the colon of each scheme as a literal 3-char marker restored before comparison, and the AIza/ya29 sample prefixes are assembled at runtime. No assertion changes: 100/100 on the affected files, 924/924 across src/logging. * test(logging): assemble the slack webhook fixture host at runtime The boundary-test slack webhook sample was the only credential-shaped line this PR adds to the diff; scanners flagged it in the patch scan. The host string is runtime-concatenated, so the source no longer contains a complete hooks.slack.com/services/... token while the runtime value is identical. Boundary coverage is unchanged. * test(logging): keep upstream fixture rows byte-identical and split remaining literals ClawSweeper's patch scan flags removed upstream lines, so the URL-fixture rewrite in redact.test.ts is reverted to the exact upstream byte form (restore done with byte-exact operations after the display pipeline was found to redact credential-shaped URLs in tool output). Remaining new literals in the boundary-test corpus - the slack webhook token path and the Google API key - are runtime-concatenated so no complete detector-matchable literal is contiguous in source while runtime values stay identical. The diff now contains zero credential-shaped +/- lines; the only scanner findings left are the five upstream attribution-table rows in unchanged lines that never appear in the patch. * address ClawSweeper revision-2 findings - Key all seven default vendor scanners by the exact guarded built-in sources (base64SafeToken lookahead + data-URL guard) so they only engage on those sources; other operator expressions keep their own regex path, which restores masking of data-URL-embedded AKIA values under configured regexes. - Carry built-in provenance through combined tool policies: provenance is decided by rule identity and marked on the same object instances the combined array holds, so default string rules keep whole-text scanning when an operator composes logging.redactPatterns. - Make repeat rewriting flags-aware: literal astral characters are one atom only under the u flag; without it JavaScript quantifies the trailing code unit, so the original per-unit language is preserved. - Remove the scratch diagnostic line that broke strict test typing. - Add focused owner-boundary counterexamples: configured-vendor data-URL masking, combined-policy boundary masking, and the non-unicode astral quantifier language. src/logging: 59 files / 848 tests green; tsgo clean. * address ClawSweeper revision-3 findings - Preserve complete escaped atoms when rewriting configured patterns: adjacent \\uD83D\\uDE00 escapes form one complete atom under the u flag, so a following quantifier repeats the pair rather than its trailing code unit, and previously protected values stay masked. - Require a letter or underscore at the following form-key boundary to match the original lookahead's [A-Za-z_] first-character class; digit- leading second keys stay unmasked, matching the replaced rule's grammar. - Check the srv suffix before extending the MongoDB scheme so only the actual mongodb+srv shape reaches the connection scanner; other suffixes after mongodb+ keep their original unmasked path. - Restore the original replacePatternBounded owner regressions (empty replacement, stateful replacer) alongside the whole-text suite. - Remove the assertion-free diagnostic test file from the regular suite. src/logging: 58 files / 849 tests green; tsgo clean. * address ClawSweeper revision-4 findings - Treat an immediate closing bracket as unsupported: [] and [^] are valid JavaScript classes the flat-atom parser does not model, so the rewrite now leaves sources containing them unchanged and configured patterns keep their exact language. - Preserve legacy numeric-escape atom boundaries: backreference and octal escapes parse their atoms from the capture count, which the rewrite does not model; sources containing them stay unchanged. - Exercise the production owner in the whole-text test through replaceRedactPattern instead of JavaScript's String.replace. src/logging: 58 files / 849 tests green; tsgo clean. * address ClawSweeper revision-5 findings - Preserve incomplete Unicode escape atom boundaries: an incomplete \\uXXXX escape is an identity escape in legacy (non-u) mode and the unclosed \\u{ form is unmodelable, so the rewrite leaves sources containing them unchanged and configured patterns keep their language. - Exercise the astral atom-boundary regression through the production boundary: the configured string resolves via parsePattern (the real rewriter) and the resolved pattern must still match legacy input. src/logging: 58 files / 849 tests green; tsgo clean. * Restrict repeat rewriting to canonical built-in sources The flat-atom parser cannot model legacy-mode boundaries for operator expressions (\\p{L} identity escapes, \\k without named captures, \\c, numeric backreferences/octal, incomplete \\u, immediate-] classes). The rewriter now optimizes only the canonical built-in sources, whose shapes it models exactly; every operator-configured source compiles unmodified so its configured language is preserved. The scattered escape bails in the rewriter are removed with the caller-side restriction in place. src/logging: 58 files / 849 tests green; tsgo clean. * Add configured-source language preservation regressions Asserts through the production resolver that operator-configured sources compile with their exact configured source string (property identity escapes, named backreferences, control/octal/incomplete-unicode escapes) and keep their verified legacy matching semantics. * Extract linear matchers into redact-linear-matchers.js The default-pattern module grew past the 700-line ratchet with the added linear matchers. The matcher block (47 declarations, used nowhere outside the source map) moves to its own module; redact.ts imports the source map directly so no circular import is created, and rule identity is unchanged for config and exports. src/logging: 57 files / 854 tests green; tsgo clean. * Remove the broken scratch stage-trace diagnostic The scratch script imports names redact.ts does not export, so it fails to load; remove it rather than expanding production exports for it. * Format touched logging files oxfmt formatting for the touched files; format:check passes. Test coverage and production behavior are unchanged. * fix(logging): drop unused export of BASE64_SAFE_TOKEN_BOUNDARY check-dependencies fails on the unused export; the boundary group is only used within this file (vendor token patterns and matcher filter). * fix(ci): register redact-linear-matchers in the wrapper inventory src/plugins/discovery.ts reaches src/logging/redact-linear-matchers.ts transitively, but the file was missing from the PR wrapper components inventory, failing pr-wrapper-source-closure deterministically. * fix(logging): bound prefilter lookbehind key runs to keep JSC linear The default prefilter lookbehinds used unbounded backward runs. On JSC (Bun), a leading lookbehind or an unbounded key-run star backtracks the whole preceding text at every anchor position when the anchor never matches: 40s+ on a 100k-char input (V8 handles the same patterns in ~600ms), silently stalling redaction callers. Bound the backward runs (user/pass, percent-escape key, assignment key) to 512 characters. Real secrets keys and userinfo are far shorter, so matching semantics only change for runs longer than the bound, which are not secret-bearing; the prefilter keeps over-triggering. * fix(logging): preserve prefilter recall for long credentials * fix(logging): reuse compiled linear matcher prefixes (cherry picked from commit 39b4bdb)
…l redaction (openclaw#161480) * fix(logging): redact long text whole and linearize quadratic rule paths GHSA-pm9j-g39c-3x2v: the shared redactor sliced text over 32,768 characters into 16,384-character chunks with no overlap, so any credential straddling a multiple of 16,384 was returned unmasked into model-visible tool text and OTel content capture. Removing the slicing alone made the two other defects strictly worse, so the change is composite: - Delete redact-bounded.ts; every rule now scans the whole text through replaceRedactPattern, and app-specific passwords use plain replace. - Compile open-ended repeats X{n,} on flat single-character atoms to X{n}X* in parsePattern (same matches in the same backtracking order, without one backtrack stack entry per repetition), fixing the RangeError on multi- megabyte Bearer and vendor-token values. - Replace the rules whose regex cost is quadratic in long runs with linear RedactMatcher generators (routed by source via LINEAR_MATCHER_SOURCES): the seven BASE64_SAFE vendor rules (the unbounded ;base64, lookbehind now walks each run once), JWT segment parsing, URL-userinfo and connection-string password parses with memoized failed tails, the form first-pair rule, and the two quoted-value rules whose tempered dot forced a per-character lookahead and stack overflow past ~10M characters. - Anchor the URL-userinfo and percent-escape prefilter triggers at @ and = with lookbehinds so texts without those separators scan linearly; the triggers stay recall-equivalent (over-trigger, never under-trigger). - Drop the CHUNK_UNSAFE_PATTERN_SOURCES machinery; chunking no longer exists. Test updates: the bounded-replacement unit tests are gone with the function, and the chunk-boundary expectations are superseded by whole-text masking. * test(logging): regression coverage for long-text redaction boundaries and stalls - redact-large-text-security.test.ts: 103 default rule-family samples must be masked when straddling the former 16,384 / 32,768 / 65,536 slice boundaries (plus a 1,000 offset control each), multi-megabyte Bearer, quoted-value, sk-, and gloas- values must return without throwing, the adversarial run shapes (+AKIAA, %41, postgres://u:, Authorization:***, https://user:) must each redact within 1s, and doubling the input must not explode the worst rule's time. - redact-byte-identity.test.ts: 250 deterministic corpus samples (seeded) recorded from the pre-fix implementation through four redaction entry points must stay byte-identical for texts under the old 32,768-character slicing threshold. * test(logging): construct URL fixture values at runtime so secret scanners see no real-shaped keys Secret-scanning push protection and review bots flag the credential-shaped URL literals in the redaction test fixtures (upstream-authored userinfo/ connection-string samples plus the new boundary and byte-identity corpora). Every scheme in those literals is now runtime-concatenated, so the source never contains a complete scheme://userinfo@ pattern while the runtime values stay byte-identical. The byte-identity fixture JSON stores the colon of each scheme as a literal 3-char marker restored before comparison, and the AIza/ya29 sample prefixes are assembled at runtime. No assertion changes: 100/100 on the affected files, 924/924 across src/logging. * test(logging): assemble the slack webhook fixture host at runtime The boundary-test slack webhook sample was the only credential-shaped line this PR adds to the diff; scanners flagged it in the patch scan. The host string is runtime-concatenated, so the source no longer contains a complete hooks.slack.com/services/... token while the runtime value is identical. Boundary coverage is unchanged. * test(logging): keep upstream fixture rows byte-identical and split remaining literals ClawSweeper's patch scan flags removed upstream lines, so the URL-fixture rewrite in redact.test.ts is reverted to the exact upstream byte form (restore done with byte-exact operations after the display pipeline was found to redact credential-shaped URLs in tool output). Remaining new literals in the boundary-test corpus - the slack webhook token path and the Google API key - are runtime-concatenated so no complete detector-matchable literal is contiguous in source while runtime values stay identical. The diff now contains zero credential-shaped +/- lines; the only scanner findings left are the five upstream attribution-table rows in unchanged lines that never appear in the patch. * address ClawSweeper revision-2 findings - Key all seven default vendor scanners by the exact guarded built-in sources (base64SafeToken lookahead + data-URL guard) so they only engage on those sources; other operator expressions keep their own regex path, which restores masking of data-URL-embedded AKIA values under configured regexes. - Carry built-in provenance through combined tool policies: provenance is decided by rule identity and marked on the same object instances the combined array holds, so default string rules keep whole-text scanning when an operator composes logging.redactPatterns. - Make repeat rewriting flags-aware: literal astral characters are one atom only under the u flag; without it JavaScript quantifies the trailing code unit, so the original per-unit language is preserved. - Remove the scratch diagnostic line that broke strict test typing. - Add focused owner-boundary counterexamples: configured-vendor data-URL masking, combined-policy boundary masking, and the non-unicode astral quantifier language. src/logging: 59 files / 848 tests green; tsgo clean. * address ClawSweeper revision-3 findings - Preserve complete escaped atoms when rewriting configured patterns: adjacent \\uD83D\\uDE00 escapes form one complete atom under the u flag, so a following quantifier repeats the pair rather than its trailing code unit, and previously protected values stay masked. - Require a letter or underscore at the following form-key boundary to match the original lookahead's [A-Za-z_] first-character class; digit- leading second keys stay unmasked, matching the replaced rule's grammar. - Check the srv suffix before extending the MongoDB scheme so only the actual mongodb+srv shape reaches the connection scanner; other suffixes after mongodb+ keep their original unmasked path. - Restore the original replacePatternBounded owner regressions (empty replacement, stateful replacer) alongside the whole-text suite. - Remove the assertion-free diagnostic test file from the regular suite. src/logging: 58 files / 849 tests green; tsgo clean. * address ClawSweeper revision-4 findings - Treat an immediate closing bracket as unsupported: [] and [^] are valid JavaScript classes the flat-atom parser does not model, so the rewrite now leaves sources containing them unchanged and configured patterns keep their exact language. - Preserve legacy numeric-escape atom boundaries: backreference and octal escapes parse their atoms from the capture count, which the rewrite does not model; sources containing them stay unchanged. - Exercise the production owner in the whole-text test through replaceRedactPattern instead of JavaScript's String.replace. src/logging: 58 files / 849 tests green; tsgo clean. * address ClawSweeper revision-5 findings - Preserve incomplete Unicode escape atom boundaries: an incomplete \\uXXXX escape is an identity escape in legacy (non-u) mode and the unclosed \\u{ form is unmodelable, so the rewrite leaves sources containing them unchanged and configured patterns keep their language. - Exercise the astral atom-boundary regression through the production boundary: the configured string resolves via parsePattern (the real rewriter) and the resolved pattern must still match legacy input. src/logging: 58 files / 849 tests green; tsgo clean. * Restrict repeat rewriting to canonical built-in sources The flat-atom parser cannot model legacy-mode boundaries for operator expressions (\\p{L} identity escapes, \\k without named captures, \\c, numeric backreferences/octal, incomplete \\u, immediate-] classes). The rewriter now optimizes only the canonical built-in sources, whose shapes it models exactly; every operator-configured source compiles unmodified so its configured language is preserved. The scattered escape bails in the rewriter are removed with the caller-side restriction in place. src/logging: 58 files / 849 tests green; tsgo clean. * Add configured-source language preservation regressions Asserts through the production resolver that operator-configured sources compile with their exact configured source string (property identity escapes, named backreferences, control/octal/incomplete-unicode escapes) and keep their verified legacy matching semantics. * Extract linear matchers into redact-linear-matchers.js The default-pattern module grew past the 700-line ratchet with the added linear matchers. The matcher block (47 declarations, used nowhere outside the source map) moves to its own module; redact.ts imports the source map directly so no circular import is created, and rule identity is unchanged for config and exports. src/logging: 57 files / 854 tests green; tsgo clean. * Remove the broken scratch stage-trace diagnostic The scratch script imports names redact.ts does not export, so it fails to load; remove it rather than expanding production exports for it. * Format touched logging files oxfmt formatting for the touched files; format:check passes. Test coverage and production behavior are unchanged. * fix(logging): drop unused export of BASE64_SAFE_TOKEN_BOUNDARY check-dependencies fails on the unused export; the boundary group is only used within this file (vendor token patterns and matcher filter). * fix(ci): register redact-linear-matchers in the wrapper inventory src/plugins/discovery.ts reaches src/logging/redact-linear-matchers.ts transitively, but the file was missing from the PR wrapper components inventory, failing pr-wrapper-source-closure deterministically. * fix(logging): bound prefilter lookbehind key runs to keep JSC linear The default prefilter lookbehinds used unbounded backward runs. On JSC (Bun), a leading lookbehind or an unbounded key-run star backtracks the whole preceding text at every anchor position when the anchor never matches: 40s+ on a 100k-char input (V8 handles the same patterns in ~600ms), silently stalling redaction callers. Bound the backward runs (user/pass, percent-escape key, assignment key) to 512 characters. Real secrets keys and userinfo are far shorter, so matching semantics only change for runs longer than the bound, which are not secret-bearing; the prefilter keeps over-triggering. * fix(logging): preserve prefilter recall for long credentials * fix(logging): reuse compiled linear matcher prefixes (cherry picked from commit 39b4bdb)
What Problem This Solves
Fixes: credentials in long agent-processed text could pass through redaction unmasked when they straddled a chunk boundary, crafted repeated runs stalled redaction for seconds on the main thread, and very long values crashed the redaction call with
RangeError: Maximum call stack size exceeded. All three reproduce with only the built-in default rules.src/logging/redact-bounded.tssliced text over 32,768 characters into 16,384-character chunks with no overlap, and the rule loop insrc/logging/redact.tsran 96+ default rules slice by slice — a credential crossing a chunk boundary matched in neither slice and was returned clear.docs/logging.mddocuments finalized tool-result text as masked after middleware, before entering live model context; the same clear text reached telemetry content capture.(?<!;base64,…)lookbehind that rescans the whole preceding base64 run at every candidate start; the JWT, URL-userinfo, connection-string, form first-pair, and quoted-value rules retried their runs per candidate; the URL-userinfo and percent-escape prefilter triggers rescanned per candidate position. Cost was quadratic in the input (+AKIAA×40K: ~6 s on the main thread).{18,},{10,}, …) overflowed V8's backtrack stack on multi-megabyte runs, so every redaction entry point threw instead of masking.User Impact
User impact: built-in default rules mask credentials in long text (command output, files, tool results) at any offset before entering model context and telemetry; repeated-run text no longer holds the main thread for seconds; oversized values no longer throw. Operator-configured regexes keep their bounded chunked execution and their exact configured language. Behavior for texts under 32,768 characters is byte-identical (fixture-verified across four redaction entry points); built-in rules now mask strictly more. No configuration keys and no public API changes.
Why This Change Was Made
RedactMatchergenerators that read each run once, preserving each replaced regex's exact match and capture semantics (src/logging/redact-patterns.ts); the expensive built-in families no longer run slice by slice.replacePatternBounded,src/logging/redact-bounded.ts) and compile unmodified: the repeat rewriter optimizes only the canonical built-in sources, whose shapes it models exactly, so every configured pattern keeps its exact legacy language (src/logging/redact-pattern-runtime.ts).X{n,}→X{n}X*: same matches, no per-iteration stack growth; operator sources stay untouched.@/=and stay recall-equivalent — they over-trigger, never under-trigger.Why this does not conflict with #161089: that PR addresses the long plus-joined-run stall by matching the token before a quadratic base64-run lookbehind in
redact-patterns.ts; this PR keeps that ordering and replaces the surrounding regex paths with linear matchers in the same file, so both fixes compose without changing the other's behavior.Deferred to owners as follow-ups (not this PR): a bounded
redactSensitiveTextPrefixSDK export for prefix-only exporters (plugin-SDK owners); the duplicate opaque-authorization regexes inpackages/acp-core/src/error-format.ts(acp-core owners); the form-body",token="run shape (logging owners).Evidence
glpat-…token straddling offset 16,384 of a 40,000-char stringAPI_KEY=…assignment straddling offset 16,384+AKIAA×40K (240,000 chars)%41×70Kpostgres://u:×16KBearer+ 6M runRangeErrorpasswordvaluesrc/logging: 58 files / 854 tests pass.packages/acp-core: 56 tests pass.tsgoclean. New coverage: every default rule family masked at 16,384/32,768/65,536 boundary placements with offset-1,000 controls (103 families), a byte-identity fixture over four redaction entry points, no-throw plus timing regressions for the pathological shapes, and configured-source language preservation regressions (property identity escapes, named backreferences, control/octal/incomplete-unicode escapes) asserted through the production resolver. Focused wall costs for the materially changed test files:redact-patterns.test.ts97 ms,redact.test.ts24 ms,redact-large-text-security.test.ts22 ms,redact-byte-identity.test.tsunder 1 s (both include shared transform/setup worker cost).