Commit 079e2d2
authored
🐛 Enforce HS256-only JWT parsing via shared parser with WithValidMethods (#4356)
All JWT parsing now goes through middleware.ParseJWT() which uses a shared
jwt.Parser configured with jwt.WithValidMethods([]string{"HS256"}).
Previously, ParseWithClaims was called without algorithm restriction — the
library's default accepts any signing method. This could theoretically
allow algorithm confusion attacks (e.g., HS384, RS256-with-HMAC-key).
Defense-in-depth: the keyfunc also explicitly checks token.Method is
*jwt.SigningMethodHMAC before returning the secret.
Four call sites consolidated:
- JWTAuth middleware (HTTP API)
- ValidateJWT (WebSocket/exec)
- RefreshToken handler
- Logout handler
Signed-off-by: Andrew Anderson <andy@clubanderson.com>1 parent 08edb2d commit 079e2d2
2 files changed
+24
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
464 | | - | |
465 | | - | |
| 463 | + | |
466 | 464 | | |
467 | 465 | | |
468 | 466 | | |
| |||
511 | 509 | | |
512 | 510 | | |
513 | 511 | | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
| 512 | + | |
518 | 513 | | |
519 | 514 | | |
520 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
32 | 52 | | |
33 | 53 | | |
34 | 54 | | |
| |||
184 | 204 | | |
185 | 205 | | |
186 | 206 | | |
187 | | - | |
188 | | - | |
189 | | - | |
| 207 | + | |
190 | 208 | | |
191 | 209 | | |
192 | 210 | | |
| |||
265 | 283 | | |
266 | 284 | | |
267 | 285 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 286 | + | |
271 | 287 | | |
272 | 288 | | |
273 | 289 | | |
| |||
0 commit comments