Commit 83285e7
authored
fix(core): infer JWT algorithms for JWKS keys without alg (#3434)
## Summary
- Fix JWT verification for IdPs whose JWKS keys omit `alg`, such as
Microsoft Entra.
- Pass `jws.WithInferAlgorithmFromKey(true)` to `jwt.WithKeySet` while
preserving issuer, audience, skew, kid, and signature validation.
- Add regression coverage for a JWKS key with `kid` but no `alg`.
## Jira
- DSPX-3172
## Testing
- `~/go/bin/gofumpt -w service/internal/auth/token_verifier.go
service/internal/auth/token_verifier_test.go`
- `cd service && go test ./internal/auth -run
'TestTokenVerifier|TestNewTokenVerifier' -v`
- `cd service && go test ./internal/auth`
- `cd service && golangci-lint run --new ./internal/auth`
## Known Existing Failures
- `cd service && golangci-lint run ./internal/auth` fails on
pre-existing unused `//nolint` directives in `authn.go`.
- `make test` fails in `lib/fixtures` on `TestTokenManager_InitialLogin`
and `TestTokenManager_CustomTokenBuffer`, unrelated to this auth
verifier change.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* JWT verification now infers the signing algorithm from the
verification key, allowing token authentication to succeed when JWKS
keys omit an explicit algorithm, improving robustness and
interoperability.
* **Tests**
* Added coverage for tokens validated against JWKS entries that do not
include an alg field.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: strantalis <strantalis@virtru.com>1 parent aa23179 commit 83285e7
2 files changed
Lines changed: 42 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | | - | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
28 | 44 | | |
29 | 45 | | |
30 | 46 | | |
| |||
33 | 49 | | |
34 | 50 | | |
35 | 51 | | |
36 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
37 | 58 | | |
38 | 59 | | |
39 | 60 | | |
| |||
149 | 170 | | |
150 | 171 | | |
151 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
152 | 191 | | |
153 | 192 | | |
154 | 193 | | |
| |||
0 commit comments