Fix ReDoS vulnerability in tag validation regex#308
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a potential regex-based denial-of-service (ReDoS) issue in tag validation by simplifying the tag validation regex and adding a regression test to catch catastrophic backtracking/performance issues.
Changes:
- Updated
TAG_VALIDATION_REto remove redundant leading/trailing\s*and avoid catastrophic backtracking. - Added
test_redos.pywith a performance regression test and basic validation behavior checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
apprise_api/api/views.py |
Simplifies tag validation regex to mitigate ReDoS risk. |
apprise_api/api/tests/test_redos.py |
Adds tests intended to validate both performance and correctness of the tag validation regex. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1b1787e to
0b103a9
Compare
|
Thank you! I really appreciate the PR. 🙏I’m working through it to fully understand the implications, although I’m not able to test it directly at the moment. I’d like to clarify how this issue is actually exposed. My current understanding is that a potential DoS risk would only exist if the existing tag validation (which runs prior to applying the regex in question) were absent. If that validation is already enforced, would that not mitigate the concern? Please let me know if I’m misunderstanding this. From reviewing the tests, it appears they demonstrate that the regex could present a DoS risk if used in isolation, but not necessarily in the way it is currently implemented. Is that accurate? Also, is there a realistic scenario where this could be exploited via a GET or POST request through the API, or is this change more about defensive hardening to prevent future misuse or regression? If possible, it would be helpful to include a test case that reflects a realistic exploitation path, assuming one exists. |
0b103a9 to
0d6f42e
Compare
|
@caronc, the vulnerability is actually reachable through the standard API endpoints. While there is a global 3MB limit on payloads, there isn't any specific length validation for the tag parameter before it hits the regex. I've added |
0d6f42e to
e941604
Compare
|
@caronc Done as requested and updated the test cases to reflect this change, also cleaned up the indentation and inline comment spacing in the test file, and switched to |
d08e4d1 to
5109283
Compare
5109283 to
39884ad
Compare
|
If it helps, you can verify this works before you commit with options like: # Just test /align formating where possible
tox -e format
# run tests yourself (if it's a test failing)
tox -e qa
# run a specific test (below 'just' runs any test_ with redos in function name):
tox -qa -- -k redos |
|
@caronc thanks for the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #308 +/- ##
===========================================
+ Coverage 99.37% 100.00% +0.62%
===========================================
Files 7 12 +5
Lines 794 1239 +445
Branches 0 221 +221
===========================================
+ Hits 789 1239 +450
+ Misses 5 0 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Merged! thank you very much @RinZ27 🚀 |
Description:
Fixed a ReDoS vulnerability in the tag validation regex within
views.py. The original pattern suffered from catastrophic backtracking due to overlapping whitespace groups, which could lead to high CPU consumption with crafted payloads.Replaced the regex with a linear-time alternative that maintains the same validation logic but prevents exponential complexity.
Related issue (if applicable): N/A
Checklist
ruff)