Repository navigation
fix: return 401 with WWW-Authenticate for unauthenticated content req… - #1649
Conversation
…uests HeaderContentGuard.permit() was raising PermissionError (mapped to 403) when the x-rh-identity header was missing, preventing browsers from showing the authentication popup. Only FeatureContentGuard had the AuthenticationError path that triggers 401 + WWW-Authenticate. Extends patch 0078 to also handle HeaderContentGuard, covering regular distributions that use the domain default content guard. Also derives the WWW-Authenticate realm from CONTENT_ORIGIN instead of hardcoding it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reviewer's GuideExtends the missing-identity authentication flow to HeaderContentGuard so unauthenticated content requests return 401 with a Basic WWW-Authenticate challenge, while ordinary authorization failures remain 403; the challenge realm is now derived from CONTENT_ORIGIN and covered by focused tests. Sequence diagram for unauthenticated content authentication challengesequenceDiagram
participant Client
participant ContentApp
participant ContentGuard
Client->>ContentApp: GET content request
ContentApp->>ContentGuard: permit()
ContentGuard-->>ContentApp: AuthenticationError
ContentApp-->>Client: 401 Unauthorized
ContentApp-->>Client: WWW-Authenticate: Basic realm=CONTENT_ORIGIN
Flow diagram for content authorization outcomesflowchart TD
A[Content request] --> B{ x-rh-identity present? }
B -->|No| C[AuthenticationError]
C --> D[401 Unauthorized + Basic challenge]
B -->|Yes, not authorized| E[PermissionError]
E --> F[403 Forbidden]
B -->|Yes, authorized| G[Serve content]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. Requests missing the x-rh-identity header now receive a 401 with a Basic authentication challenge whose realm comes from CONTENT_ORIGIN, rather than the previous denial response. Reverting restores the old response, but cannot retract challenges already sent; this does not grant access or expose protected content.
When both headers are missing, the identity guard now raises AuthenticationError which takes priority over PermissionError in the composite guard's denial logic (per patch 0078). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…uests
HeaderContentGuard.permit() was raising PermissionError (mapped to 403) when the x-rh-identity header was missing, preventing browsers from showing the authentication popup. Only FeatureContentGuard had the AuthenticationError path that triggers 401 + WWW-Authenticate.
Extends patch 0078 to also handle HeaderContentGuard, covering regular distributions that use the domain default content guard. Also derives the WWW-Authenticate realm from CONTENT_ORIGIN instead of hardcoding it.
Summary by Sourcery
Return an authentication challenge for unauthenticated content requests while retaining forbidden responses for authorization failures.
Bug Fixes:
Enhancements:
Documentation:
Tests: