Commit 11d1086
fix(sdk): replace base64url regexes with replaceAll (SonarQube S5852 + 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>1 parent 539316c commit 11d1086
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | | - | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
0 commit comments