Skip to content

fix: return 401 instead of 500 for invalid bearer tokens (IS-5805)#8

Open
mykyta-batalov wants to merge 1 commit intomasterfrom
fix/IS-5805-invalid-bearer-returns-401
Open

fix: return 401 instead of 500 for invalid bearer tokens (IS-5805)#8
mykyta-batalov wants to merge 1 commit intomasterfrom
fix/IS-5805-invalid-bearer-returns-401

Conversation

@mykyta-batalov
Copy link
Copy Markdown

@mykyta-batalov mykyta-batalov commented Mar 16, 2026

Summary

  • Invalid/expired/empty bearer tokens caused the OIDC plugin to return HTTP 500 instead of 401
  • The plugin fell through verify_bearer_jwt()introspect()make_oidc(), where resty.openidc.authenticate() failed with a non-standard error string, triggering the catch-all 500 at handler.lua:106
  • Added short-circuit 401 responses after failed JWT verify and introspection when a bearer token is detected via has_bearer_access_token()
  • Browser/session flows (no bearer token) are unaffected — they still fall through to make_oidc()

Branch restructuring

  • Created v2 branch to preserve the v2.0.x work (23 commits)
  • Reset master to v1.4.0-7 (current production) so this fix targets the deployed version
  • Tagged as v1.4.0-8

Test plan

  • Deploy to stage and test with an invalid bearer token → should now return 401
  • Test with an empty bearer (Authorization: Bearer ) → should return 401
  • Test with a valid bearer token → should work as before (200)
  • Test with no Authorization header (browser flow) → should redirect to OIDC provider as before

Jira: IS-5805

🤖 Generated with Claude Code

When a bearer token is present but invalid/expired/empty, the plugin
was falling through to make_oidc() which returned a generic 500.
Now short-circuits with 401 after failed JWT verify or introspection
when a bearer token is detected, preventing the fallthrough.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@unblocked unblocked Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues found

About Unblocked

Unblocked has been set up to automatically review your team's pull requests to identify genuine bugs and issues.

📖 Documentation — Learn more in our docs.

💬 Ask questions — Mention @unblocked to request a review or summary, or ask follow-up questions about your code.

👍 Give feedback — React to comments with 👍 or 👎 to help us improve.

⚙️ Customize — Adjust settings in your preferences.

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.

1 participant