FixVibe

// docs / baas security / supabase service role exposure

Supabase service role key JavaScript માં ઉજાગર: તેનો અર્થ શું છે અને તેને કેવી રીતે શોધવી

Supabase service role key તમારા database ની master key છે. તેને ધારણ કરનાર કોઈપણ Row-Level Security ને bypass કરે છે, દરેક table ના દરેક column ને વાંચી શકે છે, અને કંઈપણ લખી અથવા delete કરી શકે છે. તે ફક્ત server-side code માં રહેવા માટે રચાયેલી છે — ક્યારેય browser માં નહીં. જ્યારે AI કોડિંગ ટૂલ તેને JavaScript bundle માં ship કરે છે, ત્યારે તમારું database, અસરમાં, public છે. આ લેખ leak થયેલી key ને ઓળખતો JWT shape, leak ઉત્પન્ન કરતા ત્રણ AI-ટૂલ patterns, detection પછી પ્રથમ કલાકમાં શું કરવું, અને વપરાશકર્તાઓ પહેલા તેને automatically scan કરવા તે સમજાવે છે.

Service role key શું છે

Supabase દરેક project માટે બે અલગ keys ઈશ્યુ કરે છે: anon key (નવા projects માં publishable key પણ કહેવાય છે) અને service_role key. બંને તમારા project ની JWT secret દ્વારા signed JSON Web Tokens છે. તફાવત JWT payload માં બેક કરેલા role claim નો છે — public key માટે anon, master key માટે service_role. PostgREST, Supabase Storage, અને Supabase Auth બધા જ્યારે service_role claim જુએ ત્યારે bypass-everything mode માં બદલાય છે.

કોઈપણ Supabase key ને jwt.io પર decode કરો અને payload જુઓ. Service-role JWT નો shape અસ્પષ્ટ નથી:

Service-role JWT ની decoded payload (નીચે syntax-highlighted block તરીકે બતાવેલ).

json
{
  "iss": "supabase",
  "ref": "[project-ref]",
  "role": "service_role",
  "iat": 1700000000,
  "exp": 2000000000
}

નવા Supabase projects JWT ને બદલે sb_secret_ prefix સાથે secret-style keys ઈશ્યુ કરે છે. વર્તન સમાન છે — public bundle માં sb_secret_ ધરાવતું કંઈપણ સમાન રીતે વિનાશક છે.

AI કોડિંગ ટૂલ service role key કેવી રીતે leak કરે છે

અમે હજારો vibe-coded apps માં એ જ ત્રણ patterns જોયા છે. દરેક developer ના AI ટૂલ ને મદદ માટે પૂછવાથી શરૂ થાય છે અને service key bundle માં inlined થવા સાથે સમાપ્ત થાય છે.

Pattern 1: NEXT_PUBLIC_ prefix સાથે એક જ .env file

Developer AI ટૂલ ને "Supabase set up કરો" પૂછે છે અને બંને keys સાથે એક .env સ્વીકારે છે. AI ટૂલ — એક corpus પર trained જ્યાં મોટાભાગના environment variables NEXT_PUBLIC_* દ્વારા expose થાય છે — બંને ને NEXT_PUBLIC_ prefix કરે છે. Next.js એ prefix સાથે મેળ ખાતી કોઈપણ વસ્તુ ને build time પર client bundle માં inline કરે છે. Vercel પર ship કરો, અને service key main.[hash].js માં છે.

Pattern 2: createClient call માં ખોટી key

Developer AI દ્વારા generated config.ts file માં બંને keys paste કરે છે, અને AI browser-side createClient() call ને ભૂલથી process.env.SUPABASE_SERVICE_ROLE_KEY સાથે populate કરે છે. Build variable ને pull કરે છે, અને JWT bundle માં લેન્ડ થાય છે.

Pattern 3: Service-role key seed scripts માં hardcoded

Developer AI ટૂલ ને એક script લખવા પૂછે છે જે database ને seed કરે છે. AI service-role key ને file માં સીધી hardcode કરે છે (environment માંથી વાંચવાને બદલે), file ને repository માં commit કરે છે, અને public GitHub repo અથવા deployed app નો /scripts/seed.js route હવે key serve કરી રહ્યો છે.

FixVibe bundle scan leak ને કેવી રીતે detect કરે છે

FixVibe ની bundle-secrets check deployed app દ્વારા referenced દરેક JavaScript file download કરે છે — entry chunks, lazy-loaded chunks, web workers, service workers — અને તેમને એક detector મારફતે ચલાવે છે જે JWT shape (eyJ[base64-header].eyJ[base64-payload].[signature]) સાથે મેળ ખાતી કોઈપણ વસ્તુ ને decode કરે છે. જો decoded payload માં "role": "service_role" હોય, તો scan તેને file path અને key જ્યાં દેખાય તે ચોક્કસ line સાથે critical finding તરીકે report કરે છે. એ જ check નવા sb_secret_* pattern સાથે prefix દ્વારા પણ મેળ ખાય છે.

