feat(jwt): add optional requireAudience to verifyJwt#130
Conversation
|
Warning Review limit reached
Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Walkthrough
ChangesJWT audience requirement
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/jwt/src/verify.test.ts (1)
160-193: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for an empty-string audience.
The contract includes
aud: "", but these tests cover onlyaud: []and a missing claim. Add a case that verifiesrequireAudience: truerejects the empty string branch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/jwt/src/verify.test.ts` around lines 160 - 193, Add a test alongside the existing empty-array case in the verifyJwt tests, using a mock verified payload with aud set to an empty string and requireAudience enabled. Assert that verifyJwt rejects with the existing “JWT audience is required but missing” error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/jwt/src/verify.test.ts`:
- Around line 149-156: Update the verifyJWT invocation assertions in this test
to inspect this test’s call rather than a prior suite call: clear the mock
history in beforeEach or reference the latest mock call before asserting
requireAudience is absent. Preserve the existing audience assertion.
---
Nitpick comments:
In `@packages/jwt/src/verify.test.ts`:
- Around line 160-193: Add a test alongside the existing empty-array case in the
verifyJwt tests, using a mock verified payload with aud set to an empty string
and requireAudience enabled. Assert that verifyJwt rejects with the existing
“JWT audience is required but missing” error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d341f587-2a22-4760-bf48-e95f555af5fe
📒 Files selected for processing (3)
.changeset/jwt-require-audience.mdpackages/jwt/src/verify.test.tspackages/jwt/src/verify.ts
b6875fa to
ea70b1f
Compare
|
@venables a review when convenient would be great. Companion to #129: an opt-in |
What
Adds an optional
requireAudiencetoverifyJwt. When true, a verified tokenwhose
audclaim is absent or empty (empty string,[],[""]) is rejected.Why
did-jwt'sverifyJWTonly runs its audience match when the token carries anaudclaim. So a token that omitsaudverifies even when the caller suppliesan
audience.verifyJwtalready layers anissuerpost-check on top ofdid-jwt; this adds an opt-in audience-presence check in the same shape, so a
caller that supplies
audiencecan also require the claim to exist.This gap is live in this repo:
packages/ack-id/src/a2a/verify.tscallsverifyJwt(jwt, { audience: did, ... })with a comment that the message is"intended for the provided DID", yet an aud-less token verifies there today.
I have kept this PR to the
jwtpackage alone; wiringrequireAudience: trueinto the ack-id A2A verifiers is a natural follow-up but is a behavior change
in another package, so I would rather agree the direction first.
Design note (happy to adjust)
The opt-in boolean is the conservative, non-breaking choice. An alternative is
to infer the requirement whenever an
audienceis supplied (jose-style), whichwould be a behavior change. Glad to open this as an issue first and take
whichever shape you prefer.
Change
requireAudience?: booleanonVerifyJwtOptionshasAudiencehelper (non-empty string or array with a non-emptyentry) so empty audiences do not slip through
Tests
verify.test.ts: the realistic path ({ audience, requireAudience: true },asserting
audienceis forwarded andrequireAudienceis not), plusmissing-aud and empty-array rejection.
pnpm --filter @agentcommercekit/jwt test-> 21 passing. Changeset included (minor).AI assistance disclosure
Per the repository AI policy: implemented and tested by gpt 5.6-sol and fable 5, then reviewed and understood by me. I can explain the implementation and its trade-offs without AI aid. Tests, typecheck, and formatting pass locally against the package suite.
Summary by CodeRabbit
New Features
requireAudiencesetting for JWT verification.Bug Fixes