Fix HTTP status codes: use 403 for authorization failures on authenticated users #16
+7
−7
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.
The codebase was incorrectly returning 401 (Unauthorized) when authenticated users lacked permission to access resources. Per HTTP semantics, 401 indicates authentication failure (missing/invalid credentials), while 403 indicates authorization failure (authenticated but insufficient permissions).
Changes
Handler fixes - Changed 401 to 403 for ownership/permission checks:
internal/handlers/llm_services.go: 4 occurrencesinternal/handlers/projects.go: 1 occurrenceTest updates:
internal/handlers/llm_services_sharing_test.go: Updated expectation for access denied scenario (403 instead of 401)Example change:
All affected cases involved checks where
AuthUserKeywas already set in context (user authenticated) but authorization failed (not owner/no access). Error messages normalized to lowercase for consistency.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.