Repository navigation
Render item content when ?regex= is invalid - #2399
Merged
Merged
Conversation
Collaborator
|
@rikvanriel, did you see the conflict message? Please rebase with current master and resolve the conflict. There is also issue #2234 related to this topic. |
Contributor
Author
|
Rebased on current master and resolved the conflict (append-append in test_frontend.py — kept both the new search regression tests and the highlight test). Note re #2234: this PR only stops invalid patterns from crashing the view (re.error → match-nothing). Pathological-but-valid patterns (ReDoS) are still unaddressed and left for that issue. |
When an item is viewed with ?regex= containing an invalid regular expression, highlight.py does re.compile() on user-controlled input without any exception handling. The re.error is caught by the generic error handler, so the item body is replaced by an error box and a traceback is logged for every such request. All it takes is a crafted query string on any public item: GET /MoinTest?regex=[[[ Wrap the compile in try/except re.error and fall back to a pattern that never matches ((?!)), so the view renders the content without highlights. Valid-but-pathological patterns (ReDoS, issue moinwiki#2234) are not addressed here.
rikvanriel
force-pushed
the
fix-highlight-regex-crash
branch
from
October 21, 2026 00:33
1039a46 to
fd8a369
Compare
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.
Render item content when ?regex= is invalid
When an item is viewed with ?regex= containing an invalid regular
expression, highlight.py does re.compile() on user-controlled input
without any exception handling. The re.error is caught by the generic
error handler, so the item body is replaced by an error box and a
traceback is logged for every such request. All it takes is a crafted
query string on any public item: GET /MoinTest?regex=[[[
Wrap the compile in try/except re.error and fall back to a pattern
that never matches ((?!)), so the view renders the content without
highlights. Valid-but-pathological patterns (ReDoS, issue #2234) are
not addressed here.