Repository navigation
fix(security): decide filters on the normalised request path (#2342) - #2375
Conversation
…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>
CI feedbackpassing · Nothing to fix: every check in this commit concluded successfully. |
juanresendiz813
left a comment
There was a problem hiding this comment.
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
-
blocking· Correctness ·saiku-core/saiku-web/src/main/java/org/saiku/web/security/share/ShareTokenAuthFilter.java:75-76
RequestPaths.pathWithinApplicationreturnsnullfor a path it can't normalise, and this filter callspath.startsWith(VIEW_PREFIX)on it.EmbedAuthFilter:153andOAuthBearerAuthenticationFiltergot thepath == 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 passesStrictHttpFirewalland 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 aShareTokenAuthFilterTestcase for a non-normalisable path (chain continues, no guest, no exception). -
blocking· Correctness / Compatibility ·saiku-core/saiku-web/src/main/java/org/saiku/web/security/embed/EmbedAuthFilter.java:533and:556
parseTarget/parseAuthoringTargetstillURLDecoder.decodethe tail, which now arrives already decoded byRequestPaths. So it's decoded twice, andURLDecoderalso turns+into a space. The comment at:531-532is no longer true.
Repro: the embed client encodes segments withencodeURIComponent(saiku-ui/src/embed/api.ts:64,creatorApi.ts:155), soSales + Margin.saikuis requested asSales%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 returnsEMBED_INVALID. Same forai/authoringcube references. It also weakens the helper's decode-once guarantee for the token-pin comparison. No authz bypass (EmbedViewResourcereads the resource from the pinned token,:141-176), only false denials.
Would accept: drop bothURLDecoder.decodecalls, fix the comment, and add a test that a%2Bpath matches a token pinned to a name containing+. -
blocking· Build ·acceptance/2342/spec.json:4uses"kind": "command"; the validator (.github/scripts/acceptance-spec.mjs:28) accepts onlyapiandui, soci / flake-policy testsfails withacceptance/2342: "kind" must be one of api, ui. Not a flake.
Would accept:"kind": "ui"(the convention for acommandarray,docs/acceptance-specs.md:245). Yourcheck.mjsalready behaves correctly; "spec fails on base" is green.
Non-blocking
non-blocking· Security ·RequestPaths.java:48-51strips the context path by comparing the raw URI withgetContextPath(), 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: anullpath passes through into apermitAllchain where the filter is the authentication boundary. It should demand a bearer.non-blocking· Security ·DemoGateFilter.java:103still returns "not gated" for anything under/rest/*that isn't/rest/saiku/; the issue's step 4 asked to flip that default, and only thenullcase 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.javaandShareTokenAuthFilter.java(adjacent import lines only); keep both imports.
🤖 Generated with Claude Code
juanresendiz813
left a comment
There was a problem hiding this comment.
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>
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>
Summary
Every hand-written security filter in
saiku-webnow decides on the same decoded, normalised application path that the servlet container and Spring Security route on, instead of the raw percent-encodedgetRequestURI(). A path that cannot be normalised fails closed.Root cause
SaikuCsrfRequestMatcher,DemoGateFilter,EmbedAuthFilter,ShareTokenAuthFilter,OAuthBearerAuthenticationFilter,ScimAuthFilterandSpaFallbackFiltereach testedgetRequestURI()withstartsWith./%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
org.saiku.web.security.RequestPaths.pathWithinApplication(req): strips the context path, strips;params, percent-decodes once (strict UTF-8), drops.segments, collapses//. It returnsnullfor.., an encoded or literal slash/backslash inside a segment, NUL/control characters, or malformed/non-UTF-8 escapes.nullfails closed: the CSRF matcher returns "applies",DemoGateFilter.requiresVerification(null)is nowtrue(wasfalse), and the pre-auth filters mint no guest / process no bearer.getRequestURI()now remains only inAuditLogger(raw path is desirable there) and the helper.Not done here: the Jersey runtime probes / launcher ITs from the issue,
StrictHttpFirewalltuning, and the WARcookie-confighardening (#2348 item e).Overlap: the #2343 PR also touches
EmbedAuthFilter,ShareTokenAuthFilterandScimAuthFilter; both are based ondevelopment, so expect a trivial rebase on whichever merges second.Test plan
acceptance/2342/check.mjsred 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:applyCloses #2342
🤖 Generated with Claude Code