Skip to content

Support query params in PATH rules (closes #839) - #4114

Open
Sage-senpai wants to merge 1 commit into
fosrl:mainfrom
Sage-senpai:fix-query-param-blocking
Open

Sage-senpai wants to merge 1 commit into
fosrl:mainfrom
Sage-senpai:fix-query-param-blocking

Conversation

@Sage-senpai

Copy link
Copy Markdown

Closes #839.

Two things were broken:

  1. 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 through the UI/API.
  2. Even if it had been, isPathAllowed only 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: isValidUrlGlobPattern now accepts an optional ?key=value&... component after the path, validated as its own 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. 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 like key=value pairs. Otherwise the whole pattern still matches as a path exactly as before.
  • 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 existing test that exercises the ? wildcard (file?* matching fileX) still passes.

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.
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.

Issue with blocking URLs with "?" in Pangolin

1 participant