[PR #5402] ES256 JWT validation fails when JWKS key contains x5c field #25787

Open
opened 2026-08-05 07:06:28 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/5402

State: closed
Merged: No


Describe your changes

Fixed JWT validation failure when using EC/ES256 keys with x5c certificates in JWKS.
The bug occurred in shared/auth/jwt/validator.go where getPublicKey() checked for the presence of x5c before checking kty (key type). When an OIDC provider (like Authentik) returned an EC key with x5c field populated, NetBird attempted to parse it as RSA, causing authentication to fail with "key is not a valid RSA public key" error.
The fix reorders the checks to verify kty first, ensuring EC keys are handled correctly regardless of whether x5c is present.

Closes #5302

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Explanation: This is an internal bug fix that corrects existing behavior without changing the public API or configuration format. Users don't need to change any settings - ES256/EC keys will simply work as documented after this fix.

Docs PR URL (required if "docs added" is checked)

N/A

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Bug Fixes
    • JWT verification now chooses the verification method by key type first, improving correctness for RSA and EC tokens.
    • RSA verification prefers certificate-sourced keys when available; EC verification prefers explicit curve coordinates and validates supported curves, with safer fallbacks.
    • Error messages now clearly indicate incomplete EC keys, unsupported key types, and certificate/parsing failures.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5402 **State:** closed **Merged:** No --- ## Describe your changes Fixed JWT validation failure when using EC/ES256 keys with x5c certificates in JWKS. The bug occurred in shared/auth/jwt/validator.go where getPublicKey() checked for the presence of x5c before checking kty (key type). When an OIDC provider (like Authentik) returned an EC key with x5c field populated, NetBird attempted to parse it as RSA, causing authentication to fail with "key is not a valid RSA public key" error. The fix reorders the checks to verify kty first, ensuring EC keys are handled correctly regardless of whether x5c is present. ## Issue ticket number and link Closes #[5302](https://github.com/netbirdio/netbird/issues/5302) ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) Explanation: This is an internal bug fix that corrects existing behavior without changing the public API or configuration format. Users don't need to change any settings - ES256/EC keys will simply work as documented after this fix. ### Docs PR URL (required if "docs added" is checked) N/A https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * JWT verification now chooses the verification method by key type first, improving correctness for RSA and EC tokens. * RSA verification prefers certificate-sourced keys when available; EC verification prefers explicit curve coordinates and validates supported curves, with safer fallbacks. * Error messages now clearly indicate incomplete EC keys, unsupported key types, and certificate/parsing failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 07:06:28 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#25787