fix(webdav): remove polynomial-redos in Basic auth header regex - #439
Merged
davidwkeith merged 1 commit intoJul 24, 2026
Merged
Conversation
parseBasicAuthorization's /^basic\s+(.+)$/i had \s+ immediately before (.+)$, ambiguous over runs of whitespace in the same way the already-fixed webmention Link header regex (#436) was. Replaced with an unambiguous search()/slice() split. Closes GitHub code scanning alert #11 (js/polynomial-redos).
davidwkeith
commented
Jul 24, 2026
davidwkeith
left a comment
Owner
Author
There was a problem hiding this comment.
Small, well-scoped ReDoS fix that follows the same pattern already established in #436. Verified the replacement search/slice split against the old regex across the relevant edge cases (missing separator, wrong auth scheme, multiple whitespace, trailing-whitespace-only header) — behavior is preserved. Changeset included, existing test coverage (credentials.test.ts) continues to pass, CI is green, and the PR template's Summary/Packages affected/Checklist sections match CONTRIBUTING.md's structure. Left one non-blocking nit on the CI-gate checklist wording. No changes requested.
Generated by Claude Code
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.
Summary
Fixes GitHub code scanning alert #11 (
js/polynomial-redos, CodeQL):parseBasicAuthorization's regex inpackages/webdav/src/credentials.tshad\s+immediately before(.+)$. Since\sis a subset of what.matches,the two quantifiers were ambiguous about how to split the client-supplied
Authorizationheader between them — the same shape already fixed in@dwk/webmention'sparseLinkHeader(#436).Fix: replaced the combined regex with a plain
search()/slice()split onthe first whitespace run, which is unambiguous by construction (a linear
scan, no backtracking). Behavior is unchanged, confirmed by the existing
parseBasicAuthorizationtest suite (4/4 passing, 128/128 across the whole@dwk/webdavpackage).I also investigated the other four currently-open alerts of this same title
(
#8/#9inpackages/mastodon-api/src/sanitize.ts:139,144,#10inpackages/webauthn/src/encoding.ts:42,#12inpackages/webdav/src/locks.ts:97). All four regexes involved use only asingle quantifier per character class with no adjacent-quantifier ambiguity
(e.g.
/=+$/,/^\/+/, or the sticky, mutually-exclusive-character-classtokenizer in
sanitize.tsthat already has extensive complexity-proofcomments from a prior ReDoS hardening pass). I stress-tested each against
adversarial multi-hundred-KB inputs locally and saw flat, linear timing —
they don't reproduce backtracking blowup, so I've left them as-is rather than
changing working code without a reproducible finding. Flagging them here in
case they should be dismissed as false positives on the CodeQL side.
Packages affected
@dwk/webdavChecklist
spec/packages/and updated them if behaviour changed — not applicable, no behavior change, pure regex hardeningsrc/*.test.ts) — not applicable, existingcredentials.test.tscoverage already exercisesparseBasicAuthorizationand continues to passpnpm lint && pnpm format:check && pnpm typecheck && pnpm build && pnpm test—lint/format:checkran locally, repo-wide;typecheck/build/testran locally scoped to@dwk/webdavonly (128/128 passing). The full repo-widetypecheck/build/testsequence CONTRIBUTING.md's gate calls for was covered by CI'sbuild-testjob instead, which is green on this PR.pnpm changeset) if this touches a publishable packagecatalog.json/conformance/status.jsonif this adds a new mountable worker or changes conformance status — not applicable, no new worker or conformance status change