Repository navigation
Accept the auth server issuer in edge function JWT verification - #375
Open
thomasbergernz wants to merge 1 commit into
Open
thomasbergernz wants to merge 1 commit into
thomasbergernz wants to merge 1 commit into
Conversation
Edge functions verify user tokens against SB_JWT_ISSUER, which supabase/functions/.env sets to http://127.0.0.1:54321/auth/v1. When the local stack is served under another URL (auth.external_url, e.g. behind a reverse proxy), the auth server issues tokens with that public URL as "iss", so AuthMiddleware rejects every request with unexpected iss claim value and user management fails. Also accept the issuer advertised by the auth server itself (/auth/v1/.well-known/openid-configuration). The signature is still checked against the project JWKS. Discovery is cached, and retried on the next request if the auth server could not be reached.
This branch has not been deployed
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.
Problem
Edge functions that use
AuthMiddleware(users,merge_contacts,delete_note_attachments,update_password) verify the user's JWT against a single issuer:SB_JWT_ISSUER, orSUPABASE_URL/auth/v1when it is unset.supabase/functions/.envsets it tohttp://127.0.0.1:54321/auth/v1.When the local Supabase stack is reached through another URL, the auth server signs tokens with that public URL as
iss. This happens when[auth] external_url/API_EXTERNAL_URLis set, for example behind a reverse proxy or tunnel. Every request then fails with401 JWTClaimValidationFailed: unexpected "iss" claim value, so managing users from the Settings page fails.Solution
Also accept the issuer that the auth server advertises in
/auth/v1/.well-known/openid-configuration. Only the acceptedissvalues change:The logic lives in a small helper (
_shared/jwtIssuer.ts) with unit tests.This doesn't touch the MCP function, which #373 rewrites.
How To Test
supabase/config.toml, set[auth] external_urlto a URL other thanhttp://127.0.0.1:54321/auth/v1, and serve the stack through it.make start, log in, then edit a user in Settings → Users (PATCH /functions/v1/users).401 unexpected "iss" claim value. After it, the request succeeds.Unit tests:
npm run test:unit:functions -- supabase/functions/_shared.I also checked the helper against a running auth server with a public
external_url. A token with the public issuer is rejected with the current configured issuer and accepted with the new list.Additional Checks