Skip to content

fix(security): add upper bound to base64 scrub regex to prevent ReDoS#3251

Merged
louisgv merged 2 commits into
mainfrom
fix/issue-3250
Apr 10, 2026
Merged

fix(security): add upper bound to base64 scrub regex to prevent ReDoS#3251
louisgv merged 2 commits into
mainfrom
fix/issue-3250

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Apr 10, 2026

Why: The regex /[A-Za-z0-9+/]{40,}={0,2}\b/g causes exponential backtracking (ReDoS) on long strings of base64-like characters followed by a non-word boundary. An attacker controlling error message content (API responses, filenames) can craft input that hangs the CLI at 100% CPU.

Fix

Added upper bound {40,100} and removed \b word boundary anchor. This prevents catastrophic backtracking while still matching legitimate base64 tokens.

Testing

  • Lint: bunx @biomejs/biome check src/ passes (182 files, 0 errors)
  • Tests: bun test passes (2032 tests, 0 failures)

Fixes #3250

-- refactor/security-auditor

Fixes #3250

The unbounded quantifier {40,} with word boundary \b caused exponential
backtracking on long non-matching strings. Adding {40,100} upper bound
and removing \b prevents catastrophic backtracking.

Agent: security-auditor
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@louisgv louisgv left a comment

Choose a reason for hiding this comment

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

Security Review

Verdict: APPROVED - Critical ReDoS vulnerability fix
Commit: 3efedc6

Summary

This PR fixes a Critical ReDoS (Regular Expression Denial of Service) vulnerability in the telemetry base64 scrubbing regex. The fix adds an upper bound to prevent exponential backtracking.

Changes Reviewed

  • packages/cli/src/shared/telemetry.ts:48 - Changed {40,} to {40,100} and removed word boundary \b
  • packages/cli/package.json - Version bump to 0.32.3 (follows version policy)

Security Analysis

Before: /[A-Za-z0-9+/]{40,}={0,2}\b/g

  • Unbounded quantifier {40,} + word boundary \b causes catastrophic backtracking
  • Attack vector: long sequence of valid chars followed by non-word-boundary char
  • Can cause 100% CPU hang, requires SIGKILL

After: /[A-Za-z0-9+/]{40,100}={0,2}/g

  • Bounded quantifier {40,100} prevents exponential backtracking
  • Removed word boundary eliminates backtracking trigger
  • Still matches legitimate base64 strings (40-100 chars)
  • Longer base64 strings (>100 chars) will be matched in 100-char chunks

Test Results

  • ✅ All 2032 tests pass (0 failures)
  • ✅ Regex tested against legitimate base64 (correct matches)
  • ✅ Regex tested against ReDoS attack vectors (no hang, <1ms)
  • ✅ Version bump follows CLI version policy

Findings

No security issues. This is a clean fix for a Critical vulnerability.


-- security/pr-reviewer

@louisgv louisgv added the security-approved Security review approved label Apr 10, 2026
@louisgv louisgv merged commit 88c1f37 into main Apr 10, 2026
5 checks passed
@louisgv louisgv deleted the fix/issue-3250 branch April 10, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-approved Security review approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: ReDoS vulnerability in telemetry.ts base64 scrubbing regex

2 participants