fix: validate JWT audience and issuer claims#41
Open
alanzabihi wants to merge 1 commit intosupabase:mainfrom
Open
fix: validate JWT audience and issuer claims#41alanzabihi wants to merge 1 commit intosupabase:mainfrom
alanzabihi wants to merge 1 commit intosupabase:mainfrom
Conversation
jwtVerify was called without audience or issuer options, so any JWT signed by a key in the JWKS was accepted regardless of who issued it or who it was intended for. In setups where multiple services share signing keys, a token from one service would pass verification on another. Add optional SUPABASE_JWT_AUDIENCE and SUPABASE_JWT_ISSUER env vars. When set, they are forwarded to jose's jwtVerify options. Existing behavior is unchanged when they are not set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
jwtVerifyinverify-credentials.tsis called withoutaudienceorissueroptions:Any JWT signed by a key in the project's JWKS is accepted, regardless of who issued it or who it was intended for. In setups where multiple services share signing keys (common in self-hosted Supabase), a token minted by Service A is accepted by Service B as valid user auth.
What is the new behavior?
Two new optional fields on
SupabaseEnv:audienceandissuer. When set, they're forwarded tojwtVerify's options. Tokens that don't match are rejected withInvalidCredentialsError.New environment variables:
SUPABASE_JWT_AUDIENCEandSUPABASE_JWT_ISSUER. Both are optional. Existing behavior is unchanged when they aren't set.Files changed:
src/types.ts-- addaudience?andissuer?toSupabaseEnvsrc/core/resolve-env.ts-- read the new env varssrc/core/verify-credentials.ts-- pass them tojwtVerifydocs/security.md-- document the new options and why they matterdocs/environment-variables.md-- list the new varsTests:
The actual logic this PR adds is: "if the env field is set, pass it to
jose." The claim validation itself happens insidejose. Every existingusermode test already callsmakeEnv()without audience or issuer, so the backward-compatible path is implicitly covered.The one test worth adding is a
resolveEnvwiring test: does it correctly readSUPABASE_JWT_AUDIENCEandSUPABASE_JWT_ISSUERfrom the environment and surface them onSupabaseEnv? Happy to add that if you'd like.