@yagyeshvyas/vibeguard 0.1.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/rules-pack.js CHANGED
@@ -380,6 +380,7 @@ const mikroOrmRules = [
380
380
  title: 'MikroORM query with raw identifier from request',
381
381
  re: /knex\.raw\s*\(\s*[^)]*req\.(?:body|query|params)/i,
382
382
  skipComments: true,
383
+ fileFilter: '\\.(?:js|ts)$',
383
384
  message: 'MikroORM/Knex raw query with request data — identifier injection.',
384
385
  fix: 'Use parameterized queries; never pass request data as a raw SQL identifier.',
385
386
  owasp: 'A03:2025 Injection',
@@ -1063,7 +1064,7 @@ const aiSecurityRules = [
1063
1064
  severity: 'high',
1064
1065
  confidence: 'medium',
1065
1066
  title: 'AI agent can trigger deployment',
1066
- re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:deploy|publish|release|ship)/i,
1067
+ re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?<!false\s*[,}])\b(?:deploy|publish|release|ship)\b/i,
1067
1068
  skipComments: true,
1068
1069
  message: 'AI agent can trigger a deployment — prompt injection can ship malicious code.',
1069
1070
  fix: 'Never let an AI agent deploy; require a human review step before any deployment.',
@@ -1087,7 +1088,7 @@ const aiSecurityRules = [
1087
1088
  severity: 'high',
1088
1089
  confidence: 'medium',
1089
1090
  title: 'AI agent can access environment secrets',
1090
- re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?:process\.env|environment|secrets|\.env)/i,
1091
+ re: /(?:agent|tool|function)\s*[:=]\s*[^}]*(?<!false\s*[,}])\b(?:process\.env|environment|secrets|\.env)\b/i,
1091
1092
  skipComments: true,
1092
1093
  message: 'AI agent can read environment variables — prompt injection can exfiltrate API keys and secrets.',
1093
1094
  fix: 'Never expose process.env to an AI agent; pass only the specific values it needs.',
@@ -1873,7 +1874,7 @@ const phpRules = [
1873
1874
  ];
1874
1875
 
