Conversation
PUT /users/v1/{username}/email validated the new email against a
catastrophic-backtracking pattern: ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@{1}...)$
The nested (X*Y)* construction over overlapping character classes lets a
crafted string with no '@' drive exponential backtracking, hanging the
worker thread (ReDoS / API4:2019 Lack of Resources & Rate Limiting).
Replace it with an equivalent-intent email pattern where every repetition
is bounded (no unbounded quantifier is nested inside another), so
backtracking work stays linear in input length, plus a hard 254-char
length cap on the input as defense in depth. Verified locally that a
crafted payload that hung the original regex for 60+ seconds at n=30 now
gets rejected in milliseconds even at 250+ chars, while legitimate email
updates (e.g. name1@example.com) still succeed with HTTP 204.
🏆 VAmPI — CTF Patch Score1 / 9 challenges patched
Commit: 🎉 Your result is on the leaderboard — see where you rank! 🏆 |
Author
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.
Vulnerability
PUT /users/v1/{username}/emailvalidated the new email against a catastrophic-backtracking regex:The nested
(X*Y)*construction over overlapping character classes is classic ReDoS territory: a crafted input with no@(e.g. a long run of alphanumerics) forces the engine into exponential backtracking, hanging the worker thread. Locally, this pattern took 60+ seconds on a 30-character crafted payload before I gave up waiting.Fix
Replaced the regex in the
if vuln:branch ofupdate_email()(api_views/users.py) with an equivalent-intent email pattern where no unbounded quantifier is nested inside another — every repetition is capped to a small explicit bound, so backtracking work stays bounded/linear in input length regardless of content. Added a hard 254-character length cap on the input as defense in depth, since no regex-only fix should be trusted to stay cheap for arbitrarily long input.Testing (local, WSL)
vulnerable=1), seeded via/createdb, logged in asname1.'a'*30 + '!'did not return within 60 seconds.@) is now rejected with400in ~10ms.PUT /users/v1/name1/emailwith{"email": "name1@example.com"}returns204and updates the email as before. Additional valid formats (john.doe@sub.domain.co,a_b-c@x-y.io) also match correctly.