Skip to content

Fix redaction regex reuse: avoid mutating patterns and keep allowlist working across calls#19

Merged
SynthLuvr merged 3 commits into
mainfrom
2576-fix-whitelist
Feb 23, 2026
Merged

Fix redaction regex reuse: avoid mutating patterns and keep allowlist working across calls#19
SynthLuvr merged 3 commits into
mainfrom
2576-fix-whitelist

Conversation

@SynthLuvr
Copy link
Copy Markdown
Contributor

@SynthLuvr SynthLuvr commented Feb 23, 2026

This PR fixes a subtle statefulness bug in the redactor caused by cloning regexes and forcibly adding the global (g) flag.

What changed

  • Removed cloneRegex, which was creating new RegExp instances with g appended.
  • Updated replaceAllMatchesWithContext and replaceBip39MnemonicMatchesWithContext to use the provided pattern directly in String.prototype.replace.
  • Removed explicit "g" flags from the internal HEX / BASE64 / BASE64URL / BASE58 regexes and adjusted the mnemonic regex from "gi" to "i" to avoid unnecessary global state.

Why

Cloning and forcing g can make matching behavior unexpectedly stateful (via lastIndex) and can also change how callers’ patterns behave. In practice, this could cause allowlist rules to stop matching reliably after repeated invocations, depending on how the regex is reused.

Tests

  • Added a regression test (allows whitelist each time) that calls the redactor repeatedly with a hex allow rule and asserts the allowlist continues to apply on every run.

Impact

  • Redaction behavior is now deterministic across repeated calls.
  • Allowlist rules remain effective even when the redactor is invoked many times in a row.

@SynthLuvr SynthLuvr changed the title 2576 fix whitelist Removed stateful regex Feb 23, 2026
Comment thread src/redact.ts
@SynthLuvr SynthLuvr changed the title Removed stateful regex Fix redaction regex reuse: avoid mutating patterns and keep allowlist working across calls Feb 23, 2026
@SynthLuvr SynthLuvr merged commit f6ff195 into main Feb 23, 2026
3 checks passed
@SynthLuvr SynthLuvr deleted the 2576-fix-whitelist branch February 23, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant