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

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5402
Author: @AblabiX
Created: 2/20/2026
Status: Closed

Base: mainHead: fix_jwt_ES256_validation


📝 Commits (7)

  • 3471d7e ES256 JWT validation fails when JWKS key contains x5c field
  • e312e25 Update validator.go
  • baa8288 Update validator.go 2
  • 7c314c1 Update validator.go 3
  • 7452ff2 Validate EC curve values explicitly before processing
  • 9884a16 Validate the curve on the x5c fallback
  • a3f2b5b Extract EC key handling to satisfy complexity limits

📊 Changes

1 file changed (+72 additions, -11 deletions)

View changed files

📝 shared/auth/jwt/validator.go (+72 -11)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5402 **Author:** [@AblabiX](https://github.com/AblabiX) **Created:** 2/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix_jwt_ES256_validation` --- ### 📝 Commits (7) - [`3471d7e`](https://github.com/netbirdio/netbird/commit/3471d7e2ded30bf2f0b985d27a0edb5c83eddc92) ES256 JWT validation fails when JWKS key contains x5c field - [`e312e25`](https://github.com/netbirdio/netbird/commit/e312e259cab0c6b68a18c8c7c3a25398408e4b85) Update validator.go - [`baa8288`](https://github.com/netbirdio/netbird/commit/baa8288e9a769f1264c8a8ed26a9f8ff41482ad1) Update validator.go 2 - [`7c314c1`](https://github.com/netbirdio/netbird/commit/7c314c168142fc9943643dfd90b2c801cd534229) Update validator.go 3 - [`7452ff2`](https://github.com/netbirdio/netbird/commit/7452ff2ce9653be677bfc2b273059e80671e7d11) Validate EC curve values explicitly before processing - [`9884a16`](https://github.com/netbirdio/netbird/commit/9884a16aaf56ed6b2fd3576700f2cebfd47fc082) Validate the curve on the x5c fallback - [`a3f2b5b`](https://github.com/netbirdio/netbird/commit/a3f2b5b0715139e06e496a1ca7ae35a227449cea) Extract EC key handling to satisfy complexity limits ### 📊 Changes **1 file changed** (+72 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `shared/auth/jwt/validator.go` (+72 -11) </details> ### 📄 Description ## 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 --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:06:27 -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#25778