Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

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 occurrences
    • Share/unshare definition endpoints (lines 306, 356)
    • Create instance from shared definition (line 577)
    • Share instance endpoint (line 852)
  • internal/handlers/projects.go: 1 occurrence
    • Share project endpoint (line 440)

Test updates:

  • internal/handlers/llm_services_sharing_test.go: Updated expectation for access denied scenario (403 instead of 401)

Example change:

// Before: Authenticated user who isn't the owner gets 401
if definition.Owner != ctx.Value(auth.AuthUserKey).(string) {
    return nil, huma.Error401Unauthorized(...)
}

// After: Authenticated user who isn't the owner gets 403
if definition.Owner != ctx.Value(auth.AuthUserKey).(string) {
    return nil, huma.Error403Forbidden(...)
}

All affected cases involved checks where AuthUserKey was already set in context (user authenticated) but authorization failed (not owner/no access). Error messages normalized to lowercase for consistency.

Original prompt

See if the distinction between error responses 401 and 403 is followed correctly and consistently.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 8, 2026 17:50
…ticated users

Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Co-authored-by: awagner-mainz <2088443+awagner-mainz@users.noreply.github.com>
Copilot AI changed the title [WIP] Review distinction between 401 and 403 error responses Fix HTTP status codes: use 403 for authorization failures on authenticated users Feb 8, 2026
Copilot AI requested a review from awagner-mainz February 8, 2026 17:56
@awagner-mainz awagner-mainz marked this pull request as ready for review February 8, 2026 17:58
@awagner-mainz
Copy link
Contributor

Looks good.

@awagner-mainz awagner-mainz merged commit 52edc60 into main Feb 8, 2026
1 check passed
@awagner-mainz awagner-mainz deleted the copilot/check-error-response-handling branch February 8, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants