Repository navigation
gateway: fix PR #246 — accept Bearer scheme via Indy's OnParseAuthentication - #257
Merged
Merged
Conversation
PR #246 wired CheckGatewayAuth into OnCommandGet but missed Indy's TIdCustomHTTPServer hard-coding "Basic" as the only natively-known auth scheme. When a request arrives with `Authorization: Bearer <tok>`, IdCustomHTTPServer.pas line 1454 calls DoParseAuthentication which recognises only Basic; the next line raises EIdHTTPUnsupportedAuthorisationScheme, caught at line 1476 and converted to a 401 with `WWW-Authenticate: Basic realm=""` -- BEFORE OnCommandGet runs. So PasClaw's CheckGatewayAuth never sees the bearer at all and rejects every authenticated request. Symptom: web UI prompts for the token, operator pastes the correct value, every /v1/* call returns 401 forever. `Server: PasClaw/dev` in the response is misleading -- Indy uses the configured ServerSoftware header even when its own exception handler builds the response, hence why this looked like a PasClaw-issued 401 the whole time. Fix: wire OnParseAuthentication to a handler that just sets VHandled := True for every scheme. Indy's built-in Basic path still fires first; everything else (Bearer, and future schemes if anyone adds them) falls through to OnCommandGet where CheckGatewayAuth parses the raw header directly via ExtractBearerToken. Verified against a live gateway: - no auth header -> 401 (unchanged) - wrong bearer -> 401 with WWW-Authenticate: Bearer realm="pasclaw" - right bearer -> 200 (was 401 before this commit) - exempt /v1/health, no auth -> 200 (unchanged) The reason this hid in PR #246: web UI's gwFetch suppresses the Authorization header when no token is stored in localStorage, and the default token-less config doesn't gate /v1/* at all -- so no deployment exercised the bearer path until [email protected] turned auth on for his DO App Platform instance.
This was referenced Jun 14, 2026
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
PR #246 wired bearer-token auth into
OnCommandGetbut missed that Indy'sTIdCustomHTTPServernatively recognizes onlyBasicas an auth scheme. EveryAuthorization: Bearer <tok>request is intercepted by Indy's built-in auth machinery and converted to a 401 withWWW-Authenticate: Basic realm=""beforeOnCommandGetruns — soCheckGatewayAuthnever sees the bearer at all and rejects every authenticated request, even with the correct token.Repro
Set
PASCLAW_GATEWAY_TOKEN=awesomein the container env, start the gateway, then:Root cause
Indy walks the Authorization header inside
IdCustomHTTPServer.pasat line 1454, callsDoParseAuthenticationwhich only recognizesBasic, and raisesEIdHTTPUnsupportedAuthorisationSchemeon every other scheme:The exception handler at line 1476 converts it to a 401 with the canonical
WWW-Authenticate: Basicheader — all beforeDoCommandGet(where PasClaw's middleware lives) ever fires.Fix
Wire
FHTTP.OnParseAuthenticationto a handler that just setsVHandled := Truefor every non-Basic scheme. Indy's built-inBasicparsing path is unchanged;Bearerand any future scheme now fall through toOnCommandGet, where the existingExtractBearerToken+ constant-time comparison inCheckGatewayAuthdoes the real validation.Why this hid in PR #246
gwFetch(webui.html) doesn't attach anAuthorizationheader until a token is stored inlocalStorage, so for a fresh / token-less deployment no Authorization header ever reaches the gateway./v1/*at all — so every request was being routed through the no-token-needed path.PASCLAW_GATEWAY_TOKENset), every request 401'd.Verified
Against a live gateway with
PASCLAW_GATEWAY_TOKEN=awesome:Test plan
WWW-Authenticate: Bearer realm="pasclaw", notBasicStacked relationship
Independent of PR #255 (startup auth-state logging). #255 makes the misconfiguration visible in logs; this PR is the actual functional fix. Either can merge first.
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code