Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds audience validation when validating a jwt #87

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

ctran88
Copy link
Contributor

@ctran88 ctran88 commented Dec 5, 2024

What's New?

  • Adds 24 hour expiry time for JWKS cache
  • Adds aud claim validation when validating a JWT

Screenshots (if appropriate):

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have manually tested my code thoroughly
  • I have added/updated inline documentation for public facing interfaces if relevant
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing integration and unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional context

@ctran88 ctran88 force-pushed the PSG-4850-validate-aud-claims branch from e56773f to ad21f9b Compare December 5, 2024 22:15
throw new InvalidArgumentException('Missing kid in token');
$decodedToken = JWT::decode($jwt, $this->jwks);

$aud = (array) $decodedToken->aud;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not array, turn into array

Comment on lines -55 to -62
$jwtSegments = explode('.', $jwt);
if (count($jwtSegments) !== 3) {
throw new InvalidArgumentException('Invalid JWT format');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already checked by JWT::decode here

if (!$header->kid) {
throw new InvalidArgumentException('Missing kid in token');
if (!in_array($expectedAud, $aud)) {
throw new UnexpectedValueException('JWT audience does not match');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already checked by JWT::decode here, here, and here

@ctran88 ctran88 force-pushed the PSG-5155-add-new-method-signatures branch from ced84c7 to 87ce425 Compare December 6, 2024 17:34
Base automatically changed from PSG-5155-add-new-method-signatures to main December 6, 2024 17:50
$decodedToken = JWT::decode($jwt, $this->jwks);

$aud = (array) $decodedToken->aud;
$expectedAud = $this->app->getHosted() ? $this->appId : $this->app->getAuthOrigin();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the note in passageidentity/passage-go#89 (comment), the app ID audience claim change is live for all apps in production, so this conditional can be simplified.

@ctran88 ctran88 force-pushed the PSG-4850-validate-aud-claims branch from c0795cb to f722ca7 Compare December 10, 2024 22:58
@ctran88 ctran88 requested a review from bertrmz December 10, 2024 22:58
@ctran88 ctran88 merged commit 1700bce into main Dec 10, 2024
4 checks passed
@ctran88 ctran88 deleted the PSG-4850-validate-aud-claims branch December 10, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants