अगर आपने Claude या Cursor के साथ कोई ऐप बनाया है और अब इसे किसी भुगतान करने वाले क्लाइंट को देने वाले हैं, तो रुकिए। AI-generated कोड में सुरक्षा की समस्याएं होती हैं — खुला हुआ API keys, input validation नहीं, डेटाबेस permissions जो किसी भी यूजर को दूसरे के डेटा देख सकते हैं। ये edge cases नहीं हैं। लगभग हर पहले draft के AI-generated codebase में ये होते हैं।

यह गाइड launch से पहले की सुरक्षा checklist है। किसी भी असली यूजर को आपका ऐप देने से पहले इसे step by step फॉलो करें। यह सबसे common vibe coding stack के लिए लिखा गया है (Next.js + Supabase + Vercel), लेकिन ये सिद्धांत किसी भी tool के लिए काम करते हैं।

Quick Facts
पूरा करने का समय
एक typical ऐप के लिए 2–4 घंटे
कौशल required
कोई सुरक्षा background नहीं — step-by-step checklist
Stack माना गया
Next.js + Supabase + Vercel (adaptable)
आप क्या ठीक करेंगे
Auth, data isolation, API keys, validation, rate limits, env vars
यह कब करें
किसी भी असली यूजर या क्लाइंट के ऐप को access करने से पहले
अंतिम सत्यापन
अप्रैल 2026

AI-Generated Code में सुरक्षा समस्याएं क्यों होती हैं

AI models "क्या यह काम करता है?" के लिए optimize करते हैं, न कि "क्या यह सुरक्षित है?" के लिए। जब आप Claude को कहते हैं "मुझे user accounts के साथ एक task manager बनाओ," तो यह code generate करेगा जो users बनाता है, tasks store करता है, और उन्हें display करता है। लेकिन यह शायद automatically नहीं करेगा: सुनिश्चित करना कि User A, User B के tasks नहीं देख सकता, input fields को malicious scripts न accept करने के लिए validate करना, API keys को browser के developer tools से छिपाना, या API endpoints को hammer करने से रोकने के लिए rate limiting add करना।

ये AI की failures नहीं हैं — ये prompt में gaps हैं। AI वह बनाता है जो आपने कहा। आपने शायद सुरक्षा के लिए नहीं कहा क्योंकि आप features पर focused थे। अब इसे वापस जाकर add करने का समय है।

Step 1: अपने Environment Variables को Audit करें

यह vibe-coded apps में सबसे common और सबसे खतरनाक mistake है। अपने project के हर file में hardcoded API keys, database URLs, या secrets के लिए check करें।

क्या देखें: अपने codebase में ऐसी strings search करें जो sk-, eyJ, sbp_, supabase, postgres://, या कोई भी लंबी random-looking strings से शुरू होती हैं। इन files को specifically check करें: आपके /app या /pages directory में कोई भी file, कोई भी component file, आपका next.config.js, और कोई भी utility files।

Fix: हर secret को environment variables में move करें। Next.js में, केवल NEXT_PUBLIC_ से prefixed variables browser को expose होते हैं। आपका database URL, service role key, और API secrets को कभी भी यह prefix नहीं होना चाहिए।

.env.local
# .env.local (कभी भी इस file को commit न करें)
SUPABASE_SERVICE_ROLE_KEY=your-secret-key
DATABASE_URL=postgres://...

# ये browser को expose करने के लिए ठीक हैं:
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

Verify करें: अपनी .gitignore file check करें कि इसमें .env.local शामिल है। अगर आपने पहले से ही secrets को Git में commit कर दिया है, तो वे आपके history में हैं भले ही deletion के बाद — तुरंत हर exposed key को rotate (regenerate) करें।

Step 2: Supabase में Row-Level Security Enable करें

अगर आप Supabase use कर रहे हैं तो यह सबसे critical step है। Default में, Supabase tables के पास कोई access restrictions नहीं हैं — आपके anon key के साथ कोई भी हर table के हर row को read और write कर सकता है। इसका मतलब User A एक simple API call से User B का data देख सकता है।

Fix: हर table पर Row-Level Security (RLS) enable करें, फिर policies create करें जो access को restrict करें।

अपने Supabase dashboard में जाएं → Table Editor → हर table को select करें → "RLS Disabled" पर क्लिक करके enable करें। फिर policies add करें:

एक typical app के लिए जहां users अपना data ही देख सकें, एक SELECT policy create करें: auth.uid() = user_id। INSERT, UPDATE, और DELETE के लिए भी similar policies create करें।

Test करें: User A के रूप में log in करें, API के माध्यम से User B के data को access करने की कोशिश करें। अगर आप इसे देख सकते हैं, तो आपकी policies गलत हैं। Supabase में एक SQL editor है जहां आप policies को directly test कर सकते हैं।

Common AI mistake: Claude अक्सर Supabase queries को service_role key (जो RLS को bypass करता है) से generate करता है, anon key with proper RLS policies की जगह। Check करें कि आपका client-side code केवल anon key use करता है। Service role key केवल server-side code (API routes, server actions) में होना चाहिए और कभी भी browser को expose नहीं होना चाहिए।

Step 3: सही तरीके से Authentication Add करें

AI-generated auth code अक्सर काम करता है लेकिन shortcuts लेता है। इन specific issues को check करें:

Session management: सुनिश्चित करें कि sessions expire होते हैं। Check करें कि आपका auth setup एक reasonable session timeout include करता है (Supabase defaults आमतौर पर ठीक हैं, लेकिन verify करें)। सुनिश्चित करें कि logout करना actually session को invalidate करता है, केवल local cookie को clear नहीं करता।

Password requirements: अगर आपके पास email/password auth है, तो minimum password length (8+ characters) enforce करें। Supabase यह आपकी project settings → Authentication → Password Requirements में handle करता है।

Protected routes: हर page जो user-specific data दिखाता है को authentication middleware की जरूरत है। Next.js App Router में, एक middleware create करें जो valid session के लिए check करता है और unauthenticated users को login page पर redirect करता है। केवल client-side checks पर rely न करें — एक यूजर आपके API को directly hit करके उन्हें bypass कर सकता है।

Email verification: Supabase Auth settings में email confirmation enable करें। यह लोगों को fake email addresses से accounts create करने से रोकता है और account validity की एक basic layer add करता है।

क्या यह मूल्यवान है? हम AI tools, workflows, और practical guides पर हर हफ्ते एक deep-dive publish करते हैं। जो इसे पहले पाते हैं उनके साथ join करें →

Step 4: सभी Inputs को Validate करें

AI-generated forms आमतौर पर basic validation (required fields, email format) have करते हैं लेकिन rarely malicious input से protect करते हैं।

क्या add करें:

हर API endpoint पर server-side validation। कभी भी केवल client-side validation पर trust न करें — इसे सीधे API को requests भेजकर bypass किया जा सकता है। एक validation library जैसे Zod (TypeScript के लिए) use करें जो हर data के लिए schemas define करता है जो आपका ऐप accept करता है।

किसी भी user-generated content में जो browser में render होता है उसे HTML sanitize करें। अगर आपके ऐप में comments, descriptions, या कोई भी text field है जो browser में render होता है, तो DOMPurify जैसी library use करें जो dangerous scripts को strip करती है। इसके बिना, कोई JavaScript inject कर सकता है जो दूसरे users के sessions को steal करता है (cross-site scripting / XSS)।

अगर आपका ऐप file uploads accept करता है तो file upload size और types को limit करें। AI-generated upload handlers में अक्सर कोई limits नहीं होते, जिसका मतलब कोई 2GB file या एक executable upload कर सकता है। Size limits add करें (5MB most apps के लिए reasonable है) और file types को उन तक restrict करें जो आपको actually चाहिए (images, PDFs, etc.)।

Step 5: अपने API Routes को Secure करें

अपने ऐप के हर API route या server action को इन issues के लिए check करें:

हर endpoint पर Authentication। हर API route जो user data return या modify करता है को पहले user के session को verify करना चाहिए। AI अक्सर API routes generate करता है जो किसी से भी requests accept करते हैं।

Authentication से beyond authorization। एक यूजर logged in है यह confirm करने के बाद, verify करें कि वे specific resource को access करने की permission have करते हैं जो वे request कर रहे हैं। "User A logged in है" का मतलब यह नहीं कि "User A, User B के profile को edit कर सकता है।" हर data access पर ownership check करें।

Rate limiting। Rate limiting के बिना, कोई per second thousands requests भेज सकता है आपके API को, या तो data scrape करने के लिए या आपके server को overwhelm करने के लिए। rate-limiter-flexible जैसी library use करके या Vercel के built-in rate limiting को Edge Functions पर use करके basic rate limiting add करें।

HTTP methods। सुनिश्चित करें कि आपके API routes केवल उन HTTP methods को respond करते हैं जो उन्हें should करने चाहिए। एक route जो POST requests handle करता है को DELETE requests को भी respond नहीं करना चाहिए जब तक आपने explicitly इसे design न किया हो।

Step 6: अपने Deployment Configuration को Check करें

आपके deployment platform के पास security settings हैं जो AI configure नहीं करता।

Vercel settings to check: "Deployment Protection" enable करें (preview deployments को view करने के लिए auth require करता है — clients को accidentally preview URLs share करने से रोकता है जो in-progress work को expose करते हैं)। Spending limits set up करें unexpected charges से prevent करने के लिए अगर आपके ऐप को traffic spikes मिलते हैं। अपने allowed domains को CORS headers में configure करें।

Custom domain और SSL: अगर आप इसे क्लाइंट को deliver कर रहे हैं, तो उनके custom domain को HTTPS के साथ set up करें। Vercel और Netlify automatically SSL handle करते हैं। कभी भी क्लाइंट ऐप को .vercel.app subdomain पर deliver न करें — यह unprofessional लगता है और क्लाइंट इसे आसानी से transfer नहीं कर सकता।

Headers: अपने next.config.js या vercel.json में security headers add करें: X-Content-Type-Options: nosniff, X-Frame-Options: DENY (आपकी site को iframes में embed होने से रोकता है clickjacking के लिए), Strict-Transport-Security (HTTPS को force करता है)। ये one-time additions हैं जो attacks की पूरी classes को prevent करते हैं।

Step 7: एक Final Security Scan चलाएं

क्लाइंट को कुछ भी देने से पहले, इन free checks को run करें:

npm audit: अपनी project directory में npm audit run करें। यह आपकी dependencies में known vulnerabilities को flag करता है। Critical और high-severity issues को fix करें। npm audit fix को automatic fixes के लिए जहां available हो run करें।

Lighthouse: Chrome में अपनी deployed site को open करें, DevTools को open करें, एक Lighthouse audit run करें। "Best Practices" score को check करें — यह common security issues को catch करता है जैसे missing HTTPS, vulnerable libraries, और insecure headers।

Manual testing: एक यूजर के रूप में log in करें, दूसरे यूजर के data को access करने की कोशिश करें URLs या API calls को modify करके। Empty forms, oversized inputs, और special characters (जैसे encoded XSS payloads) submit करने की कोशिश करें। अगर कोई भी ये काम करता है, तो आपके पास fix करने के लिए issues हैं।

The Pre-Launch Checklist

यह print करें और live होने से पहले हर item को check करें:

  • सभी secrets environment variables में (कोई hardcoded keys नहीं)
  • .env.local .gitignore में है (और कोई secrets Git history में नहीं हैं)
  • Supabase RLS हर table पर enabled है
  • RLS policies tested हैं (User A, User B के data को नहीं देख सकता)
  • Client-side code केवल anon key use करता है (service role key केवल server-side)
  • हर API route पर Authentication है
  • Authorization checks (ownership verification) data access पर हैं
  • हर form पर Input validation है (server-side, केवल client-side नहीं)
  • File upload limits हैं (size और type) अगर applicable है
  • API endpoints पर Rate limiting है
  • Security headers configured हैं
  • npm audit run किया गया है और critical issues fixed हैं
  • Custom domain SSL के साथ configured है
  • Preview deployments protected हैं
  • Manual cross-user data access test pass हुआ है

The Bottom Line

Vibe-coded app को secure करना एक security expert बनने के बारे में नहीं है। यह एक checklist को run करने के बारे में है जो predictable gaps को catch करता है जो AI behind छोड़ता है। ऊपर दिए गए steps 2–4 घंटे लेते हैं और most common vulnerabilities को prevent करते हैं। एक client-facing ऐप के लिए, यह optional नहीं है — यह professional work और एक liability के बीच का difference है।

अगर आप अपना पहला vibe-coded app build कर रहे हैं, तो हमारे complete guide to vibe coding से शुरू करें। अगर आप Claude या Cursor के साथ use करने वाले prompts को improve करना चाहते हैं, तो हमारे free prompt optimizer को try करें। और best coding tools के breakdown के लिए, Claude Code vs Codex को देखें।

यह है जो हम हर हफ्ते करते हैं। AI tools, workflows, और honest takes पर एक deep-dive — कोई hype नहीं, कोई filler नहीं। हमारे साथ join करें →

Disclosure: इस article में कुछ links affiliate links हैं। हम केवल ऐसे tools को recommend करते हैं जिन्हें हमने personally test किया है और regularly use करते हैं। हमारी full disclosure policy देखें।