caddyauth: set user placeholders before auth rejection#7685
caddyauth: set user placeholders before auth rejection#7685steadytao merged 2 commits intocaddyserver:masterfrom
Conversation
|
I pushed a tiny follow-up to keep the package comment aligned with the new behaviour. Once CI is green this is good to merge. |
steadytao
left a comment
There was a problem hiding this comment.
@cyphercodes Thank you.
LGTM. I confirmed the patch covers the bug, only touches the caddyauth change and includes regression coverage for the unauthorised placeholder case.
|
Lint failure is not caused by this PR;
Will be handled separately. |
|
Let’s hope this does not introduce unintended side effects. Exposing http.auth.user.* placeholders before authentication has actually succeeded changes their semantics quite significantly. Until now, these placeholders implicitly represented an authenticated principal. With this change, they may represent a merely resolved or identified principal, even if authentication is rejected. This creates a few concerns:
Would it make sense to keep http.auth.user.* strictly for successfully authenticated principals and introduce a separate placeholder namespace for pre-auth resolved identities (for example http.auth.candidate.* or similar)? That would preserve the existing security semantics while still making unresolved identity metadata available where needed. |
|
I agree with your concerns. I was already thinking of a part of your concerns but thank you for helping expand my thoughts. I still think the merge was reasonable for the reported issue because it fixed the unauthorised error-handler use case and the normal handler chain is still not reached when authentication fails. That said, I agree the boundaries are worth tightening before release.
I think the clean follow-up may indeed be to preserve |
Summary
http.auth.user.*placeholders as soon as a provider returns user information, even when the request is rejected as unauthenticatedFixes #7684
Testing
go test ./modules/caddyhttp/caddyauth -run TestAuthenticationSetsUserPlaceholdersOnUnauthorized -count=1go test ./modules/caddyhttp/caddyauth -count=1go test -race ./modules/caddyhttp/caddyauth -count=1go test ./modules/caddyhttp/caddyauth ./modules/caddyhttp -count=1git diff --checkAssistance Disclosure
AI assistance used: Hermes Agent (OpenAI GPT-5.5 via Nous Research) helped draft and verify this focused change. I reviewed the diff and test output for correctness.