Skip to content

Render item content when ?regex= is invalid - #2399

Merged
UlrichB22 merged 1 commit into
moinwiki:masterfrom
rikvanriel:fix-highlight-regex-crash
Oct 21, 2026
Merged

UlrichB22 merged 1 commit into
moinwiki:masterfrom
rikvanriel:fix-highlight-regex-crash

Conversation

@rikvanriel

@rikvanriel rikvanriel commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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.

@UlrichB22

Copy link
Copy Markdown
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.

@rikvanriel

Copy link
Copy Markdown
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
rikvanriel force-pushed the fix-highlight-regex-crash branch from 1039a46 to fd8a369 Compare October 21, 2026 00:33
@rikvanriel rikvanriel changed the title Fix crash on invalid ?regex= highlighting param Render item content when ?regex= is invalid Oct 21, 2026
@UlrichB22
UlrichB22 merged commit e7fe386 into moinwiki:master Oct 21, 2026
10 checks passed
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.

2 participants