Commit 1ae23be
committed
fix(apple): validate id_token iss and aud on Sign in with Apple
After ParseWithClaims succeeded the Apple handler accepted any token Apple
had signed, regardless of which Sign-in-with-Apple client it was issued
to. The relying party MUST verify iss == https://appleid.apple.com and
aud == ClientID per Apple's spec; we did neither, which let an
attacker-controlled Sign-in-with-Apple client (or a sibling service in
the same Apple developer team) substitute its own id_token and
authenticate as the foreign sub.
Add validateAppleIDClaims helper, run it after ParseWithClaims, return
403 with "invalid id_token" on rejection. Same fix applied to v1
(github.com/golang-jwt/jwt v3.2.2 API: VerifyIssuer/VerifyAudience) and
v2 (jwt v5 API: GetIssuer/GetAudience), single PR.
Update the test fixture createTestResponseToken to use realistic iss/aud
so existing happy-path integration tests keep passing.
Tests:
* TestValidateAppleIDClaims -- table-driven coverage of the helper:
wrong-iss, missing-iss, wrong-aud, missing-aud rejection (and
audience-as-list match for v2).
* TestAppleHandler_LoginHandler_RejectsWrongIssuer -- integration
regression test at the handler boundary. Drives the full exchange
flow with a token signed by the test JWK but iss = attacker.example.com.
With the fix in place the handler returns 403 invalid id_token; if
the validateAppleIDClaims call site is reverted the foreign-iss
token authenticates (200 with a JWT) and this test fails on the
status-code assertion. The unit-level helper test alone wouldn't
catch a missing call.
prepareAppleOauthTest gains an explicit testIDTokenOverride parameter
so the regression test can inject its own iss/aud while existing
callers keep their defaults.1 parent e5f47f5 commit 1ae23be
5 files changed
Lines changed: 270 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
783 | 792 | | |
784 | 793 | | |
785 | 794 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
354 | 355 | | |
355 | 356 | | |
356 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
357 | 364 | | |
358 | 365 | | |
359 | 366 | | |
| |||
568 | 575 | | |
569 | 576 | | |
570 | 577 | | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
180 | 225 | | |
181 | 226 | | |
182 | 227 | | |
| |||
327 | 372 | | |
328 | 373 | | |
329 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
330 | 416 | | |
331 | | - | |
332 | | - | |
| 417 | + | |
333 | 418 | | |
334 | 419 | | |
335 | 420 | | |
336 | 421 | | |
337 | | - | |
| 422 | + | |
338 | 423 | | |
339 | 424 | | |
340 | 425 | | |
| |||
488 | 573 | | |
489 | 574 | | |
490 | 575 | | |
491 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
492 | 595 | | |
493 | 596 | | |
494 | 597 | | |
| |||
511 | 614 | | |
512 | 615 | | |
513 | 616 | | |
514 | | - | |
| 617 | + | |
515 | 618 | | |
516 | 619 | | |
517 | 620 | | |
| |||
535 | 638 | | |
536 | 639 | | |
537 | 640 | | |
538 | | - | |
| 641 | + | |
539 | 642 | | |
540 | 643 | | |
541 | 644 | | |
| |||
647 | 750 | | |
648 | 751 | | |
649 | 752 | | |
650 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
651 | 777 | | |
652 | | - | |
| 778 | + | |
653 | 779 | | |
654 | 780 | | |
655 | | - | |
| 781 | + | |
656 | 782 | | |
657 | 783 | | |
658 | 784 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
345 | 346 | | |
346 | 347 | | |
347 | 348 | | |
348 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
349 | 352 | | |
350 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
351 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
352 | 365 | | |
353 | 366 | | |
354 | 367 | | |
| |||
568 | 581 | | |
569 | 582 | | |
570 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
0 commit comments