Repository navigation
Support query params in PATH rules (closes #839) - #4114
Open
Sage-senpai wants to merge 1 commit into
Open
Sage-senpai wants to merge 1 commit into
Sage-senpai wants to merge 1 commit into
Conversation
isValidUrlGlobPattern rejected any rule value containing "?", so a rule meant to block a login URL with a query param (e.g. /audiobookshelf/login/?autoLaunch=0) couldn't even be saved. And even if it had been, isPathAllowed only ever compared path segments, so a saved rule with a query component would never have matched a real request either, since the query string was never passed in or checked at all. Both are fixed: - validators.ts: isValidUrlGlobPattern now accepts an optional ?key=value&... component after the path, validated as its own set of key/value pairs (with * wildcard support in values). - pathMatch.ts: isPathAllowed takes an optional query param record and matches each key=value pair in the rule's query component against it. Since ? already means "match one character" as a glob wildcard within a path segment (e.g. "file?*"), a bare ? is only treated as the start of a query component when what follows actually looks like key=value pairs; otherwise the whole pattern still matches as a path exactly as before. Caught this via the existing verifySession.test.ts coverage for that wildcard before it could regress. - verifySession.ts: threads the request's query object through checkRules into isPathAllowed, where it was already being parsed but never used for PATH rules. Added tests for both the validator and the matcher, covering the original bug report's exact case, wildcard query values, missing/empty query on the request, and the query-vs-wildcard disambiguation. Ran the full suite before and after on a clean tree: same pre-existing failures in both (missing config file, missing native sqlite bindings, unrelated to this change), and the one existing test that exercises the ? wildcard (file?* matching fileX) still passes.
Sage-senpai
requested review from
miloschwartz and
oschwartz10612
as code owners
November 15, 2026 10:38
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.
Closes #839.
Two things were broken:
isValidUrlGlobPatternrejected any rule value containing "?", so a rule meant to block a login URL with a query param (e.g./audiobookshelf/login/?autoLaunch=0) couldn't even be saved through the UI/API.isPathAllowedonly ever compared path segments, the query string was never passed in or checked at all, so a saved rule with a query component would never actually match a real request.Fixed both:
validators.ts:isValidUrlGlobPatternnow accepts an optional?key=value&...component after the path, validated as its own key/value pairs (with*wildcard support in values).pathMatch.ts:isPathAllowedtakes an optional query param record and matches eachkey=valuepair in the rule's query component against it. Important:?already means "match one character" as a glob wildcard within a path segment (e.g.file?*), so a bare?is only treated as the start of a query component when what follows actually looks likekey=valuepairs. Otherwise the whole pattern still matches as a path exactly as before.verifySession.ts: threads the request'squeryobject throughcheckRulesintoisPathAllowed, where it was already being parsed but never used for PATH rules.Added tests for both the validator and the matcher, covering the original bug report's exact case, wildcard query values, missing/empty query on the request, and the query-vs-wildcard disambiguation.
Ran the full suite before and after on a clean tree: same pre-existing failures in both (missing config file, missing native sqlite bindings — unrelated to this change), and the existing test that exercises the
?wildcard (file?*matchingfileX) still passes.