Commit 207ed5f
fix(auth): fix getClaims() crash with asymmetric JWTs on first call (#1300)
Fixed a crash in getClaims() that occurred when verifying JWTs signed
with asymmetric algorithms (RS256, ES256) on the first call.
The issue was that _jwks was force-unwrapped (_jwks!) before it was
initialized. On the first call to getClaims() with an asymmetric JWT
containing a 'kid' header, _jwks would be null, causing a null check
operator error.
The fix passes an empty JWKSet when the cache is null:
_jwks ?? JWKSet(keys: []). This allows _fetchJwk() to handle the first
call gracefully by fetching from the server and populating the cache.
Changes:
- Updated getClaims() to use null-coalescing operator instead of force-unwrap
- Added test case to reproduce and verify the fix for SDK-627
- Enhanced documentation to clarify JWKS caching behavior for asymmetric JWTs
Linear: SDK-627
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 0719e55 commit 207ed5f
File tree
2 files changed
+54
-1
lines changed- packages/gotrue
- lib/src
- test
2 files changed
+54
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1397 | 1397 | | |
1398 | 1398 | | |
1399 | 1399 | | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
1400 | 1405 | | |
1401 | 1406 | | |
1402 | 1407 | | |
| |||
1428 | 1433 | | |
1429 | 1434 | | |
1430 | 1435 | | |
1431 | | - | |
| 1436 | + | |
1432 | 1437 | | |
1433 | 1438 | | |
1434 | 1439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
210 | 258 | | |
211 | 259 | | |
212 | 260 | | |
| |||
0 commit comments