Rule request: detect Supabase `service_role` JWTs (distinct from safe `anon` keys)
Author: MohamedQiqaCreated Sep 19, 2026Updated Sep 19, 2026
Related issue
This overlaps with #2225 (opened July 2026, no replies yet). Our issue adds tested regexes and exact evidence that issue lacks.
Problem
Supabase issues two JWTs per project:
anon— public, safe to ship in a browserservice_role— full database access, must be secret
The stock jwt rule matches both. This means:
- Users get a false alarm on the public
anonkey (noisy) - Or they disable the
jwtrule entirely — and lose detection of the dangerousservice_rolekey
We verified this by running the current regex against a real key of each type.
The fix
The JWT payload carries a role claim that separates them cleanly:
anonkey payload:"role":"anon"service_rolekey payload:"role":"service_role"
With --max-decode-depth already in Gitleaks, a rule matching "role":"service_role" works today without any new machinery.
Important caveat
Such a rule must not carry a keywords filter. The words service_role only exist after base64 decoding — a keyword pre-filter would stop the rule from ever running.
Evidence
- Confirmed with real (revoked) keys of both types
anonkey → should NOT match the new rule (false positive to avoid)service_rolekey → should match (true positive)
We are preparing a PR with a Go rule file implementing this.
Source: gitleaks/gitleaks