Skip to content

Fix Regular Expression Denial of Service in email update - #54

Open
JBHook wants to merge 1 commit into
OWASP-CTF:dc34-ctffrom
JBHook:fix-redos-update-email
Open

JBHook wants to merge 1 commit into
OWASP-CTF:dc34-ctffrom
JBHook:fix-redos-update-email

Conversation

@JBHook

@JBHook JBHook commented Aug 9, 2026

Copy link
Copy Markdown

Summary

update_email() validated the new email against a regex with nested, overlapping quantifiers - classic catastrophic-backtracking territory, letting a crafted input tie up a request thread indefinitely. Switched to the already-present backtracking-safe pattern (previously gated behind the vuln flag).

Test plan

  • Booted the app locally and validated live: normal email update still succeeds (204); a payload designed to catastrophically backtrack against the old pattern now returns in ~10ms with a clean 400 instead of hanging.

update_email() validated the new email against
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@{1}([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$,
a pattern with nested, overlapping quantifiers - classic catastrophic
backtracking territory. A crafted input (many repeated characters
followed by a non-matching character) can drive the regex engine's
running time up exponentially, tying up a request-handling thread
indefinitely.

The code already had a correct, backtracking-safe regex behind the
`vuln` flag's else branch - made that the only path (as a raw string,
which also silently fixes a pre-existing SyntaxWarning from the
unescaped `\.` in the old non-raw string literal).

Verified live: a normal email update still succeeds (204); a
40-character repeated-character-plus-non-matching-suffix payload that
would catastrophically backtrack against the old pattern now returns
in ~10ms with a 400 "invalid email" response instead of hanging.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🏆 VAmPI — CTF Patch Score

████░░░░░░░░░░░░░░░░  3 / 16 pts  (19%)

1 / 9 challenges patched

Per-challenge detail is withheld — it would reveal the rubric.

Commit: 2653b22 · scoring run

🎉 Your result is on the leaderboard — see where you rank! 🏆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant