Skip to content

Close the access protection bypass through crafted paths - #137

Merged
tricknotes merged 2 commits into
mainfrom
gate-path-normalization
Nov 23, 2026
Merged

tricknotes merged 2 commits into
mainfrom
gate-path-normalization

Conversation

@tricknotes

Copy link
Copy Markdown
Owner

Summary

The access protection of an app (ARCHITECTURE 8.3) could be skipped without logging in. Reproduced against a real Caddy, with an unauthenticated POST:

Request path X-Koroku-Wake: <slug> Before Now
/graphql/../.koroku/auth/x yes 200 from the app 404
/graphql/..%2F.koroku/auth/x yes 200 from the app 404
/.KOROKU/auth/x yes 200 from the app 404
/admin/..%2Fwebhooks/x (exempt path /webhooks/) no 200 from the app 401
/admin/../webhooks/x no 200 from the app 401
/WEBHOOKS/x no 200 from the app 401

Two things combined: Caddy matches the decoded, cleaned, case-insensitive path but forwards the request as sent, with the client's own headers; koroku judged the raw path with a case-sensitive prefix test and trusted a client-sent X-Koroku-Wake on routes where Caddy does not set it.

  • Caddy: every route to koroku other than the wake proxy deletes a client-sent X-Koroku-Wake.
  • koroku: wakeDispatch and hostDispatch decide what is a reserved path on the path as Caddy's matcher reads it; the wake handler never proxies a path with ., .. or //.
  • Exempt paths: a request skips the check only when the raw request target starts with the prefix exactly as configured and its path is not ambiguous (dot segments, //, a backslash, encoded ., /, \). Anything else goes through the login check instead of being refused, so logged-in users are unaffected, and exempt paths do not depend on koroku being up.
  • An app's active custom domain no longer reaches the console's handlers (second commit).

Visible to users: exempt paths are now case-sensitive (/webhooks/ does not exempt /Webhooks/x), and callers that send // or %2F in the path of an exempt URL get 401.

Test plan

  • go vet ./..., go vet -tags integration ./..., go test ./...
  • Integration against a real Caddy (2.11.9, and 2.7.6 when this was written): TestAccessProtectionThroughCaddy with 37 path spellings, TestWakeHeaderReachesKorokuOnlyFromTheWakeRoute
  • The whole integration suite on the combined stack
  • HTTP/2 and HTTP/3 clients (the tests speak HTTP/1.1)

🤖 Generated with Claude Code

tricknotes and others added 2 commits November 24, 2026 03:43
Caddy's path matcher compares the decoded, cleaned, lower-cased path
but forwards the request as the client sent it, headers included. koroku
compared the raw path case-sensitively and trusted an X-Koroku-Wake
header on routes where Caddy does not set it. Two ways around the gate
of a protected app followed, both reproduced against a real Caddy:

- POST /graphql/../.koroku/auth/x (or ..%2F, or /.KOROKU/auth/x) with
  X-Koroku-Wake: <slug>. Caddy sent it to koroku as a login endpoint,
  koroku did not recognize the path as its own, honoured the header and
  proxied the request to the app without a gate check.
- POST /admin/../webhooks/x or /admin/..%2Fwebhooks/x with /webhooks/
  exempt. Caddy read it as /webhooks/x and skipped forward_auth, the app
  received the path as sent.

Caddy side:

- Every proxy to koroku that is not the wake route (the console, the
  /.koroku/auth/ endpoints, the gate check) deletes X-Koroku-Wake, so
  the header reaches koroku only where Caddy sets it.
- A request skips forward_auth only if, besides the cleaned path being
  under an exempt prefix, the request target as sent starts with that
  prefix in the configured spelling (same case, not percent-encoded) and
  its path has no "." or ".." segment (also "..;x"), no "//", no
  backslash and no encoded ".", "/" or "\". Anything else is not refused,
  it goes through forward_auth like any other path. This is an
  expression (CEL) matcher on {http.request.orig_uri}. vars_regexp is
  not used because it expands placeholders found in the value, which
  would let a client rewrite the string that is matched.
  /Webhooks/ is no longer exempt for /webhooks/: koroku cannot know
  whether the app routes case-sensitively.

koroku side:

- wakeDispatch and hostDispatch decide whether a path is a gate path on
  the form Caddy's matcher compares (caddy.MatchedPath), so a request
  Caddy routed as a gate path is never taken for a path of the app. The
  gate handlers answer only the exact spelling; any other is 404.
- The wake handler answers 400 to a path with "." or ".." segments or
  repeated slashes instead of waking the app and proxying it.

Tests: the probes above (and more spellings) are permanent assertions
in TestAccessProtectionThroughCaddy, and
TestWakeHeaderReachesKorokuOnlyFromTheWakeRoute records what a stand-in
for koroku receives from a real Caddy. Both also pass against Caddy
2.7.6, the oldest version the provisioning script accepts.

The prepare-app skill told users that exempt paths ignore case; it now
describes the exact spelling and which calls do not skip the login.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
hostDispatch refused everything but the gate paths on <slug>.<base>
hostnames, but took an active custom domain of an app for a hostname of
the console: a request on such a domain that koroku did not read as a
gate path fell through to the console and its API. Caddy forwards
nothing of that kind today, so this is a second line behind the path
normalization, in case Caddy and koroku ever disagree about a path
again.

A hostname is now an app's if it is under the base domain or an active
custom domain (one indexed lookup, only for requests whose Host is
neither the console's nor under the base domain). Hostnames that are no
app's still get the console: local development and direct access to the
loopback listen address depend on that, so the console is not limited to
the console hostname.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Base automatically changed from policy-allowlist to main November 23, 2026 19:23
@tricknotes
tricknotes merged commit 281aecf into main Nov 23, 2026
5 checks passed
@tricknotes
tricknotes deleted the gate-path-normalization branch November 23, 2026 19:23
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.

1 participant