Skip to content

fix(logging): long tool text could leak unmasked credentials and stall redaction - #161480

Merged
eleqtrizit merged 21 commits into
openclaw:mainfrom
eleqtrizit:1085
Oct 4, 2026
Merged

eleqtrizit merged 21 commits into
openclaw:mainfrom
eleqtrizit:1085

Conversation

@eleqtrizit

@eleqtrizit eleqtrizit commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

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.

  1. src/logging/redact-bounded.ts sliced text over 32,768 characters into 16,384-character chunks with no overlap, and the rule loop in src/logging/redact.ts ran 96+ default rules slice by slice — a credential crossing a chunk boundary matched in neither slice and was returned clear. docs/logging.md documents finalized tool-result text as masked after middleware, before entering live model context; the same clear text reached telemetry content capture.
  2. The seven base64-boundary vendor rules carried an unbounded (?<!;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).
  3. Open-ended repeats ({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

  • The built-in default rules now scan complete texts through linear RedactMatcher generators 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.
  • Operator-configured regexes retain the recently restored bounded chunked execution (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).
  • Open-ended repeats on canonical built-in flat atoms compile X{n,} → X{n}X*: same matches, no per-iteration stack growth; operator sources stay untouched.
  • The URL-userinfo and percent-escape prefilter triggers anchor at @/= 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 redactSensitiveTextPrefix SDK export for prefix-only exporters (plugin-SDK owners); the duplicate opaque-authorization regexes in packages/acp-core/src/error-format.ts (acp-core owners); the form-body ",token=" run shape (logging owners).

Evidence

Input Before After
glpat-… token straddling offset 16,384 of a 40,000-char string returned clear masked
API_KEY=… assignment straddling offset 16,384 returned clear masked
+AKIAA ×40K (240,000 chars) 6,105 ms 60 ms
%41 ×70K 10,331 ms 3 ms
postgres://u: ×16K 2,035 ms 4 ms
Bearer + 6M run RangeError no throw
quoted 10.5M password value clear past 16,384 / throws masked, no throw

src/logging: 58 files / 854 tests pass. packages/acp-core: 56 tests pass. tsgo clean. 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.ts 97 ms, redact.test.ts 24 ms, redact-large-text-security.test.ts 22 ms, redact-byte-identity.test.ts under 1 s (both include shared transform/setup worker cost).

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.
@clawsweeper

clawsweeper Bot commented Sep 30, 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.

…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.
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

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.
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

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.
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 11:40 PM ET / October 4, 2026, 03:40 UTC (Revision 17).

ClawSweeper review

What this changes

The 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
Reviewed head: 1eba3739576e081cb86463d81ef483559b2c17ae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused security repair with substantial regression coverage and no blocking defect found in the inspected patch.
Proof confidence 🌊 off-meta tidepool Not applicable: The security guard verifies maintainer permission, so ordinary contributor proof is exempt. The body reports shared-redactor boundary masking, reduced pathological-run timings, and oversized-value recovery; those results were not independently rerun. No stored-data model changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The security guard verifies maintainer permission, so ordinary contributor proof is exempt. The body reports shared-redactor boundary masking, reduced pathological-run timings, and oversized-value recovery; those results were not independently rerun. No stored-data model changes.
Evidence reviewed 9 items Pinned introduction: Reviewed the merge-base-to-head production and test changes at the supplied identities; the checkout remained clean.
Current main still needs the repair: Current main sends ordinary built-in regexes through replacePatternBounded and has no linear-matcher module. Its existing safeguards therefore do not solve the full boundary-leak and repeated-run problem.
Latest-release check: The v2026.9.8 source likewise uses bounded replacement for ordinary built-in regexes; this PR’s central repair is not present in that release.
Findings None None.
Security None None.

How this fits together

OpenClaw’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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +932, Tests +412, Other +1. Total +1345 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 965 33 +932
Tests 4 418 6 +412
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 11 1384 39 +1345

Review metrics

Metric Value Why it matters
Production growth and regression coverage production +931 LOC; tests +412 LOC; fixture +1 line The substantial production growth has a stated purpose: replacing stack-sensitive and quadratic regex paths while preserving their matching contracts.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The repair addresses credential exposure and prolonged redaction stalls in shared tool-result, logging, and telemetry workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The security guard verifies maintainer permission, so ordinary contributor proof is exempt. The body reports shared-redactor boundary masking, reduced pathological-run timings, and oversized-value recovery; those results were not independently rerun. No stored-data model changes.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head production and test changes at the supplied identities; the checkout remained clean. (src/logging/redact.ts:752, 1eba3739576e)
  • Current main still needs the repair: Current main sends ordinary built-in regexes through replacePatternBounded and has no linear-matcher module. Its existing safeguards therefore do not solve the full boundary-leak and repeated-run problem. (src/logging/redact.ts:680, d0c59630c5a6)
  • Latest-release check: The v2026.9.8 source likewise uses bounded replacement for ordinary built-in regexes; this PR’s central repair is not present in that release. (src/logging/redact.ts:684, fc23bc864e45)
  • Configured-pattern compatibility: Repeat rewriting is restricted to canonical built-in sources, and only built-in resolved patterns gain whole-text scanning. Configured-source language and bounded execution have focused regression coverage. (src/logging/redact.ts:217, 1eba3739576e)
  • Re-review and latest change: The prior long-URL and padded-key findings are addressed by uncapped presence probes and corresponding regression cases. The latest commit pools compiled prefixes with exclusive checkout and finally-based reset, preserving nested scanning. The full earlier-revision comparison could not complete because a local Git object was unavailable and the comparison API route was blocked; the latest commit patch was inspected through GitHub. (src/logging/redact-linear-matchers.ts:77, 1eba3739576e)
  • Documented production boundary: Logging documentation defines masking before persistence and before finalized tool results enter model context. Session tool-result preparation and telemetry normalization consume this shared owner; no Codex dependency signal was found. Public docs: docs/logging.md. (docs/logging.md:985, 1eba3739576e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (16 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-01T22:23:24.625Z sha 91961cf :: needs changes before merge. :: [P3] Remove the diagnostic that imports private redaction helpers
  • reviewed 2026-10-01T22:31:42.121Z sha 6705127 :: needs changes before merge. :: none
  • reviewed 2026-10-01T22:42:25.422Z sha a39ac45 :: needs changes before merge. :: none
  • reviewed 2026-10-01T22:48:21.820Z sha a39ac45 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T03:27:26.979Z sha f8d6861 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T04:16:53.113Z sha 558880c :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T23:27:12.895Z sha 1f9c757 :: blocked before merge. :: [P1] [P1] Preserve URL credential detection beyond 512 characters | [P1] [P1] Keep padded sensitive keys reachable through the prefilter
  • reviewed 2026-10-03T03:04:01.104Z sha d84f44a :: needs maintainer review before merge. :: none

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.
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

1 similar comment
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Oct 1, 2026
- 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.
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 2, 2026
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 3, 2026
@eleqtrizit

Copy link
Copy Markdown
Contributor Author

Merge record

Summary: 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 spawnSync git ENOBUFS while reading a baseline larger than Node’s default child-process buffer.

@eleqtrizit
eleqtrizit merged commit 39b4bdb into openclaw:main Oct 4, 2026
134 of 137 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…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
@eleqtrizit
eleqtrizit deleted the 1085 branch October 4, 2026 06:22
AshleyHollis pushed a commit to AshleyHollis/openclaw that referenced this pull request Oct 5, 2026
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.
amittell added a commit to amittell/openclaw that referenced this pull request Oct 9, 2026
…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.
amittell added a commit to amittell/openclaw that referenced this pull request Oct 9, 2026
… 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.
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
…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)
amittell pushed a commit to amittell/openclaw that referenced this pull request Oct 11, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant