Skip to content

fix(security): decide filters on the normalised request path (#2342) - #2375

Merged
juanresendiz813 merged 4 commits into
developmentfrom
fix/2342-normalised-path
Nov 18, 2026
Merged

juanresendiz813 merged 4 commits into
developmentfrom
fix/2342-normalised-path

Conversation

@buggtb

@buggtb buggtb commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Every hand-written security filter in saiku-web now decides on the same decoded, normalised application path that the servlet container and Spring Security route on, instead of the raw percent-encoded getRequestURI(). A path that cannot be normalised fails closed.

Root cause

SaikuCsrfRequestMatcher, DemoGateFilter, EmbedAuthFilter, ShareTokenAuthFilter, OAuthBearerAuthenticationFilter, ScimAuthFilter and SpaFallbackFilter each tested getRequestURI() with startsWith. /%72est/saiku/... is /rest/saiku/... to Jetty and Spring, but not to those filters: the CSRF matcher and demo gate failed open for it (CWE-647).

The fix

  • New org.saiku.web.security.RequestPaths.pathWithinApplication(req): strips the context path, strips ;params, percent-decodes once (strict UTF-8), drops . segments, collapses //. It returns null for .., an encoded or literal slash/backslash inside a segment, NUL/control characters, or malformed/non-UTF-8 escapes.
  • The seven filters use it and their private copies are removed. null fails closed: the CSRF matcher returns "applies", DemoGateFilter.requiresVerification(null) is now true (was false), and the pre-auth filters mint no guest / process no bearer.
  • getRequestURI() now remains only in AuditLogger (raw path is desirable there) and the helper.

Not done here: the Jersey runtime probes / launcher ITs from the issue, StrictHttpFirewall tuning, and the WAR cookie-config hardening (#2348 item e).

Overlap: the #2343 PR also touches EmbedAuthFilter, ShareTokenAuthFilter and ScimAuthFilter; both are based on development, so expect a trivial rebase on whichever merges second.

Test plan

  • acceptance/2342/check.mjs red on base, green on head (structural: no filter reads the raw URI; helper and tests exist)
  • mvn -pl saiku-core/saiku-web -am test -Dtest='RequestPathsTest,SaikuCsrfRequestMatcherTest,DemoGateFilterTest,SpaFallbackFilterTest,EmbedAuthFilter*Test,ShareTokenAuthFilter*Test,ScimAuthFilter*Test,OAuthBearer*Test' passes (new tests: encoded prefix, ;jsessionid, /./, //, .., encoded slash, bad encoding)
  • mvn spotless:apply
  • Launcher ITs not run locally (full reactor build avoided)

Closes #2342

🤖 Generated with Claude Code

buggtb and others added 2 commits November 12, 2026 17:03
…2342)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…#2342)

Add RequestPaths.pathWithinApplication (percent-decode, strip ;params, drop
./, collapse //, reject .., encoded separators, NUL, bad encoding) and use it
in the CSRF matcher, demo gate, embed/share/SCIM/OAuth filters and the SPA
fallback instead of the raw getRequestURI(). A path that cannot be
normalised fails closed: CSRF demanded, demo gate applied, no guest minted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@buggtb buggtb added the security Created by Hive for agent-filed issue provenance label Nov 12, 2026
@github-actions github-actions Bot added risk/high Change risk tier: high (see docs/risk-tiers.md) area/web labels Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

CI feedback

passing · e542f27
Generated 2026-11-18T21:55:22.792Z. Machine-readable copy: ci-feedback.json (schema v1, see docs/ci-feedback.md) - artifact on this run.

Nothing to fix: every check in this commit concluded successfully.

@juanresendiz813 juanresendiz813 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One helper instead of seven copies, with strict UTF-8 decoding and good negative cases in RequestPathsTest, is a real improvement; two filters weren't adapted to it and CI is red.

Blocking

  1. blocking · Correctness · saiku-core/saiku-web/src/main/java/org/saiku/web/security/share/ShareTokenAuthFilter.java:75-76
    RequestPaths.pathWithinApplication returns null for a path it can't normalise, and this filter calls path.startsWith(VIEW_PREFIX) on it. EmbedAuthFilter:153 and OAuthBearerAuthenticationFilter got the path == null || guard; this one didn't, and it sits on the main chain. A request whose path decodes to a control character or invalid UTF-8 passes StrictHttpFirewall and then throws an NPE here: a 500 and stack trace where base answered 401. Still denies, so it's error handling, not a bypass. Jetty 12.1 rejects those spellings first, so the launcher is unaffected; a WAR on a container that forwards them is.
    Would accept: the same guard as the sibling filters, plus a ShareTokenAuthFilterTest case for a non-normalisable path (chain continues, no guest, no exception).

  2. blocking · Correctness / Compatibility · saiku-core/saiku-web/src/main/java/org/saiku/web/security/embed/EmbedAuthFilter.java:533 and :556
    parseTarget / parseAuthoringTarget still URLDecoder.decode the tail, which now arrives already decoded by RequestPaths. So it's decoded twice, and URLDecoder also turns + into a space. The comment at :531-532 is no longer true.
    Repro: the embed client encodes segments with encodeURIComponent (saiku-ui/src/embed/api.ts:64, creatorApi.ts:155), so Sales + Margin.saiku is requested as Sales%20%2B%20Margin.saiku. Base compares the token against /homes/admin/Sales + Margin.saiku; this head compares against /homes/admin/Sales Margin.saiku, and the embed returns EMBED_INVALID. Same for ai/authoring cube references. It also weakens the helper's decode-once guarantee for the token-pin comparison. No authz bypass (EmbedViewResource reads the resource from the pinned token, :141-176), only false denials.
    Would accept: drop both URLDecoder.decode calls, fix the comment, and add a test that a %2B path matches a token pinned to a name containing +.

  3. blocking · Build · acceptance/2342/spec.json:4 uses "kind": "command"; the validator (.github/scripts/acceptance-spec.mjs:28) accepts only api and ui, so ci / flake-policy tests fails with acceptance/2342: "kind" must be one of api, ui. Not a flake.
    Would accept: "kind": "ui" (the convention for a command array, docs/acceptance-specs.md:245). Your check.mjs already behaves correctly; "spec fails on base" is green.

Non-blocking

  • non-blocking · Security · RequestPaths.java:48-51 strips the context path by comparing the raw URI with getContextPath(), which on Jetty is the configured path, not the request's spelling, so an encoded spelling of a non-root context path isn't stripped. Same as base, so not a regression, and the launcher serves at root. getServletPath() + getPathInfo() (what the container routed, and what Spring's matchers use) is the robust form.
  • non-blocking · Security · ScimAuthFilter.java:70-74: a null path passes through into a permitAll chain where the filter is the authentication boundary. It should demand a bearer.
  • non-blocking · Security · DemoGateFilter.java:103 still returns "not gated" for anything under /rest/* that isn't /rest/saiku/; the issue's step 4 asked to flip that default, and only the null case was flipped.
  • non-blocking · Tests · the test plan lists the four pre-auth filter test classes as passing, but none gains an encoded or non-normalisable path case (that's how item 1 got through). The launcher IT the issue asked for isn't added.
  • Merge note: this textually conflicts with #2382 in EmbedAuthFilter.java, ScimAuthFilter.java and ShareTokenAuthFilter.java (adjacent import lines only); keep both imports.

🤖 Generated with Claude Code

@juanresendiz813 juanresendiz813 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The pre-auth filter follow-ups are tracked in #2424. To get CI green: acceptance/2342/spec.json:4 needs "kind": "ui". Separately, the double URL-decode at EmbedAuthFilter.java:533/:556 makes embeds whose names contain + or % return EMBED_INVALID; That's tracked in #2435.

🤖 Generated with Claude Code

Signed-off-by: Juan Resendiz <50384386+juanresendiz813@users.noreply.github.com>
The spec validator only accepts "api" or "ui"; a check.mjs command spec
is the "ui" kind (as acceptance/2172 is). "command" failed
ci / flake-policy tests with '"kind" must be one of api, ui'.

Signed-off-by: Juan Resendiz <50384386+juanresendiz813@users.noreply.github.com>
@juanresendiz813
juanresendiz813 added this pull request to the merge queue Nov 18, 2026
Merged via the queue into development with commit cf530fd Nov 18, 2026
27 checks passed
juanresendiz813 added a commit that referenced this pull request Nov 18, 2026
Resolve import conflicts in EmbedAuthFilter, ScimAuthFilter and
ShareTokenAuthFilter: keep both RequestPaths (#2375) and TokenPrincipals.

Signed-off-by: Juan Resendiz <50384386+juanresendiz813@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/web risk/high Change risk tier: high (see docs/risk-tiers.md) security Created by Hive for agent-filed issue provenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[security] Pre-auth, CSRF and gate filters match on the raw getRequestURI() while Spring Security and the servlet container match on the decoded path

2 participants