fix(sdk): clear SonarQube ReDoS hotspot in base64url encode#62
Merged
Conversation
…+ S7781)
SonarQube flagged `/=+$/` in encode() as a slow-regex hotspot (S5852,
ReDoS/CWE-1333). It only ran on btoa() output where `=` is at most 2 trailing
padding chars, so the quadratic input was unreachable — but rather than dismiss
it, remove the regex entirely: convert all the global-regex replaces in encode()
and decode() to replaceAll() with string literals (ES2022 target). This also
satisfies S7781 ("prefer replaceAll over replace"), keeps the transforms linear
and non-backtracking, and is more readable.
Behavior-preserving: base64 only emits `=` as trailing padding, so stripping all
`=` equals stripping the trailing run; the rest are exact equivalents. Output is
byte-identical and the full vitest round-trip suite (76 tests) and tsc pass.
Refs #60
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wolpert
force-pushed
the
fix-base64url-redos-hotspot
branch
from
June 13, 2026 14:35
c65e194 to
11d1086
Compare
|
wolpert
enabled auto-merge (rebase)
June 13, 2026 14:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Resolves the single SonarQube security hotspot on the browser SDK (
codeheadsystems_passkeys-browser).The hotspot
typescript:S5852— slow regular expression / ReDoS (category DoS, CWE-400/CWE-1333).clients/passkeys-browser/src/base64url.ts:18— the/=+$/padding stripper inencode().Why it was effectively safe
The regex only runs on
btoa()output, where=appears solely as 0–2 trailing padding characters (never interior). The catastrophic/quadratic input S5852 warns about — a long run of=followed by a non-matching char — is therefore unreachable, and the input is the host's own bounded bytes, not attacker-controlled.The fix (clear it at the source rather than dismiss it)
Since
=only ever appears as trailing padding in base64, removing all=is equivalent to stripping a trailing run, and/=/gis a single-character, non-backtracking match:Byte-identical output; the full vitest suite (76 tests, incl. base64url round-trips) passes. This removes the finding at the root so it can't reappear on a future scan — no manual "mark Safe" sign-off needed.
🤖 Generated with Claude Code