Repository navigation
Close the access protection bypass through crafted paths - #137
Merged
Merged
Conversation
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>
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.
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:
X-Koroku-Wake: <slug>/graphql/../.koroku/auth/x/graphql/..%2F.koroku/auth/x/.KOROKU/auth/x/admin/..%2Fwebhooks/x(exempt path/webhooks/)/admin/../webhooks/x/WEBHOOKS/xTwo 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-Wakeon routes where Caddy does not set it.X-Koroku-Wake.wakeDispatchandhostDispatchdecide what is a reserved path on the path as Caddy's matcher reads it; the wake handler never proxies a path with.,..or//.//, 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.Visible to users: exempt paths are now case-sensitive (
/webhooks/does not exempt/Webhooks/x), and callers that send//or%2Fin the path of an exempt URL get 401.Test plan
go vet ./...,go vet -tags integration ./...,go test ./...TestAccessProtectionThroughCaddywith 37 path spellings,TestWakeHeaderReachesKorokuOnlyFromTheWakeRoute🤖 Generated with Claude Code