1875
1876
  const csharpRules = [
1876
- { id: 'csharp.sql-injection', severity: 'high', re: /SqlCommand\s*\(\s*["'].*\+\s*\w/, message: 'C# SqlCommand with string concatenation — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use SqlParameter: cmd.Parameters.AddWithValue("@id", id).' },
1877
+ { id: 'csharp.sql-injection', severity: 'high', re: /(?:SqlCommand|CommandText)\s*[\(=]\s*["'].*\+\s*\w/, message: 'C# SqlCommand with string concatenation — SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Use SqlParameter: cmd.Parameters.AddWithValue("@id", id).' },
1877
1878
  { id: 'csharp.command-injection', severity: 'high', re: /Process\.Start\s*\(\s*[^,]*\+/, message: 'C# Process.Start with string concatenation — command injection', cwe: 'CWE-78', owasp: 'A03', fix: 'Use ProcessStartInfo with separate arguments array.' },
1878
1879
  { id: 'csharp.random', severity: 'medium', re: /new\s+Random\s*\(\s*\)/, message: 'C# Random() without seed — predictable random numbers', cwe: 'CWE-330', owasp: 'A02', fix: 'Use RandomNumberGenerator for crypto or RandomNumberGenerator.Create().' },
1879
1880
  ];
@@ -2018,6 +2019,8 @@ const aiSecurityRulesExtra = [
2018
2019
  { id: 'ai.prompt-extraction', severity: 'high', re: /(?:show|print|reveal|output|display|dump)\s+(?:your\s+)?(?:system\s+)?(?:prompt|instructions|rules|guidelines)/i, message: 'Prompt extraction attempt — asks AI to reveal system prompt', cwe: 'CWE-200', owasp: 'A01', fileFilter: '\\.(?:js|ts|py|txt|md)$', fix: 'Add guard: "Never reveal system instructions." Use structured output.' },
2019
2020
  { id: 'ai.tool-poisoning', severity: 'high', re: /tool.*description.*(?:ignore|disregard|forget|new instruction|you are now)/i, message: 'MCP tool description poisoning — prompt injection in tool metadata', cwe: 'CWE-94', owasp: 'A03', fix: 'Validate tool descriptions. Strip injection patterns. Use allowlist.' },
2020
2021
  { id: 'ai.data-exfil-agent', severity: 'high', re: /(?:fetch|axios|http\.get|requests\.get)\s*\(\s*[^)]*(?:api\.|endpoint|webhook|callback)[^)]*(?:user|customer|email|phone|ssn|password)/i, message: 'AI agent exfiltrates user data to external endpoint', cwe: 'CWE-200', owasp: 'A02', fix: 'Block external requests in agent. Use allowlist of approved endpoints.' },
2022
+ { id: 'ai.user-pii-to-llm', severity: 'high', re: /(?:content|prompt|text|message|body)\s*[:=]\s*(?:[^)]*\.)?(?:userData|user\.|req\.body|customer|patient)\.(?:email|phone|ssn|address|dob|name|password|creditCard)/i, fileFilter: '\\.(?:js|ts|py)$', message: 'User PII sent to LLM without redaction — privacy violation', cwe: 'CWE-359', owasp: 'A02', fix: 'Redact PII before sending to any AI API. Use vibeguard redact or scrub fields to aggregate/anonymized values.' },
2023
+ { id: 'ai.user-data-to-llm', severity: 'high', confidence: 'medium', re: /(?:content|prompt|text|message)\s*[:=]\s*(?:JSON\.stringify\s*\(\s*(?:userProfile|user_Data|user_data|profile|userData|req\.body)\s*\)|req\.body\s*[,\)])|body\s*[:=]\s*JSON\.stringify\s*\(\s*req\.body\s*\)/i, fileFilter: '\\.(?:js|ts|py)$', message: 'User data object sent to LLM without redaction — may contain PII', cwe: 'CWE-359', owasp: 'A02', fix: 'Redact PII before sending to any AI API. Send only the fields the LLM needs, not the whole user object.' },
2021
2024
  { id: 'ai.model-id-user-input', severity: 'high', re: /model\s*:\s*(?:req|user|input|params|query|body)\.(?:model|modelId|engine)/, message: 'Model ID from user input — model injection/billing abuse', cwe: 'CWE-94', owasp: 'A03', fix: 'Validate model ID against allowlist. Never pass user input as model.' },
2022
2025
  { id: 'ai.adversarial-no-filter', severity: 'medium', re: /(?:temperature\s*:\s*(?:2|2\.0|1\.9|1\.8|1\.7)|top_p\s*:\s*(?:1|0\.99))/, message: 'Very high temperature/top_p — adversarial output risk', cwe: 'CWE-105', owasp: 'A04', fix: 'Cap temperature at 1.0 and top_p at 0.95 for safety.' },
2023
2026
  { id: 'ai.memory-poisoning', severity: 'high', re: /(?:memory|context|history)\s*(?:\.push|\.unshift|\.concat|\[\s*\w+\s*\])\s*=\s*req\.(?:body|query|params)/, message: 'AI agent memory updated from user input — memory poisoning', cwe: 'CWE-94', owasp: 'A08', fix: 'Sanitize memory inputs. Use structured memory with type checking.' },
@@ -2025,6 +2028,15 @@ const aiSecurityRulesExtra = [
2025
2028
  { id: 'ai.agent-loop-no-cap', severity: 'high', re: /while\s*\(\s*true\s*\)|for\s*\(\s*;\s*;\s*\)|maxIterations\s*:\s*(?:Infinity|0|-1|undefined)/, message: 'AI agent loop without iteration cap — infinite loop / cost', cwe: 'CWE-835', owasp: 'A04', fix: 'Set maxIterations to a finite number. Add timeout and budget.' },
2026
2029
  { id: 'ai.tool-result-injection', severity: 'high', re: /(?:response|result|output)\s*(?:\.text|\.content|\.body|\.json)\s*(?:\+|\`\$\{)/, message: 'Tool result concatenated into prompt — indirect prompt injection', cwe: 'CWE-94', owasp: 'A03', fix: 'Escape tool results before including in prompt. Use structured parsing.' },
2027
2030
  { id: 'ai.no-content-filter-bypass', severity: 'medium', re: /(?:moderation|filter|safety)\s*(?::\s*false|\.disable|\.bypass)/, message: 'AI content filter/safety disabled', cwe: 'CWE-693', owasp: 'A05', fix: 'Keep content moderation enabled. Use provider-side safety settings.' },
2031
+ // --- AI-code-generation-specific rules (the wedge: generic SAST misses these) ---
2032
+ { id: 'ai.user-input-in-system-prompt', severity: 'critical', re: /system['"`][^}]*content\s*:\s*[^}]*(?:req|request|user|input|body|query|params)\b/i, message: 'User input injected into system prompt — prompt injection root cause', cwe: 'CWE-94', owasp: 'A03', fix: 'Never put user input in the system prompt. Use the user message role only.' },
2033
+ { id: 'ai.llm-output-exec', severity: 'critical', re: /(?:exec|execSync|spawn|eval|Function)\s*\(\s*(?:completion|response|result|output|message|content|text|answer|reply)\b/i, message: 'LLM output passed to exec/eval — prompt injection becomes RCE', cwe: 'CWE-94', owasp: 'A03', fix: 'Never execute LLM output. Parse structured JSON and validate before any eval/exec.' },
2034
+ { id: 'ai.llm-output-sql-v2', severity: 'high', re: /(?:query|execute|raw)\s*\(\s*(?:completion|response|result|output|message|content|text|answer|reply)\b/i, message: 'LLM output passed to SQL query — prompt injection becomes SQL injection', cwe: 'CWE-89', owasp: 'A03', fix: 'Never use LLM output as SQL. Extract structured data and parameterize.' },
2035
+ { id: 'ai.no-prompt-injection-guard', severity: 'medium', re: /(?:openai|anthropic|gemini|claude)\.(?:chat|completions|messages)\.create\s*\(\s*\{[^}]*(?:messages|prompt)\s*:/i, confidence: 'low', message: 'LLM API call without prompt injection guard — no input sanitization', cwe: 'CWE-94', owasp: 'A03', fix: 'Add a prompt injection detection layer before sending user input to the LLM.' },
2036
+ { id: 'ai.mcp-tool-no-auth', severity: 'high', re: /server\.tool\s*\(\s*['"][^'"]+['"][^)]*(?:file|exec|shell|command|database|query|delete|write|read)/i, message: 'MCP tool with dangerous capability and no auth check — abuse by prompt injection', cwe: 'CWE-306', owasp: 'A01', fix: 'Add authentication/authorization to MCP tools that access files, commands, or databases.' },
2037
+ { id: 'ai.cursorrule-injection', severity: 'medium', re: /(?:IGNORE|DISREGARD|FORGET)\s+(?:all\s+)?(?:previous|prior|above)\s+(?:instructions|rules|guidelines)/i, fileFilter: '\\.(?:md|txt|cursorrules|cursorrule)$', message: 'Prompt injection pattern in rules file — AI may follow injected instructions', cwe: 'CWE-94', owasp: 'A03', fix: 'Remove injection patterns from rules files. Use structured rule format.' },
2038
+ { id: 'ai.hallucinated-import', severity: 'medium', re: /(?:require|import)\s*\(\s*['"](?:ai-|openai-|claude-|llm-|gpt-|chat-)[a-z0-9-]+['"]\)/i, confidence: 'low', message: 'Import of AI-specific package — verify it exists (slopsquatting risk)', cwe: 'CWE-1104', owasp: 'A06', fix: 'Verify the package exists on npm. AI tools sometimes hallucinate package names.' },
2039
+ { id: 'ai.agent-env-key-direct', severity: 'critical', re: /\bsk-[a-zA-Z0-9]{20,}\b(?!.*process\.env)/i, message: 'AI API key hardcoded in code — key visible to AI agents in context', cwe: 'CWE-798', owasp: 'A02', fix: 'Use a secret vault (vibeguard vault) to hide keys from AI agent context. Never expose keys in code AI tools can read.' },
2028
2040
  ];
2029
2041
 
2030
2042
  // ---------------------------------------------------------------------------
@@ -2299,6 +2311,7 @@ const powerRulesExtra = [
2299
2311
  { id: 'secret.asana-token', severity: 'high', re: /ASANA_(?:ACCESS_)?TOKEN\s*[:=]\s*['"]\d+\/[A-Za-z0-9]{32,}['"]/i, message: 'Asana access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
2300
2312
  { id: 'secret.turso-token', severity: 'high', re: /TURSO_(?:GROUP_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9._-]{40,}['"]/i, message: 'Turso group token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
2301
2313
  { id: 'secret.supabase-service-role', severity: 'critical', re: /SUPABASE_SERVICE_ROLE_KEY\s*[:=]\s*['"][A-Za-z0-9._-]{40,}['"]/i, message: 'Supabase service role key exposed — bypasses RLS', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable. Never expose service role key to client.' },
2314
+ { id: 'secret.supabase-service-role-createclient', severity: 'critical', re: /createClient\s*\(\s*['"][^'"]*supabase\.co['"]\s*,\s*['"]eyJ[A-Za-z0-9._-]{20,}['"]/i, message: 'Supabase service role key in createClient() — bypasses RLS, visible to all users', cwe: 'CWE-798', owasp: 'A02', fix: 'Never use the service role key in client code. Use the anon key with RLS policies.' },
2302
2315
  { id: 'secret.mapbox-token', severity: 'medium', re: /MAPBOX_(?:ACCESS_)?TOKEN\s*[:=]\s*['"]pk\.[A-Za-z0-9._-]{60,}['"]/i, message: 'Mapbox access token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
2303
2316
  { id: 'secret.twilio-account-sid', severity: 'medium', re: /TWILIO_ACCOUNT_SID\s*[:=]\s*['"]AC[a-z0-9]{32}['"]/i, message: 'Twilio Account SID exposed — combined with auth token enables API access', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
2304
2317
  { id: 'secret.postmark-token', severity: 'high', re: /POSTMARK_(?:SERVER_)?TOKEN\s*[:=]\s*['"][A-Za-z0-9-]{36}['"]/i, message: 'Postmark server token exposed', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable.' },
@@ -2324,6 +2337,9 @@ const powerRulesExtra = [
2324
2337
  { id: 'injection.xss-angular-bypass', severity: 'high', re: /DomSanitizer(?:Provider)?\s*\(\s*\)|bypassSecurityTrust(?:Html|ResourceUrl|ScriptUrl|Style)/, message: 'Angular DomSanitizer bypass — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Never bypass Angular sanitization. Use safe pipes or component templates.' },
2325
2338
  { id: 'injection.xss-vue-v-html', severity: 'high', re: /v-html\s*=\s*['"]?\{?\{?\s*(?:req|user|input|data|params|query|body|response)/, message: 'Vue v-html with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Never use v-html with user input. Use v-text or sanitize with DOMPurify.' },
2326
2339
  { id: 'injection.xss-angular-innerHTML', severity: 'high', re: /innerHTML\s*=\s*(?:this\.)?(?:data|user|input|response|result|body|query)\./i, fileFilter: '\\.(?:ts|js)$', message: 'Angular innerHTML with user data — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use Angular sanitization. Set [innerHTML] with sanitized content.' },
2340
+ { id: 'injection.xss-innerhtml-direct', severity: 'high', re: /\.innerHTML\s*=\s*(?:req|request|params|query|body|userInput|location\.search|location\.hash|new\s+URLSearchParams|URLSearchParams|document\.URL|document\.location|window\.location)/i, fileFilter: '\\.(?:js|ts|jsx|tsx)$', message: 'innerHTML assigned from user-controllable input — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use textContent instead of innerHTML. If HTML is needed, sanitize with DOMPurify.' },
2341
+ { id: 'injection.xss-outerhtml', severity: 'high', re: /\.outerHTML\s*=\s*(?:req|request|params|query|body|userInput|location\.search|location\.hash|new\s+URLSearchParams|URLSearchParams|document\.URL|window\.location)/i, fileFilter: '\\.(?:js|ts|jsx|tsx)$', message: 'outerHTML assigned from user-controllable input — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use textContent. Never set outerHTML from user input.' },
2342
+ { id: 'injection.xss-insertadjacent', severity: 'high', re: /insertAdjacentHTML\s*\(\s*['"](?:beforebegin|afterbegin|beforeend|afterend)['"]\s*,\s*(?:req|request|params|query|body|userInput|location\.search|location\.hash|new\s+URLSearchParams|URLSearchParams|document\.URL|window\.location)/i, fileFilter: '\\.(?:js|ts|jsx|tsx)$', message: 'insertAdjacentHTML with user-controllable input — XSS', cwe: 'CWE-79', owasp: 'A03', fix: 'Use insertAdjacentText or sanitize with DOMPurify before insertAdjacentHTML.' },
2327
2343
 
2328
2344
  // More auth/session
2329
2345
  { id: 'auth.session-cookie-no-httponly', severity: 'high', re: /cookie\s*[:=]\s*\{[^}]*(?:name|key)\s*:\s*['"]session['"][^}]*\}/, confidence: 'low', message: 'Session cookie without httpOnly flag — JS can read session', cwe: 'CWE-1004', owasp: 'A05', fix: 'Set httpOnly: true on session cookies.' },
@@ -2360,9 +2376,7 @@ const powerRulesExtra = [
2360
2376
 
2361
2377
  // More AI security
2362
2378
  { id: 'ai.prompt-leak-via-error', severity: 'high', re: /catch\s*\(\s*\w+\s*\)\s*\{[^}]*(?:console\.log|throw|res\.(?:json|send))[^}]*(?:prompt|system|instructions)/i, message: 'AI prompt leaked via error handler — system prompt exposure', cwe: 'CWE-209', owasp: 'A01', fix: 'Never include prompt content in error responses. Log server-side only.' },
2363
- { id: 'ai.no-input-sanitization', severity: 'high', re: /(?:messages|prompt|input)\s*[:=]\s*req\.(?:body|query|params)\.(?:prompt|message|input|text)/i, confidence: 'low', message: 'AI input from user without sanitization — prompt injection', cwe: 'CWE-20', owasp: 'A03', fix: 'Sanitize user input before passing to LLM. Strip injection patterns.' },
2364
2379
  { id: 'ai.unbounded-output', severity: 'medium', re: /max_tokens\s*[:=]\s*(?:undefined|0|-1|Infinity|100000|1000000)/i, message: 'AI output without max_tokens limit — cost and DoS risk', cwe: 'CWE-770', owasp: 'A04', fix: 'Set max_tokens to a reasonable limit (e.g. 500-2000).' },
2365
- { id: 'ai.no-rate-limit', severity: 'medium', re: /(?:openai|anthropic|gemini|llama)\.(?:completions|chat|messages|generate)/i, confidence: 'low', message: 'LLM API call without rate limiting — cost abuse risk', cwe: 'CWE-770', owasp: 'A04', fix: 'Add rate limiting on AI endpoints. Track and limit per-user costs.' },
2366
2380
  { id: 'ai.response-not-validated', severity: 'medium', re: /(?:response|completion|output)\.(?:text|content|message|choices)\[0\]\.(?:text|content)/, confidence: 'low', message: 'AI response used without validation — may contain injection or malformed data', cwe: 'CWE-20', owasp: 'A08', fix: 'Validate AI output format with Zod schema before using.' },
2367
2381
  ];
2368
2382
 
@@ -2615,10 +2629,103 @@ const amazingRules = [
2615
2629
  { id: 'firewall.keylogger-install', severity: 'critical', re: /(?:install|create|deploy)\s+(?:a\s+)?keylogger/i, skipComments: true, message: 'Keylogger installation request', cwe: 'CWE-200', owasp: 'A01', fix: 'Block immediately. This is surveillance malware.' },
2616
2630
  ];
2617
2631
 
2632
+ // ---------------------------------------------------------------------------
2633
+ // HARDENED BATCH: 60 rules — rate limiting, input validation, secrets deep,
2634
+ // dependency vulns, error/info leakage, file upload safety
2635
+ // ---------------------------------------------------------------------------
2636
+
2637
+ // --- 10 Rate Limiting Rules ---
2638
+ const rateLimitRules = [
2639
+ { id: 'ratelimit.express-missing', severity: 'high', re: /app\.(?:get|post|put|delete|patch)\s*\([^)]*(?:req,\s*res)/, confidence: 'low', skipComments: true, message: 'Express route without rate limiting — brute force / DoS', cwe: 'CWE-770', owasp: 'A04', fix: 'Add express-rate-limit: rateLimit({ windowMs: 60000, max: 100 })' },
2640
+ { id: 'ratelimit.login-no-limit', severity: 'critical', re: /(?:login|signin|authenticate)\s*[:(]\s*(?:async\s+)?function|(?:login|signin).*app\.(?:post|get)/i, confidence: 'medium', skipComments: true, message: 'Login endpoint without rate limiting — credential stuffing', cwe: 'CWE-307', owasp: 'A07', fix: 'Add per-IP rate limit on login: max 5 attempts per 15 min. Add exponential backoff.' },
2641
+ { id: 'ratelimit.api-no-key', severity: 'medium', re: /app\.(?:get|post)\s*\(\s*['"]\/api\//, confidence: 'low', skipComments: true, message: 'API route without API key or rate limit — unbounded access', cwe: 'CWE-770', owasp: 'A04', fix: 'Add API key auth + rate limit per key. Use express-rate-limit.' },
2642
+ { id: 'ratelimit.no-burst-protection', severity: 'medium', re: /express\.json\s*\(\s*\{\s*\}\s*\)|bodyParser\s*\(\s*\)/, confidence: 'low', skipComments: true, message: 'No burst protection — large number of rapid requests can DoS', cwe: 'CWE-770', owasp: 'A04', fix: 'Add rate limiter middleware before body parser. Limit to 100 req/min per IP.' },
2643
+ { id: 'ratelimit.password-reset-no-limit', severity: 'high', re: /(?:reset|forgot).*password.*(post|route)/i, confidence: 'medium', skipComments: true, message: 'Password reset endpoint without rate limit — email bombing', cwe: 'CWE-307', owasp: 'A07', fix: 'Limit reset emails: max 3 per hour per email. Add CAPTCHA after 2 attempts.' },
2644
+ { id: 'ratelimit.no-global-limit', severity: 'medium', re: /app\.listen\s*\(/, confidence: 'low', skipComments: true, message: 'Server starts without global rate limiter — no DoS protection', cwe: 'CWE-770', owasp: 'A04', fix: 'Add app.use(rateLimit({ windowMs: 60000, max: 100 })) before routes.' },
2645
+ { id: 'ratelimit.otp-no-limit', severity: 'high', re: /(?:otp|verification|verify).*code.*(?:post|route|verify)/i, confidence: 'medium', skipComments: true, message: 'OTP/verification endpoint without rate limit — brute force OTP', cwe: 'CWE-307', owasp: 'A07', fix: 'Limit OTP attempts: max 5 per 10 min. Lock after 3 failures. Add exponential backoff.' },
2646
+ { id: 'ratelimit.websocket-no-limit', severity: 'medium', re: /(?:io|socket)\.(?:on|connect)\s*\(/, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'WebSocket without connection rate limit — resource exhaustion', cwe: 'CWE-770', owasp: 'A04', fix: 'Add connection rate limit: max 10 new connections per second per IP.' },
2647
+ { id: 'ratelimit.signup-no-limit', severity: 'high', re: /(?:signup|register|createUser).*app\.(?:post|route)/i, confidence: 'medium', skipComments: true, message: 'Signup endpoint without rate limit — account enumeration / mass registration', cwe: 'CWE-307', owasp: 'A07', fix: 'Add per-IP rate limit on signup: max 3 per hour. Add CAPTCHA.' },
2648
+ { id: 'ratelimit.ai-cost-no-cap', severity: 'high', re: /(?:openai|anthropic|gemini)\.(?:chat|completions|messages|generate)\.(?:create|stream)\b/i, confidence: 'low', skipComments: true, message: 'AI API call without cost cap — unlimited spend', cwe: 'CWE-770', owasp: 'A04', fix: 'Add per-user token budget. Set max_tokens. Track and cap daily spend.' },
2649
+ ];
2650
+
2651
+ // --- 10 Input Validation Rules ---
2652
+ const inputValidationRules = [
2653
+ { id: 'validation.missing-zod', severity: 'medium', re: /req\.(?:body|query|params)\s*(?:;|\n|\)|$)/, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Request body/query used without schema validation — type confusion / injection', cwe: 'CWE-20', owasp: 'A03', fix: 'Validate with Zod: const schema = z.object({ name: z.string().min(1) }); schema.parse(req.body).' },
2654
+ { id: 'validation.no-type-check', severity: 'medium', re: /parseInt\s*\(\s*req\.(?:body|query|params)\./, confidence: 'medium', skipComments: true, message: 'parseInt on request input without NaN check — type confusion', cwe: 'CWE-20', owasp: 'A03', fix: 'Check: if (isNaN(id)) return res.status(400).json({ error: "Invalid ID" });' },
2655
+ { id: 'validation.no-length-limit', severity: 'medium', re: /(?:req\.body|req\.query)\.(?:name|title|description|comment|bio|message|content|body|text)\b(?!.*(?:\.length|maxLength|truncate|slice|substring))/i, confidence: 'low', skipComments: true, message: 'String field from request without length validation — storage DoS', cwe: 'CWE-20', owasp: 'A04', fix: 'Limit length: if (req.body.name.length > 200) return 400; or use Zod .max(200).' },
2656
+ { id: 'validation.no-email-format', severity: 'medium', re: /req\.body\.(?:email|userEmail|user_email)\b(?!.*(?:validator|isEmail|z\.string\(\)\.email|includes\(['"]@))/i, confidence: 'low', skipComments: true, message: 'Email from request without format validation — invalid data / injection', cwe: 'CWE-20', owasp: 'A03', fix: 'Validate: if (!validator.isEmail(req.body.email)) return 400; or Zod: z.string().email().' },
2657
+ { id: 'validation.no-uuid-format', severity: 'medium', re: /req\.(?:params|body|query)\.(?:id|userId|postId|itemId|productId)\b(?!.*(?:uuid|isUUID|isValid|mongoose\.Types\.ObjectId))/i, confidence: 'low', skipComments: true, message: 'ID from request without format validation — NoSQL injection / IDOR', cwe: 'CWE-20', owasp: 'A01', fix: 'Validate ID format: if (!/^[a-f0-9]{24}$/i.test(req.params.id)) return 400;' },
2658
+ { id: 'validation.no-allowlist', severity: 'high', re: /req\.body\.(?:role|type|status|category|action|command|operation)\b(?!.*(?:allowlist|whitelist|includes|allowedTypes|validRoles))/i, confidence: 'medium', skipComments: true, message: 'User-controllable enum field without allowlist — privilege escalation / injection', cwe: 'CWE-20', owasp: 'A01', fix: 'Validate against allowlist: const allowed = ["user","admin"]; if (!allowed.includes(req.body.role)) return 400;' },
2659
+ { id: 'validation.mass-assignment-v2', severity: 'high', re: /(?:Object\.assign|spread|\.create|\.update|\.save)\s*\(\s*[^)]*req\.body\b(?!.*(?:pick|allowlist|whitelist|sanitize))/i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Mass assignment: req.body passed directly to model create/update — users can set role, isAdmin, etc.', cwe: 'CWE-915', owasp: 'A01', fix: 'Pick only allowed fields: const { name, email } = req.body; User.create({ name, email });' },
2660
+ { id: 'validation.no-regex-validation', severity: 'medium', re: /req\.body\.(?:username|slug|shortcode|handle)\b(?!.*(?:test|match|regex|pattern|validator))/i, confidence: 'low', skipComments: true, message: 'Username/slug/handle without regex validation — XSS / injection via special chars', cwe: 'CWE-20', owasp: 'A03', fix: 'Validate: if (!/^[a-zA-Z0-9_-]{3,20}$/.test(req.body.username)) return 400;' },
2661
+ { id: 'validation.no-array-validation', severity: 'medium', re: /req\.body\.(?:tags|categories|ids|items|list)\b(?!.*(?:isArray|Array\.isArray|z\.array))/i, confidence: 'low', skipComments: true, message: 'Array field from request without validation — type confusion / DoS via huge arrays', cwe: 'CWE-20', owasp: 'A04', fix: 'Validate: if (!Array.isArray(req.body.tags) || req.body.tags.length > 50) return 400;' },
2662
+ { id: 'validation.boolean-coercion', severity: 'low', re: /req\.body\.(?:active|enabled|disabled|confirmed|verified|isAdmin|isPublic)\b(?!.*(?:===\s*(?:true|false)|z\.boolean|Boolean\())/i, confidence: 'low', skipComments: true, message: 'Boolean field from request without strict check — truthy coercion ("false" string is truthy)', cwe: 'CWE-20', owasp: 'A03', fix: 'Use strict: if (req.body.isActive === true) or Zod: z.boolean().' },
2663
+ ];
2664
+
2665
+ // --- 10 Secrets Deep Rules ---
2666
+ const secretsDeepRules = [
2667
+ { id: 'secret.in-plain-config', severity: 'critical', re: /(?:password|secret|apiKey|api_key|token|privateKey)\s*[:=]\s*["'][^"']{6,}["']/i, confidence: 'high', skipComments: true, fileFilter: '\\.(?:json|yml|yaml|toml|ini|conf|cfg|env)$', message: 'Secret in plain config file — not in vault/KMS', cwe: 'CWE-798', owasp: 'A02', fix: 'Move to environment variable or secret vault. Never commit secrets in config files.' },
2668
+ { id: 'secret.hardcoded-jwt-secret', severity: 'critical', re: /jwt\.sign\s*\(\s*[^,]+,\s*["'][^"']{6,}["']/i, confidence: 'high', skipComments: true, message: 'JWT secret hardcoded in code — token forgery', cwe: 'CWE-798', owasp: 'A02', fix: 'Load from env: jwt.sign(payload, process.env.JWT_SECRET). Use at least 256-bit secret.' },
2669
+ { id: 'secret.hardcoded-session-secret', severity: 'critical', re: /session\s*\(\s*\{[^}]*secret\s*:\s*["'][^"']{6,}["']/i, confidence: 'high', skipComments: true, message: 'Session secret hardcoded — session forgery', cwe: 'CWE-798', owasp: 'A02', fix: 'Load from env: secret: process.env.SESSION_SECRET. Use 64+ random bytes.' },
2670
+ { id: 'secret.in-graphql-context', severity: 'high', re: /context\s*[:=]\s*\{[^}]*(?:apiKey|secret|token|password)\s*[:=]\s*["'][^"']{8,}["']/i, confidence: 'medium', skipComments: true, message: 'Secret hardcoded in GraphQL context — visible to all resolvers', cwe: 'CWE-798', owasp: 'A02', fix: 'Load from env or vault. Never put secrets in context object.' },
2671
+ { id: 'secret.in-dockerfile', severity: 'critical', re: /(?:ENV|ARG)\s+(?:PASSWORD|SECRET|TOKEN|API_KEY|PRIVATE_KEY)\s*=\s*["']?[^"'\s]{6,}/i, confidence: 'high', skipComments: true, fileFilter: 'Dockerfile$', message: 'Secret in Dockerfile ENV — baked into image layers forever', cwe: 'CWE-798', owasp: 'A05', fix: 'Use Docker secrets or --env-file at runtime. Never bake secrets into images.' },
2672
+ { id: 'secret.in-log', severity: 'high', re: /(?:console\.log|logger\.(?:info|debug|warn|error)|winston|bunyan|pino)\s*\([^)]*(?:password|secret|token|apiKey|privateKey|creditCard|ssn)/i, confidence: 'medium', skipComments: true, message: 'Secret written to log — credentials leaked via logs', cwe: 'CWE-532', owasp: 'A02', fix: 'Never log secrets. Redact: const { password, ...safe } = user; console.log(safe).' },
2673
+ { id: 'secret.in-error-response', severity: 'high', re: /res\.(?:json|send)\s*\(\s*\{[^}]*(?:stack|trace|error.*detail|internal).*\}/i, confidence: 'medium', skipComments: true, message: 'Error response includes stack trace or internal details — info leak', cwe: 'CWE-209', owasp: 'A05', fix: 'Send generic error: res.status(500).json({ error: "Internal error" }). Log details server-side.' },
2674
+ { id: 'secret.no-rotation-comment', severity: 'low', re: /(?:\/\/|#|\/\*)\s*(?:TODO|FIXME|HACK).*rotat/i, confidence: 'low', skipComments: false, message: 'TODO about key rotation — secrets may be stale', cwe: 'CWE-798', owasp: 'A02', fix: 'Rotate the key now. Set up automatic rotation every 90 days.' },
2675
+ { id: 'secret.k8s-secret-plaintext', severity: 'high', re: /kind:\s*Secret[\s\S]{0,500}stringData:[\s\S]{0,500}(?:password|token|key|secret)\s*:/i, confidence: 'high', fileFilter: '\\.ya?ml$', message: 'Kubernetes Secret with plaintext stringData — visible in kubectl describe', cwe: 'CWE-312', owasp: 'A02', fix: 'Use encrypted secrets: Sealed Secrets, External Secrets Operator, or Vault.' },
2676
+ { id: 'secret.in-url-query', severity: 'high', re: /https?:\/\/[^\s]*[?&](?:api_key|apikey|token|secret|password|access_token)\s*=/i, confidence: 'high', skipComments: true, message: 'Secret in URL query string — logged in server access logs, browser history, Referer headers', cwe: 'CWE-598', owasp: 'A02', fix: 'Send secrets in headers, not URL params. Use Authorization: Bearer <token>.' },
2677
+ ];
2678
+
2679
+ // --- 10 Dependency Vulnerability Rules ---
2680
+ const depVulnRules = [
2681
+ { id: 'dep.unpinned-exact', severity: 'medium', re: /"([a-z@][\w@.-]*)"\s*:\s*"\d+\.\d+\.\d+(?!\s*-\d)/, confidence: 'low', fileFilter: 'package\\.json$', message: 'Dependency pinned to exact version but no lockfile check — verify npm audit', cwe: 'CWE-1104', owasp: 'A06', fix: 'Run npm audit regularly. Consider Dependabot/Renovate for auto-updates.' },
2682
+ { id: 'dep.caret-range', severity: 'low', re: /"([a-z@][\w@.-]*)"\s*:\s*"\^\d+\.\d+\.\d+"/, confidence: 'low', fileFilter: 'package\\.json$', message: 'Dependency uses caret range (^) — minor updates may introduce vulnerabilities', cwe: 'CWE-1104', owasp: 'A06', fix: 'Run npm audit. Pin critical deps to exact versions. Use lockfile.' },
2683
+ { id: 'dep.deprecated-package', severity: 'high', re: /"(?:request|node-uuid|left-pad|colors|faker|mkdirp|lodash@4|moment|hapi|jade|gulp-util)"\s*:/, confidence: 'high', fileFilter: 'package\\.json$', message: 'Deprecated/abandoned package — security patches stopped', cwe: 'CWE-1104', owasp: 'A06', fix: 'Replace: request->got/axios, moment->day.js, colors->picocolors, faker->@faker-js/faker.' },
2684
+ { id: 'dep.no-lockfile', severity: 'medium', re: /"name"\s*:\s*"[^"]*"/, confidence: 'low', fileFilter: 'package\\.json$', message: 'package.json found — verify package-lock.json exists to prevent dependency confusion', cwe: 'CWE-1104', owasp: 'A06', fix: 'Run npm install to generate lockfile. Commit package-lock.json.' },
2685
+ { id: 'dep.preinstall-script', severity: 'critical', re: /"preinstall"\s*:\s*"/, confidence: 'high', fileFilter: 'package\\.json$', message: 'preinstall script in package.json — runs before install, can execute arbitrary code', cwe: 'CWE-506', owasp: 'A06', fix: 'Remove preinstall script. Never run arbitrary code during npm install.' },
2686
+ { id: 'dep.postinstall-script', severity: 'high', re: /"postinstall"\s*:\s*"/, confidence: 'medium', fileFilter: 'package\\.json$', message: 'postinstall script in package.json — runs arbitrary code after install', cwe: 'CWE-506', owasp: 'A06', fix: 'Review the script. Remove if not needed. Malicious packages use postinstall for malware.' },
2687
+ { id: 'dep.github-dep', severity: 'medium', re: /"[a-z@][\w@.-]*"\s*:\s*"github:[^"]+"/, confidence: 'low', fileFilter: 'package\\.json$', message: 'GitHub dependency — not on npm registry, no audit trail', cwe: 'CWE-1104', owasp: 'A06', fix: 'Prefer npm published packages. If using GitHub, pin to commit hash.' },
2688
+ { id: 'dep.trust-all', severity: 'critical', re: /npm\s+install\s+(?:--force|--no-audit)/, confidence: 'high', skipComments: true, message: 'npm install with --force or --no-audit — skipping vulnerability check', cwe: 'CWE-1104', owasp: 'A06', fix: 'Never use --force or --no-audit. Fix the vulnerability instead of suppressing it.' },
2689
+ { id: 'dep.no-engines', severity: 'low', re: /"name"\s*:\s*"[^"]*"/, confidence: 'low', fileFilter: 'package\\.json$', message: 'No engines field in package.json — node version mismatch risk', cwe: 'CWE-1104', owasp: 'A06', fix: 'Add "engines": { "node": ">=18.0.0" } to enforce Node version.' },
2690
+ { id: 'dep.unpackaged-bin', severity: 'medium', re: /(?:child_process\.exec|execSync|spawn)\s*\(\s*["'](?:npm|npx|yarn|pnpm)\s/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Executing package manager from code — supply chain risk if user input reaches it', cwe: 'CWE-78', owasp: 'A06', fix: 'Never exec npm from runtime code. Install deps at build time only.' },
2691
+ ];
2692
+
2693
+ // --- 10 Error Handling + Information Leakage Rules ---
2694
+ const errorLeakageRules = [
2695
+ { id: 'error.stack-to-client', severity: 'high', re: /res\.(?:json|send)\s*\(\s*(?:err|error|e)\.(?:stack|trace|message)/i, confidence: 'high', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Stack trace sent to client — internal paths, versions leaked', cwe: 'CWE-209', owasp: 'A05', fix: 'Send generic error: res.status(500).json({ error: "Something went wrong" }). Log stack server-side.' },
2696
+ { id: 'error.verbose-mode', severity: 'high', re: /(?:debug|verbose|showErrors|showStack)\s*:\s*true/i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Verbose/debug mode enabled — leaks internals to clients', cwe: 'CWE-489', owasp: 'A05', fix: 'Set debug: false in production. Use NODE_ENV=production.' },
2697
+ { id: 'error.sql-to-client', severity: 'high', re: /res\.(?:json|send)\s*\(\s*(?:err|error|e)\.(?:sql|sqlMessage|query|detail)/i, confidence: 'high', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'SQL error sent to client — schema/table names leaked', cwe: 'CWE-209', owasp: 'A05', fix: 'Catch DB errors: catch(e) { logger.error(e); res.status(500).json({ error: "Database error" }); }' },
2698
+ { id: 'error.console-in-prod', severity: 'medium', re: /console\.(?:log|debug|info|dir|trace)\s*\(/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'console.log in production code — info leak via logs', cwe: 'CWE-532', owasp: 'A05', fix: 'Use a logger (winston/pino) with level filtering. Remove console.log from prod.' },
2699
+ { id: 'error.no-catch-all', severity: 'medium', re: /app\.listen\s*\(/, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'No global error handler — unhandled rejections crash server', cwe: 'CWE-754', owasp: 'A05', fix: 'Add: process.on("uncaughtException", ...) and app.use((err, req, res, next) => res.status(500).json({ error: "Internal" })).' },
2700
+ { id: 'error.no-try-catch', severity: 'medium', re: /(?:JSON\.parse|parseInt|parseFloat|Number)\s*\(\s*req\.(?:body|query|params)\b(?!.*try)/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Parse of request data without try/catch — crashes on malformed input', cwe: 'CWE-754', owasp: 'A05', fix: 'Wrap: try { const data = JSON.parse(req.body.data); } catch(e) { return res.status(400).json({ error: "Invalid JSON" }); }' },
2701
+ { id: 'error.internal-msg-leak', severity: 'medium', re: /res\.(?:json|send|render)\s*\(\s*\{[^}]*(?:internal|database|connection|query|filesystem|ECONNREFUSED|ENOTFOUND)/i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Internal system details in error response — infrastructure leak', cwe: 'CWE-209', owasp: 'A05', fix: 'Send generic error. Map known errors to user-friendly messages.' },
2702
+ { id: 'error.xpoweredby', severity: 'low', re: /app\.(?:listen|use)\s*\(/, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', filter: (line, content, lines) => !lines.some(l => /helmet|disable.*x-powered-by/i.test(l)), message: 'X-Powered-By header not disabled — framework version leaked', cwe: 'CWE-200', owasp: 'A05', fix: 'Add: app.disable("x-powered-by"). Or use helmet middleware.' },
2703
+ { id: 'error.err-throw-to-client', severity: 'high', re: /(?:throw|next)\s*\(\s*(?:err|error|e)\b/i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Raw error thrown/forwarded to client — may contain stack trace or internal info', cwe: 'CWE-209', owasp: 'A05', fix: 'Map error to safe message: next(new Error("Request failed")). Never forward raw DB/system errors.' },
2704
+ { id: 'error.no-body-limit', severity: 'medium', re: /express\.json\s*\(\s*\{\s*(?:limit\s*:\s*['"]?(?:\d+['"]?\s*[GM]?B|Infinity)|)/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Body parser with no or large limit — DoS via huge payload', cwe: 'CWE-770', owasp: 'A04', fix: 'Set: express.json({ limit: "1mb" }). Default is 100kb which is fine.' },
2705
+ ];
2706
+
2707
+ // --- 10 File Upload Safety Rules ---
2708
+ const fileUploadRules = [
2709
+ { id: 'upload.no-size-limit', severity: 'high', re: /(?:multer|upload|formidable|busboy|multipart)\s*\(\s*\{\s*(?!.*limit)/i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'File upload without size limit — DoS via large files', cwe: 'CWE-770', owasp: 'A04', fix: 'Set: multer({ limits: { fileSize: 5 * 1024 * 1024 } }) — 5MB max.' },
2710
+ { id: 'upload.no-mime-check', severity: 'high', re: /multer\s*\(\s*\{[^}]*(?:dest|storage)[^}]*\}/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'File upload without MIME type validation — malicious file upload (webshell, polyglot)', cwe: 'CWE-434', owasp: 'A04', fix: 'Validate: fileFilter: (req, file, cb) => { if (["image/jpeg","image/png","application/pdf"].includes(file.mimetype)) cb(null, true); else cb(new Error("Invalid type")); }' },
2711
+ { id: 'upload.no-extension-check', severity: 'high', re: /req\.files?\b(?!.*(?:path\.extname|originalname|filename.*test|\.match|\.includes))/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Uploaded file used without extension validation — webshell upload (.php, .jsp, .exe)', cwe: 'CWE-434', owasp: 'A04', fix: 'Validate: const ext = path.extname(file.originalname).toLowerCase(); if (!["jpg","png","pdf"].includes(ext)) return 400;' },
2712
+ { id: 'upload.original-name-used', severity: 'critical', re: /(?:filename|dest|key|path)\s*:\s*req\.files?\.\w+\.originalName|fs\.(?:writeFile|createWriteStream)\s*\(\s*[^)]*req\.files?\b/i, confidence: 'high', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Uploaded file saved with original filename — path traversal via filename (../../etc/passwd)', cwe: 'CWE-22', owasp: 'A04', fix: 'Generate safe name: const name = crypto.randomUUID() + path.extname(file.originalname). Never use user-supplied filename.' },
2713
+ { id: 'upload.no-virus-scan', severity: 'medium', re: /multer\s*\(\s*\{[^}]*storage/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'File upload without virus scanning — malware storage/distribution', cwe: 'CWE-434', owasp: 'A04', fix: 'Scan with ClamAV or cloud scan API before storing. Reject infected files.' },
2714
+ { id: 'upload.executable-allowed', severity: 'critical', re: /(?:accept|allowedTypes|fileTypes|mimeTypes)\s*:\s*\[[^\]]*(?:\.exe|\.php|\.jsp|\.asp|\.sh|\.bat|\.cmd|\.jar|\.war|application\/(?:x-php|x-httpd-php|x-executable|octet-stream))/i, confidence: 'high', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Executable file type allowed in upload — webshell / RCE', cwe: 'CWE-434', owasp: 'A04', fix: 'Remove executable types from allowlist. Only allow images, PDFs, docs.' },
2715
+ { id: 'upload.no-s3-acl', severity: 'medium', re: /s3\.(?:upload|putObject)\s*\(\s*\{[^}]*Key\s*:/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'S3 upload without ACL — defaults to bucket ACL, may be public', cwe: 'CWE-732', owasp: 'A05', fix: 'Set: ACL: "private" or "bucket-owner-full-control". Never use "public-read" for user uploads.' },
2716
+ { id: 'upload.serve-from-upload-dir', severity: 'high', re: /app\.(?:get|use)\s*\(\s*['"]\/uploads/i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Serving files directly from upload directory — stored XSS via uploaded HTML/SVG', cwe: 'CWE-79', owasp: 'A03', fix: 'Serve uploads via a handler that sets Content-Disposition: attachment. Strip scripts from SVG. Never serve HTML/SVG as text/html.' },
2717
+ { id: 'upload.no-content-disposition', severity: 'medium', re: /res\.(?:sendFile|download)\s*\(\s*[^)]*upload/i, confidence: 'low', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Uploaded file served without Content-Disposition — XSS if browser renders HTML', cwe: 'CWE-79', owasp: 'A03', fix: 'Set: res.setHeader("Content-Disposition", "attachment"). Set correct Content-Type.' },
2718
+ { id: 'upload.field-name-dynamic', severity: 'medium', re: /multer\s*\(\s*\{[^}]*field\s*:\s*req\./i, confidence: 'medium', skipComments: true, fileFilter: '\\.(?:js|ts)$', message: 'Upload field name from request — multipart manipulation', cwe: 'CWE-20', owasp: 'A04', fix: 'Use fixed field names. Never accept field names from user input.' },
2719
+ ];
2720
+
2618
2721
  // ---------------------------------------------------------------------------
2619
2722
  // GAP BATCH: Assemble all line rules
2620
2723
  // ---------------------------------------------------------------------------
2621
2724
 
2725
+ // Gate language-specific rules by file extension so they don't fire on other
2726
+ // languages. Spread ...r last so a rule's own tighter fileFilter still wins.
2727
+ const withExt = (rules, ext) => rules.map((r) => ({ fileFilter: ext, ...r }));
2728
+
2622
2729
  const allLineRules = [
2623
2730
  ...clerkRules, ...authJsRules, ...oauthRules, ...supabaseAuthRules,
2624
2731
  ...drizzleRules, ...honoRules, ...trpcRules, ...convexRules,
@@ -2629,20 +2736,20 @@ const allLineRules = [
2629
2736
  ...aiSecurityRules,
2630
2737
  ...supplyChainRules,
2631
2738
  ...advancedSecurityRules,
2632
- ...goRules,
2739
+ ...withExt(goRules, '\\.go$'),
2633
2740
  ...mobileRules,
2634
2741
  ...deploymentRules,
2635
2742
  ...owaspApiRules,
2636
2743
  ...extraSecretRules,
2637
- ...javaRules,
2744
+ ...withExt(javaRules, '\\.java$'),
2638
2745
  ...rubyRules,
2639
- ...phpRules,
2640
- ...csharpRules,
2746
+ ...withExt(phpRules, '\\.php$'),
2747
+ ...withExt(csharpRules, '\\.cs$'),
2641
2748
  ...djangoRules,
2642
- ...flaskRules,
2643
- ...railsRules,
2644
- ...laravelRules,
2645
- ...springRules,
2749
+ ...withExt(flaskRules, '\\.py$'),
2750
+ ...withExt(railsRules, '\\.(rb|erb)$'),
2751
+ ...withExt(laravelRules, '\\.php$'),
2752
+ ...withExt(springRules, '\\.java$'),
2646
2753
  ...fastifyRules,
2647
2754
  ...svelteKitRules,
2648
2755
  ...nuxtRules,
@@ -2654,7 +2761,7 @@ const allLineRules = [
2654
2761
  ...deserializationRules,
2655
2762
  ...cloudRules,
2656
2763
  ...aiSecurityRulesExtra,
2657
- ...pythonDeepRules,
2764
+ ...withExt(pythonDeepRules, '\\.py$'),
2658
2765
  ...raceConditionRules,
2659
2766
  ...cicdDeepRules,
2660
2767
  ...rustRules,