Skip to content

Edge function gateway rejects valid ES256 JWT on branch environments #41691

Closed as not planned

Description

@listen3000

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Edge functions with verify_jwt = true on branch environments (created via GitHub integration) reject valid ES256 JWTs with {"code":401,"message":"Invalid JWT"}, even though the same JWT is successfully validated by the branch's auth service at /auth/v1/user.

The parent project uses the legacy JWT secret system (see Signing Keys docs), but the branch environment's auth service issues tokens signed with asymmetric keys (ES256). The JWT is correctly issued by the branch's auth service (issuer matches branch URL), is not expired, and the auth service accepts it. However, the edge function gateway rejects it at the request level before the function code executes.

This suggests the edge function gateway on branch environments inherits the legacy JWT secret configuration from the parent project, but the branch's auth service uses the new asymmetric signing keys system (ES256).

To Reproduce

  1. Set up GitHub integration for automatic branch creation on PRs
  2. Create a PR to trigger a Supabase branch environment
  3. Wait for branch to reach ACTIVE_HEALTHY status with MIGRATIONS_PASSED
  4. Authenticate against the branch environment to get an access token
  5. Call an edge function that has verify_jwt = true in config.toml
# Step 1: Verify JWT is valid with auth service (this succeeds):
curl 'https://<branch-ref>.supabase.co/auth/v1/user' \
  -H 'apikey: <branch-anon-key>' \
  -H 'authorization: Bearer <access-token>'
# Returns: user object with id, email, etc.

# Step 2: Call edge function with same JWT (this fails):
curl 'https://<branch-ref>.supabase.co/functions/v1/<function-name>' \
  -H 'apikey: <branch-anon-key>' \
  -H 'authorization: Bearer <access-token>' \
  -H 'content-type: application/json' \
  -d '{}'
# Returns: {"code":401,"message":"Invalid JWT"}

The JWT header shows ES256 algorithm:

{"alg":"ES256","kid":"<key-id>","typ":"JWT"}

Expected behavior

The edge function gateway should accept JWTs that are valid according to the branch's auth service. Both are part of the same branch environment and should share JWT verification keys.

Screenshots

N/A

System information

  • OS: macOS
  • Version of supabase-js: 2.x
  • Version of Node.js: 22.x
  • Supabase CLI: latest
  • Branch creation method: GitHub integration (automatic on PR)

Additional context

Workaround: Deploy edge functions with --no-verify-jwt and handle authentication manually in the function code:
Auth service misalignment: The production/main project's auth service returns HS256 signed token on /auth/v1/token?grant_type=password and a fresh branch project returns ES256 signed token.
Verify JWT with legacy secret: OFF

Activity

  1. added
    bug
    on Jan 3, 2026
  2. coderabbitai commented on Jan 3, 2026

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Possible Duplicates

    Related Issues

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  3. added
    external-issue
    on Jan 3, 2026
  4. listen3000 commented on Jan 3, 2026

    @listen3000
    Author

    I found the following recommendation in the “Rotate JWT signing key” popup:

    Recommendation: Change all of your Edge Functions to no longer rely on gateway-level JWT verification, and instead implement JWT verification inside the function code itself using the Supabase client library or another JWT library.

    Image

    Let me clarify whether I understand Supabase’s perspective correctly.

    Branch environments are treated as new projects, meaning they will always use the new JWT signing setup, and the Edge Functions Gateway does not support this new JWT signing setup.

    Is this an accurate assessment?

  5. kallebysantos commented on Jan 4, 2026

    @kallebysantos
    Member

    🎉 Happy new year!! @listen3000

    Please, check my comment about the incoming changes for verify_jwt

  6. self-assigned this
    on Jan 4, 2026
  7. listen3000 commented on Jan 4, 2026

    @listen3000
    Author

    Thanks for the quick reply. All clear now. I'm closing.

    And Happy New Year to you as well. 🎇🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugexternal-issueto-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions