Fix 404 for rules, templates, folders and silence in subfolders (Express 5 routes) - #13
Open
siccous wants to merge 1 commit into
Open
Fix 404 for rules, templates, folders and silence in subfolders (Express 5 routes)#13siccous wants to merge 1 commit into
siccous wants to merge 1 commit into
Conversation
Express 5 removed the ':id*' repeat syntax, and the migration in 02cc6f1 replaced it with ':id', which matches only a single path segment. Any rule, template, folder or silence target inside a subfolder no longer matched its route and returned 404. Use Express 5 named wildcards (rules/*id, templates/*id, folders/:type/*path, silence/*path) and read the path from the wildcard param array instead of parsing request.originalUrl, which also leaked query strings and skipped URL decoding. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Note
AI disclosure: This fix was developed with the help of an AI assistant (Claude Code by Anthropic). The AI analyzed the regression, authored the code changes and this PR description. The changes were reviewed and the fix was verified end-to-end against a running server by a human maintainer before submission.
Problem
Since the Express 4 to 5 migration (02cc6f1), any rule, template, folder or silence target located inside a subfolder returns 404.
Express 5 (path-to-regexp v8) removed the
:id*repeat syntax, and the migration replacedrules/:id*withrules/:id, which matches only a single path segment. SoGET /rules/myfolder/myruleno longer matches any route and Express returns 404 before the handler even runs. Therequest.originalUrl.split('/')parsing added to the handlers in that commit is unreachable for those paths, and buggy even for single-segment paths (query strings leak into the rule path and segments are never URL-decoded).Fix
rules/*id,templates/*id,folders/:type/*path,silence/*path.request.params.id.join('/'). This replaces theoriginalUrlparsing and also fixes the query-string and URL-decoding issues.Testing
Verified end-to-end against a running server:
GET /ruleslisting still works, as do single-segment rules (GET /rules/myrule).GET /rules/dir/subdir/myruleandGET /templates/tdir/mytemplatereturn the YAML instead of 404.PUT /folders/rules/newdir/sub,POST /rules/newdir/sub/newrule,DELETE /rules/newdir/sub/newruleandDELETE /folders/rules/newdirall work on nested paths.POST /silence/dir/subdir/myruleinvokes elastalert with the correctly resolved--rule .../rules/dir/subdir/myrule.yaml./rules/dir/my%20rule) now resolve correctly.npm run lintpasses.🤖 Generated with Claude Code