Skip to content

feat: validate jwt audience and issuer - #160

Open
mandar1045 wants to merge 1 commit into
supabase:mainfrom
mandar1045:fix/validate-jwt-audience-issuer
Open

mandar1045 wants to merge 1 commit into
supabase:mainfrom
mandar1045:fix/validate-jwt-audience-issuer

Conversation

@mandar1045

Copy link
Copy Markdown

TL;DR

Validate the JWT aud and iss claims during user token verification through config overrides.

Problem

Token verification currently doesn't validate the audience or issuer claims. This means a valid token issued for one service could potentially be accepted by another service.

Solution

Adds optional audience and issuer config overrides to verifyCredentials, withClaims, and withRequiredClaims.

This works with both symmetric and asymmetric keys, and doesn't read from any reserved environment variables.

Ref

@mandar1045
mandar1045 requested review from a team as code owners September 12, 2026 18:23
Comment thread src/core/resolve-env.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Sep 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@supabase/server@160

commit: 45b2e8b

@mandarini mandarini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for picking this up and for moving the options off resolveEnv. The logic is right and every call site gets the options. Three small changes before merge.

  • Drop | null from the new field types and pass the options straight to jwtVerify (or guard with !== undefined). With the current truthiness check, an empty string turns validation off with no warning and an empty array rejects every token.
  • Fix the example in docs/security.md. Supabase Auth sets aud to authenticated and iss to https://<ref>.supabase.co/auth/v1, so audience: 'my-service' would reject every Supabase token. Use issuer: fromSupabaseUrl(SUPABASE_URL) as the example and point to withRequiredClaims rather than withClaims, since withClaims lets requests with no token through.
  • Add a one-line JSDoc to each new field, matching the fields around them. Mention that they apply to user mode only.

On your question about grouping: top level is fine. It matches where jwks sits on withClaims.

@mandar1045
mandar1045 force-pushed the fix/validate-jwt-audience-issuer branch from 37e7297 to 383648e Compare September 15, 2026 15:58
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