Scan ક્યારેય discovered key સાથે authenticate નથી થતું. તે shape ઓળખે છે અને leak report કરે છે — exploitability સાબિત કરવા key નો ઉપયોગ કરવો એ તમારા database ની અનધિકૃત access હશે. પુરાવો JWT payload માં જ છે.

Detect થયું — પ્રથમ કલાકમાં શું કરવું

Leak થયેલી service role key એક runtime કટોકટી છે. ધારો કે key scrape કરી લેવામાં આવી છે — હુમલાખોરો real time માં public bundles ને monitor કરે છે. જ્યાં સુધી તમે key ને rotate કરી લો અને તાજેતરની activity નું audit કરી લો ત્યાં સુધી database ને compromise થયેલું ગણો.

  1. Key ને તરત rotate કરો. Supabase Dashboard માં, Project Settings → API → Service role key → Reset પર જાઓ. જૂની key સેકન્ડ્સ ની અંદર invalidate થાય છે. Key નો ઉપયોગ કરતો કોઈપણ service-side code rotation લેન્ડ થાય તે પહેલા update અને redeployed થવો જોઈએ.
  2. તાજેતરની database activity નું audit કરો. Dashboard માં Database → Logs ખોલો. છેલ્લા 7 દિવસ પર filter કરો. PII ધરાવતી tables સામે અસામાન્ય SELECT * queries, મોટા UPDATE અથવા DELETE statements, અને તમારી જાણીતી infrastructure ની બહારના IPs માંથી requests શોધો. Supabase દરેક request પર x-real-ip header log કરે છે.
  3. Storage objects check કરો. Storage → Logs ની મુલાકાત લો અને તાજેતરના file downloads ની સમીક્ષા કરો. Leak થયેલી service-role key private buckets ને પણ bypass-everything access આપે છે.
  4. Source control માંથી key દૂર કરો. Rotation પછી પણ, તમારી git history માં JWT છોડવાનો અર્થ છે કે તે public repo માં discoverable છે. History માંથી તેને scrub કરવા માટે git filter-repo અથવા BFG Repo-Cleaner નો ઉપયોગ કરો, પછી force-push કરો (પ્રથમ collaborators ને ચેતવણી આપો).
  5. Fix પછી ફરી scan કરો. Redeployed app સામે તાજો FixVibe scan ચલાવો. Bundle-secrets finding clear થવી જોઈએ. Confirm કરો કે કોઈ chunk માં service_role JWT અને કોઈ sb_secret_* string બાકી નથી.

પ્રથમ સ્થાને leak ને રોકવો

Structural fix નામકરણ શિસ્ત વત્તા ટૂલ-લેવલ guardrails છે:

  • Service key ને ક્યારેય NEXT_PUBLIC_*, VITE_*, અથવા કોઈ બીજા bundle-inlining prefix સાથે prefix ન કરો. નામકરણ સંમેલન સીમા છે — દરેક framework તેને માન આપે છે.
  • Developer machine પર .env માંથી service key ને સંપૂર્ણપણે બહાર રાખો. Deploy પર secret manager (Doppler, Infisical, Vercel encrypted env vars) માંથી તેને વાંચો, ક્યારેય locally commit ન કરો.
  • <strong>Mark every Supabase client construction with explicit context.</strong> Files named <code>supabase/browser.ts</code> use the anon key; files named <code>supabase/server.ts</code> use the service-role key with <code>import 'server-only'</code> at the top. The <code>server-only</code> import causes a build error if a client component tries to consume the module.
  • <strong>Add a pre-commit hook that greps for JWT-shaped strings.</strong> <code>git diff --staged | grep -E 'eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+'</code> catches both anon and service tokens before they leave your machine.
  • એક CI gate ઉમેરો જે build output ને scan કરે. next build પછી, .next/static/chunks/ output માં service_role string માટે grep કરો. જો કંઈ મેળ ખાય તો build fail કરો.
bash
# Pre-commit hook: refuse any staged JWT-shaped string.
git diff --staged \
  | grep -E 'eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+' \
  && echo "JWT detected in staged changes — refusing commit" \
  && exit 1

# CI gate: fail the build if "service_role" shipped to the static bundle.
grep -RE 'service_role|sb_secret_' .next/static/chunks/ \
  && echo "Service-role credential leaked into bundle" \
  && exit 1

