Skip to content

Conversation

@alukach
Copy link
Member

@alukach alukach commented Dec 3, 2025

BREAKING CHANGE: Authentication failures now return 401 instead of 403

Changes the EnforceAuthMiddleware to follow HTTP RFC 7235 semantics:

  • Unauthenticated requests (no/invalid token) now return 401 Unauthorized instead of 403 Forbidden
  • Authorization failures (valid token, insufficient scopes) now return 403 Forbidden instead of 401 Unauthorized

This is a breaking change for clients that expect 403 for unauthenticated requests. The correct behavior is:

  • 401: "Who are you?" - Authentication required/failed
  • 403: "I know who you are, but you lack permission" - Authorization failed

Additional improvements:

  • Remove sensitive token data from error logs (security fix)
  • Handle missing JWT scope claim gracefully (prevent KeyError)
  • Improve error messages for better debugging
  • Add detailed logging for authorization failures

…ation failures

BREAKING CHANGE: Authentication failures now return 401 instead of 403

Changes the EnforceAuthMiddleware to follow HTTP RFC 7235 semantics:
- Unauthenticated requests (no/invalid token) now return 401 Unauthorized
  instead of 403 Forbidden
- Authorization failures (valid token, insufficient scopes) now return 403
  Forbidden instead of 401 Unauthorized

This is a breaking change for clients that expect 403 for unauthenticated
requests. The correct behavior is:
- 401: "Who are you?" - Authentication required/failed
- 403: "I know who you are, but you lack permission" - Authorization failed

Additional improvements:
- Remove sensitive token data from error logs (security fix)
- Handle missing JWT scope claim gracefully (prevent KeyError)
- Improve error messages for better debugging
- Add detailed logging for authorization failures
@alukach alukach force-pushed the fix/correct-auth-codes branch from 45df0c2 to 4c4a354 Compare December 3, 2025 19:01
@alukach alukach merged commit 17227e4 into main Dec 8, 2025
3 checks passed
@alukach alukach deleted the fix/correct-auth-codes branch December 8, 2025 18:30
alukach added a commit that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.11.0](v0.10.1...v0.11.0)
(2025-12-15)


### Bug Fixes

* **auth:** Authentication failures now return 401 instead of 403
* **auth:** correct HTTP status codes for authentication and
authorization failures
([#108](#108))
([17227e4](17227e4))
* Ensure x-forwarded-port header is used in Forwarded header
([#115](#115))
([78525b1](78525b1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: ds-release-bot[bot] <116609932+ds-release-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthony Lukach <[email protected]>
pantierra pushed a commit that referenced this pull request Dec 16, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.11.0](v0.10.1...v0.11.0)
(2025-12-15)


### Bug Fixes

* **auth:** Authentication failures now return 401 instead of 403
* **auth:** correct HTTP status codes for authentication and
authorization failures
([#108](#108))
([17227e4](17227e4))
* Ensure x-forwarded-port header is used in Forwarded header
([#115](#115))
([78525b1](78525b1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: ds-release-bot[bot] <116609932+ds-release-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthony Lukach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants