तुम अपने AI coding assistant पर भरोसा करते हो। वो clean functions लिखता है, edge cases handle करता है, helpful comments डालता है। Code compile होता है, tests pass होते हैं, pull request — नया code main project में merge करने का proposal — को thumbs up मिल जाता है। तीन महीने बाद, एक security tester को उस function में छेद मिलता है जो तुम्हारे agent ने रात 2 बजे लिखा था। किसी ने question नहीं किया क्योंकि "सही तो लग रहा था।"

ये कोई thought experiment नहीं है। ये तुम्हारा average Tuesday है।

Confidence और competence के बीच का गड्ढा

AI-generated code अब बहुत सी companies में नए code का लगभग 46% है। तुम इससे बच नहीं सकते। लेकिन "AI ने लिखा" और "हमने ship कर दिया" के बीच कहीं एक खतरनाक assumption घुस गया: कि machine को पता है वो क्या कर रही है। नहीं पता। ये बस एक बहुत तेज़ typist है जिसे attackers का concept ही नहीं है।

तुम्हें एक field manual चाहिए। ये रहा तुम्हारा।

चार में से एक snippet में छेद है

फरवरी 2026 में, security research group AppSecSanta ने छह major LLMs — large language models, ChatGPT, Claude, Gemini जैसे tools के पीछे का दिमाग — को 89 security-focused coding prompts पर test किया। Python और JavaScript। Real-world tasks जो OWASP Top 10 — web application security risks की सबसे widely accepted list — से mapped थे।

Result: 25.1% generated code में confirmed vulnerabilities थीं। चार में से एक snippet। तुम्हारा AI industrial scale पर bugs लिखता है, और वो भी उस आदमी के calm confidence के साथ जिसे कभी hack नहीं किया गया।

Model के हिसाब से vulnerability rates:

Model Vuln rate
GPT-5.2 19.1% (सबसे अच्छा)
Gemini 2.5 Pro 22.4%
Grok 4 23.7%
Claude Opus 4.6 29.2%
DeepSeek V3 29.2%
Llama 4 Maverick 29.2%

वो 10-point का spread मतलब तुम्हारे model choice से फर्क पड़ता है। लेकिन सबसे अच्छा model भी हर पाँच outputs में से एक में vulnerability ship करता है। GPT-5.2 चुनना Llama 4 से बेहतर है। लेकिन ये तुम्हें बचाएगा नहीं।

Models सबसे ज़्यादा कहाँ fail होते हैं:

  • SSRF (Server-Side Request Forgery — जब तुम्हारा server attacker की तरफ से internal URLs call करने में धोखा खा जाता है): 32 findings। सबसे बड़ी category।
  • Injection (SQL injection, command injection — जब user input चुपके से database queries या system commands में घुस जाता है): 30 findings, सारे issues का 33.1%।
  • Security misconfiguration: 25 findings — hardcoded secrets, production में debug mode चालू छोड़ दिया।
  • Broken access control (users को वो करने देना जो उन्हें करने की permission नहीं होनी चाहिए): हर tested model में मौजूद।

March 2026 की एक अलग Help Net Security study ने Claude Code, OpenAI Codex, और Google Gemini को agent mode में test किया — सिर्फ autocomplete नहीं, पूरी तरह autonomous coding। Agents ने 30 pull requests cover करने वाले 38 scans में 143 security issues produce किए। 87% PRs में कम से कम एक vulnerability थी। Broken access control हर single agent के output में दिखा। हर। एक। में।

Machine insecure code क्यों लिखती है

Models злоumean नहीं हैं। ये probability machines हैं जो GitHub पर train हुई हैं, और GitHub insecure code से भरा पड़ा है। 2015 के Stack Overflow answers जो JWT secrets hardcode करते हैं (JWT — JSON Web Token, एक digital pass जो prove करता है कि तुम logged in हो)। Tutorial code जो input validation skip करता है क्योंकि "ये तो बस demo है।" उन companies का production code जिन्होंने कभी security audit नहीं चलाया।

तीन patterns बार-बार दिखते हैं:

1. Missing server-side validation. AI agents client-side values — scores, balances, user roles — accept कर लेते हैं बिना server पर verify किए। Model ने हज़ारों tutorials से सीखा जो "validation reader पर छोड़ दी।" Reader ने कभी exercise नहीं किया। AI ने भी नहीं।

2. Insecure defaults. बिना expiration date वाले JWT tokens। OAuth implementations (OAuth — वो protocol जो तुम्हें "Sign in with Google" करने देता है एक और password बनाने की बजाय) जिनमें hijacking रोकने वाला state parameter गायब है। Refresh tokens जो revoke नहीं हो सकते। Models ऐसा code generate करते हैं जो काम करता है लेकिन lazy default चुनता है, secure वाला नहीं।

3. SSRF हर जगह. जब model URL fetch करने वाला code लिखता है, तो वो लगभग कभी check नहीं करता कि URL कहाँ point कर रहा है। कोई allowlists नहीं, internal IP addresses block नहीं, protocol पर कोई restriction नहीं। बस requests.get(user_input) call करता है और ship कर देता है। Attacker http://169.254.169.254/ feed करता है और अचानक तुम्हारे cloud credentials उसके हाथ में।

तुम्हारा पाँच-layer defense stack

Models के security में smarter होने का इंतज़ार करना बंद करो। एक pipeline बनाओ — automated checks का sequence — जो problems पकड़े चाहे code किसी ने भी लिखा हो।

Layer 1: Security-focused prompting

सबसे simple fix जिसकी कोई cost नहीं। एक Veracode study में पाया गया कि prompt में एक generic security reminder जोड़ने से Claude Opus 4.6 के लिए secure code की rate 56% से 66% हो गई। एक sentence से दस percent improvement। Magic नहीं है। लेकिन free है।

ये अपने system prompt, Cursor rules, या CLAUDE.md में डालो:

When writing code: validate all inputs server-side. Never trust
client data. Use parameterized queries. Set secure defaults for
auth tokens (expiration, rotation). Block SSRF by validating URLs
against allowlists. Never hardcode secrets.

Claude Code, Codex, या Copilot जैसे AI coding agents के लिए, ये instructions अपने project की configuration files में डालो। Agent हर task पर इन्हें पढ़ता है।

Layer 2: Editor में SAST

SAST — Static Application Security Testing — तुम्हारे code को बिना run किए vulnerabilities के लिए scan करता है, जैसे spell-checker लेकिन security holes के लिए। AppSecSanta की key finding: सिर्फ एक SAST tool ने AI-generated vulnerabilities का 78% पकड़ा। Multiple scanners चलाने से coverage dramatically improve होती है।

Recommended setup:

  • Semgrep — free, fast, 3,000+ rules। VS Code, JetBrains, और CI में चलता है। Injection, SSRF, hardcoded secrets पकड़ता है।
  • Bandit (Python) — common Python security issues पकड़ता है। Zero configuration।
  • ESLint security plugins (JavaScript) — eslint-plugin-security और eslint-plugin-no-unsanitized

Semgrep को pre-commit hook के तौर पर install करो — एक script जो हर commit से पहले automatically चलती है, bad code को repository में enter होने से रोकती है:

pip install semgrep
semgrep --config auto --error .

अब हर commit scan होता है। AI code लिखता है, Semgrep push करने से पहले उसकी थप्पड़ मारता है।

Layer 3: CI pipeline scanning

तुम्हारा pre-commit hook obvious चीज़ें पकड़ता है। तुम्हारी CI pipeline — automated build-and-test system जो code push करने पर चलता है — को deeper analysis चलानी चाहिए:

# GitHub Actions example
- name: Semgrep SAST
  uses: semgrep/semgrep-action@v1
  with:
    config: >-
      p/owasp-top-ten
      p/cwe-top-25
      p/python-security
      p/javascript-security

- name: Dependency check
  uses: dependency-check/dependency-check-action@v1

Apne rules उन categories पर focus करो जहाँ AI सबसे ज़्यादा fail होता है: SSRF (CWE-918), injection (CWE-89, CWE-78), unsafe deserialization (CWE-502 — जब malicious data executable objects में unpack हो जाता है), और path traversal (CWE-22 — जब attacker ../../ use करके directory से escape करता है और ऐसी files पढ़ता है जो उसे नहीं देखनी चाहिए)।

Layer 4: Security lens वाला human review

AI-generated code का code review normal review से अलग होता है। तुम logic errors नहीं ढूंढ रहे — AI वो ठीक-ठाक handle करता है। तुम ढूंढ रहे हो:

  • बिना auth checks वाले endpoints. AI route handler लिखता है लेकिन middleware भूल जाता है — वो gatekeeper code जो check करता है "तुम्हें यहाँ होने की permission है?"
  • User input dangerous जगहों पर जा रहा है. Database queries, file operations, HTTP requests, shell commands। अगर user input इनमें से किसी को बिना sanitization के touch करता है, तो problem है।
  • Missing rate limiting. AI कभी rate limiting नहीं डालता जब तक explicitly नहीं बोलो। हर public endpoint को इसकी ज़रूरत है, वरना कोई 10,000 requests per second से hammer करेगा।
  • Code में secrets. Model कभी-कभी placeholder API keys generate करता है जो इतनी real लगती हैं कि ship हो जाती हैं। फिर GitHub पर पहुँच जाती हैं। फिर किसी और के हाथ में।

Apni team को हर AI-generated function के लिए एक सवाल पूछना सिखाओ: "अगर input hostile हो तो क्या होगा?"

Layer 5: OpenSSF rules file

OpenSSF — Open Source Security Foundation — ने AI Code Assistant Instructions के लिए एक standardized Security-Focused Guide publish की। ये एक rules file है जो तुम अपने project root में डालते हो। हर AI coding tool जो project-level instructions support करता है, इसे automatically पढ़ता है।

File input validation, output encoding, authentication, session management, cryptography, error handling, और logging cover करती है। Scratch से अपने security rules लिखने की बजाय, उनके use करो — security professionals maintain करते हैं, regularly update होते हैं, और free हैं।

इसकी क्या cost है

Time। हर layer friction add करती है। Pre-commit hooks हर commit में 5–15 seconds जोड़ते हैं। CI scans pipeline में minutes जोड़ते हैं। Human review के लिए ऐसे humans चाहिए जो जानते हों कि SSRF कैसा दिखता है। OpenSSF file को एक बार पढ़ना और समझना पड़ता है।

False positives irritate करेंगे। Semgrep ऐसा code flag करेगा जो actually ठीक है। तुम non-issues investigate करने में time spend करोगे। ये वो tax है जो real vulnerabilities पकड़ने के लिए देना पड़ता है।

और इसमें से कुछ भी foolproof नहीं है। AppSecSanta study में पाया गया कि 22% vulnerabilities सारे SAST tools से बच निकलीं। कुछ holes के लिए dynamic testing चाहिए — actually code run करके उस पर attack करना — ढूंढने के लिए। Static analysis ज़रूरी है लेकिन काफी नहीं।

Monday morning क्या करना है

तुम्हें अगले हफ्ते तक पाँचों layers implement नहीं करनी। दो से शुरू करो:

  1. अपने AI config में security instructions डालो. Layer 1 से prompt block copy करो। अपने project में paste करो। पाँच minutes।
  2. Semgrep pre-commit hook install करो. दो commands। चाय ठंडी होने से पहले हो जाएगा।

बस इतने से तुम आज AI-generated code ship करने वाली ज़्यादातर teams से आगे हो। CI scanning तब add करो जब sprint में थोड़ी साँस लेने की जगह हो। OpenSSF file तब add करो जब team में कोई इसे पढ़े और समझे। Reviewers को धीरे-धीरे train करो।

नया normal

AI-generated code में vulnerability rate 2024 में लगभग 40% से गिरकर 2026 में 25% हुई। Progress, sure। इस speed से, हम "acceptable" 2030 के आसपास पहुँचेंगे। तुम चार साल wait नहीं कर सकते।

AI-generated code को ऐसे treat करो जैसे एक junior developer का output जो 500 words per minute type करता है, confidence से चमकता है, और जिसने OWASP का नाम नहीं सुना। Review करो। Scan करो। Test करो। फिर ship करो।

AI 10x speed पर code लिखता है। तुम्हारी security tooling को match करना होगा। Tools exist करते हैं। बस एक चीज़ missing है — उन्हें use करने की आदत।