વારંવાર પૂછાતા પ્રશ્નો

Leak થયેલી Supabase service-role keys ને હુમલાખોરો કેટલી ઝડપથી શોધે છે?

Public-bundle scanners મિનિટોમાં નવા deployments trawl કરે છે. Researchers એ first deploy થી એક કલાક કરતા ઓછા સમયમાં નવા Supabase projects સામે working exploits દસ્તાવેજિત કર્યા છે. કોઈપણ service-role exposure ને 60-minute window તરીકે ગણો, 60-દિવસ ની નહીં.

શું key rotate કરવી પૂરતી છે, અથવા મારે data exfiltration ધારવી પડશે?

Rotation leak થયેલી key ને invalidate કરે છે પણ પહેલેથી pull કરેલા data ને undo નથી કરતું. જો તમારી tables માં PII, payment data, અથવા કોઈ regulated data હોય, તો તમારી પાસે GDPR (72 hours), CCPA, અથવા HIPAA હેઠળ notification ની જવાબદારી હોઈ શકે છે. Logs નું audit કરો અને જો audit શંકાસ્પદ access બતાવે તો legal counsel ની સલાહ લો.

જો service-role key leak થાય તો શું RLS મને protect કરી શકે છે?

ના. Row-Level Security service_role claim દ્વારા સંપૂર્ણપણે bypass થાય છે. તે ડિઝાઇન દ્વારા છે — key ચોક્કસપણે backend code ને admin operations માટે RLS skip કરવાની મંજૂરી આપવા માટે અસ્તિત્વમાં છે. Mitigation એ સુનિશ્ચિત કરવાનું છે કે key ક્યારેય એવા context માં ન પહોંચે જ્યાં હુમલાખોર તેને વાંચી શકે.

શું આ નવા Supabase publishable / secret key model (<code>sb_publishable_</code> / <code>sb_secret_</code>) પર લાગુ પડે છે?

હા — સમાન risk class. sb_secret_* key નવો secret-key format છે જે નવા projects માટે service-role JWT ને replace કરે છે. Bundle માં sb_secret_* ધરાવતું કંઈપણ leak થયેલા service-role JWT જેટલું જ વિનાશક છે. FixVibe ની bundle-secrets detector બંને shapes સાથે મેળ ખાય છે.

Anon / publishable key વિશે શું — શું તે bundle માં સુરક્ષિત છે?

હા, ડિઝાઇન દ્વારા. Anon key browser માં રહેવાનો હેતુ ધરાવે છે અને દરેક Supabase web client તેનો ઉપયોગ કરે છે. તેની સલામતી દરેક public table પર RLS ને યોગ્ય રીતે કોન્ફિગર કરવા પર સંપૂર્ણપણે આધારિત છે. શું check કરવું તે માટે Supabase RLS scanner લેખ જુઓ.

આગળના પગલાં

તમારા production URL સામે FixVibe scan ચલાવો — bundle-secrets check મફત છે, કોઈ signup નહીં, અને એક મિનિટ કરતા ઓછા સમયમાં service_role exposure report કરે છે. RLS layer કામ કરી રહ્યું છે કે કેમ તે verify કરવા આને Supabase RLS scanner લેખ સાથે અને file access ને lock down કરવા Supabase storage bucket security checklist સાથે pair કરો. AI ટૂલ આ leak class ને આટલી વિશ્વસનીય રીતે કેમ generate કરે છે તેની background માટે, AI કોડિંગ ટૂલ security gaps કેમ છોડે છે વાંચો.

// તમારી baas સપાટી scan કરો

બીજા કોઈ પહેલા ખુલ્લી table શોધો.

એક production URL ઉમેરો. FixVibe એ BaaS providers ની ગણતરી કરે છે જેની સાથે તમારી app વાત કરે છે, તેમના public endpoints નું fingerprint લે છે, અને જણાવે છે કે એક unauthenticated client શું વાંચી અથવા લખી શકે છે. મફત, કોઈ install નહીં, કોઈ કાર્ડ નહીં.

  • મફત tier — 3 scans / મહિને, signup માટે કાર્ડની જરૂર નથી.
  • Passive BaaS fingerprinting — domain verification ની જરૂર નથી.
  • Supabase, Firebase, Clerk, Auth0, Appwrite અને વધુ.
  • દરેક finding પર AI fix prompts — Cursor / Claude Code માં paste કરો.
મફત BaaS scan ચલાવો

signup ની જરૂર નથી

Supabase service role key JavaScript માં ઉજાગર: તેનો અર્થ શું છે અને તેને કેવી રીતે શોધવી — Docs · FixVibe