xploitscan-shared-rules 1.2.2 → 1.3.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/README.md +1 -1
- package/dist/index.cjs +1583 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +1535 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -4003,7 +4003,111 @@ var complianceMap = {
|
|
|
4003
4003
|
VC155: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
4004
4004
|
VC156: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
4005
4005
|
VC157: { owasp: "A05:2021", cwe: "CWE-16" },
|
|
4006
|
-
VC158: { owasp: "A01:2021", cwe: "CWE-639" }
|
|
4006
|
+
VC158: { owasp: "A01:2021", cwe: "CWE-639" },
|
|
4007
|
+
// VC159–VC183: Additional service-specific API key detection.
|
|
4008
|
+
// All map to A07:2021 (Identification & Auth Failures) / CWE-798 (Hardcoded
|
|
4009
|
+
// Credentials), matching the existing VC132–VC145 cluster.
|
|
4010
|
+
VC159: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4011
|
+
// Cohere
|
|
4012
|
+
VC160: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4013
|
+
// Replicate
|
|
4014
|
+
VC161: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4015
|
+
// Mistral
|
|
4016
|
+
VC162: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4017
|
+
// Together AI
|
|
4018
|
+
VC163: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4019
|
+
// Groq
|
|
4020
|
+
VC164: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4021
|
+
// Fireworks AI
|
|
4022
|
+
VC165: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4023
|
+
// Postmark
|
|
4024
|
+
VC166: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4025
|
+
// Resend
|
|
4026
|
+
VC167: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4027
|
+
// Loops
|
|
4028
|
+
VC168: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4029
|
+
// Cloudflare
|
|
4030
|
+
VC169: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4031
|
+
// Fastly
|
|
4032
|
+
VC170: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4033
|
+
// Netlify
|
|
4034
|
+
VC171: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4035
|
+
// Railway
|
|
4036
|
+
VC172: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4037
|
+
// Fly.io
|
|
4038
|
+
VC173: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4039
|
+
// Algolia admin key
|
|
4040
|
+
VC174: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4041
|
+
// Qdrant
|
|
4042
|
+
VC175: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4043
|
+
// Weaviate
|
|
4044
|
+
VC176: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4045
|
+
// Linear
|
|
4046
|
+
VC177: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4047
|
+
// Notion
|
|
4048
|
+
VC178: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4049
|
+
// Discord bot token
|
|
4050
|
+
VC179: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4051
|
+
// Intercom
|
|
4052
|
+
VC180: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4053
|
+
// Sentry auth token
|
|
4054
|
+
VC181: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4055
|
+
// Logtail / Better Stack
|
|
4056
|
+
VC182: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4057
|
+
// Highlight
|
|
4058
|
+
VC183: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
4059
|
+
// Plivo
|
|
4060
|
+
// VC184–VC187: GitHub Actions workflow security
|
|
4061
|
+
VC184: { owasp: "A08:2021", cwe: "CWE-829" },
|
|
4062
|
+
// pull_request_target + checkout PR head
|
|
4063
|
+
VC185: { owasp: "A05:2021", cwe: "CWE-732" },
|
|
4064
|
+
// permissions: write-all
|
|
4065
|
+
VC186: { owasp: "A03:2021", cwe: "CWE-78" },
|
|
4066
|
+
// expression injection in run:
|
|
4067
|
+
VC187: { owasp: "A08:2021", cwe: "CWE-829" },
|
|
4068
|
+
// third-party action receiving secrets
|
|
4069
|
+
// VC188–VC190: Dockerfile hardening
|
|
4070
|
+
VC188: { owasp: "A05:2021", cwe: "CWE-1357" },
|
|
4071
|
+
// ADD instead of COPY
|
|
4072
|
+
VC189: { owasp: "A08:2021", cwe: "CWE-494" },
|
|
4073
|
+
// RUN curl|sh
|
|
4074
|
+
VC190: { owasp: "A04:2021", cwe: "CWE-754" },
|
|
4075
|
+
// missing HEALTHCHECK
|
|
4076
|
+
// VC191–VC197: Python-specific security gaps
|
|
4077
|
+
VC191: { owasp: "A02:2021", cwe: "CWE-295" },
|
|
4078
|
+
// requests verify=False
|
|
4079
|
+
VC192: { owasp: "A03:2021", cwe: "CWE-79" },
|
|
4080
|
+
// Jinja2 autoescape=False
|
|
4081
|
+
VC193: { owasp: "A04:2021", cwe: "CWE-377" },
|
|
4082
|
+
// tempfile.mktemp TOCTOU
|
|
4083
|
+
VC194: { owasp: "A03:2021", cwe: "CWE-79" },
|
|
4084
|
+
// Django mark_safe
|
|
4085
|
+
VC195: { owasp: "A02:2021", cwe: "CWE-295" },
|
|
4086
|
+
// paramiko AutoAddPolicy
|
|
4087
|
+
VC196: { owasp: "A05:2021", cwe: "CWE-20" },
|
|
4088
|
+
// ALLOWED_HOSTS wildcard
|
|
4089
|
+
VC197: { owasp: "A02:2021", cwe: "CWE-347" },
|
|
4090
|
+
// PyJWT no algorithm allowlist
|
|
4091
|
+
// VC198–VC203: AI / LLM-specific security
|
|
4092
|
+
VC198: { owasp: "A03:2021", cwe: "CWE-94" },
|
|
4093
|
+
// prompt injection via user input
|
|
4094
|
+
VC199: { owasp: "A03:2021", cwe: "CWE-94" },
|
|
4095
|
+
// system-prompt injection
|
|
4096
|
+
VC200: { owasp: "A03:2021", cwe: "CWE-79" },
|
|
4097
|
+
// LLM output as raw HTML (XSS)
|
|
4098
|
+
VC201: { owasp: "A01:2021", cwe: "CWE-639" },
|
|
4099
|
+
// vector-store query without user filter
|
|
4100
|
+
VC202: { owasp: "A01:2021", cwe: "CWE-639" },
|
|
4101
|
+
// vector-store upsert without user metadata
|
|
4102
|
+
VC203: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
4103
|
+
// LLM call without max_tokens
|
|
4104
|
+
// VC204–VC206: GraphQL server hardening
|
|
4105
|
+
VC204: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
4106
|
+
// no query depth limit
|
|
4107
|
+
VC205: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
4108
|
+
// no query complexity limit
|
|
4109
|
+
VC206: { owasp: "A01:2021", cwe: "CWE-352" }
|
|
4110
|
+
// Apollo csrfPrevention: false
|
|
4007
4111
|
};
|
|
4008
4112
|
var consoleLogProduction = {
|
|
4009
4113
|
id: "VC097",
|
|
@@ -5348,6 +5452,1333 @@ var hardcodedPineconeKey = {
|
|
|
5348
5452
|
);
|
|
5349
5453
|
}
|
|
5350
5454
|
};
|
|
5455
|
+
function contextSecretRuleCheck(content, filePath, pattern, ruleId, title, severity, fix) {
|
|
5456
|
+
if (isTestFile(filePath)) return [];
|
|
5457
|
+
if (!SECRET_FILE_EXT.test(filePath)) return [];
|
|
5458
|
+
if (LOCK_FILE_RE.test(filePath)) return [];
|
|
5459
|
+
const findings = [];
|
|
5460
|
+
const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
5461
|
+
let m;
|
|
5462
|
+
while ((m = re.exec(content)) !== null) {
|
|
5463
|
+
if (isCommentLine(content, m.index)) continue;
|
|
5464
|
+
if (isInsideFixMessage(content, m.index)) continue;
|
|
5465
|
+
const lineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
5466
|
+
const lineText = content.substring(lineStart, content.indexOf("\n", m.index));
|
|
5467
|
+
if (PLACEHOLDER_RE.test(lineText)) continue;
|
|
5468
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
5469
|
+
findings.push({
|
|
5470
|
+
rule: ruleId,
|
|
5471
|
+
title,
|
|
5472
|
+
severity,
|
|
5473
|
+
category: "Secrets",
|
|
5474
|
+
file: filePath,
|
|
5475
|
+
line: lineNum,
|
|
5476
|
+
snippet: getSnippet(content, lineNum),
|
|
5477
|
+
fix
|
|
5478
|
+
});
|
|
5479
|
+
}
|
|
5480
|
+
return findings;
|
|
5481
|
+
}
|
|
5482
|
+
var hardcodedCohereKey = {
|
|
5483
|
+
id: "VC159",
|
|
5484
|
+
title: "Hardcoded Cohere API Key",
|
|
5485
|
+
severity: "high",
|
|
5486
|
+
category: "Secrets",
|
|
5487
|
+
description: "Cohere API keys grant access to all model endpoints (generation, embeddings, classification) and incur charges per token. A leaked key can be used to run unlimited inference at your expense.",
|
|
5488
|
+
check(content, filePath) {
|
|
5489
|
+
return contextSecretRuleCheck(
|
|
5490
|
+
content,
|
|
5491
|
+
filePath,
|
|
5492
|
+
/(?:COHERE_API_KEY|cohere[_-]?api[_-]?key)\s*[:=]\s*["'`]([A-Za-z0-9]{40})["'`]/gi,
|
|
5493
|
+
"VC159",
|
|
5494
|
+
this.title,
|
|
5495
|
+
"high",
|
|
5496
|
+
"Move the Cohere API key to an environment variable (COHERE_API_KEY). Rotate at dashboard.cohere.com \u2192 API keys."
|
|
5497
|
+
);
|
|
5498
|
+
}
|
|
5499
|
+
};
|
|
5500
|
+
var hardcodedReplicateKey = {
|
|
5501
|
+
id: "VC160",
|
|
5502
|
+
title: "Hardcoded Replicate API Token",
|
|
5503
|
+
severity: "high",
|
|
5504
|
+
category: "Secrets",
|
|
5505
|
+
description: "Replicate API tokens (r8_*) grant access to run any model in the Replicate catalog and incur charges per second of GPU time. A leaked token can run expensive image/video models at your expense.",
|
|
5506
|
+
check(content, filePath) {
|
|
5507
|
+
return secretRuleCheck(
|
|
5508
|
+
content,
|
|
5509
|
+
filePath,
|
|
5510
|
+
/r8_[A-Za-z0-9]{40,}/g,
|
|
5511
|
+
"VC160",
|
|
5512
|
+
this.title,
|
|
5513
|
+
"high",
|
|
5514
|
+
"Move the Replicate token to an environment variable (REPLICATE_API_TOKEN). Rotate at replicate.com \u2192 Account \u2192 API tokens."
|
|
5515
|
+
);
|
|
5516
|
+
}
|
|
5517
|
+
};
|
|
5518
|
+
var hardcodedMistralKey = {
|
|
5519
|
+
id: "VC161",
|
|
5520
|
+
title: "Hardcoded Mistral API Key",
|
|
5521
|
+
severity: "high",
|
|
5522
|
+
category: "Secrets",
|
|
5523
|
+
description: "Mistral API keys grant access to all chat and embedding models and incur charges per token. A leaked key can be used to run unlimited inference at your expense.",
|
|
5524
|
+
check(content, filePath) {
|
|
5525
|
+
return contextSecretRuleCheck(
|
|
5526
|
+
content,
|
|
5527
|
+
filePath,
|
|
5528
|
+
/(?:MISTRAL_API_KEY|mistral[_-]?api[_-]?key)\s*[:=]\s*["'`]([A-Za-z0-9]{32})["'`]/gi,
|
|
5529
|
+
"VC161",
|
|
5530
|
+
this.title,
|
|
5531
|
+
"high",
|
|
5532
|
+
"Move the Mistral key to an environment variable (MISTRAL_API_KEY). Rotate at console.mistral.ai \u2192 API Keys."
|
|
5533
|
+
);
|
|
5534
|
+
}
|
|
5535
|
+
};
|
|
5536
|
+
var hardcodedTogetherKey = {
|
|
5537
|
+
id: "VC162",
|
|
5538
|
+
title: "Hardcoded Together AI API Key",
|
|
5539
|
+
severity: "high",
|
|
5540
|
+
category: "Secrets",
|
|
5541
|
+
description: "Together AI API keys grant access to all open-source models hosted on the platform (Llama, Mixtral, Stable Diffusion, etc.) and incur charges per token. A leaked key can run unlimited inference at your expense.",
|
|
5542
|
+
check(content, filePath) {
|
|
5543
|
+
return contextSecretRuleCheck(
|
|
5544
|
+
content,
|
|
5545
|
+
filePath,
|
|
5546
|
+
/(?:TOGETHER_API_KEY|together[_-]?api[_-]?key)\s*[:=]\s*["'`]([a-f0-9]{64})["'`]/gi,
|
|
5547
|
+
"VC162",
|
|
5548
|
+
this.title,
|
|
5549
|
+
"high",
|
|
5550
|
+
"Move the Together AI key to an environment variable (TOGETHER_API_KEY). Rotate at api.together.ai \u2192 Settings \u2192 API Keys."
|
|
5551
|
+
);
|
|
5552
|
+
}
|
|
5553
|
+
};
|
|
5554
|
+
var hardcodedGroqKey = {
|
|
5555
|
+
id: "VC163",
|
|
5556
|
+
title: "Hardcoded Groq API Key",
|
|
5557
|
+
severity: "high",
|
|
5558
|
+
category: "Secrets",
|
|
5559
|
+
description: "Groq API keys (gsk_*) grant access to all hosted models on Groq's LPU inference platform and incur per-token charges. A leaked key can be used to run unlimited inference at your expense.",
|
|
5560
|
+
check(content, filePath) {
|
|
5561
|
+
return secretRuleCheck(
|
|
5562
|
+
content,
|
|
5563
|
+
filePath,
|
|
5564
|
+
/gsk_[A-Za-z0-9]{52,}/g,
|
|
5565
|
+
"VC163",
|
|
5566
|
+
this.title,
|
|
5567
|
+
"high",
|
|
5568
|
+
"Move the Groq key to an environment variable (GROQ_API_KEY). Rotate at console.groq.com \u2192 API Keys."
|
|
5569
|
+
);
|
|
5570
|
+
}
|
|
5571
|
+
};
|
|
5572
|
+
var hardcodedFireworksKey = {
|
|
5573
|
+
id: "VC164",
|
|
5574
|
+
title: "Hardcoded Fireworks AI API Key",
|
|
5575
|
+
severity: "high",
|
|
5576
|
+
category: "Secrets",
|
|
5577
|
+
description: "Fireworks AI API keys (fw_*) grant access to hosted open-source models and incur per-token charges. A leaked key can be used to run unlimited inference at your expense.",
|
|
5578
|
+
check(content, filePath) {
|
|
5579
|
+
return secretRuleCheck(
|
|
5580
|
+
content,
|
|
5581
|
+
filePath,
|
|
5582
|
+
/fw_[A-Za-z0-9]{20,}/g,
|
|
5583
|
+
"VC164",
|
|
5584
|
+
this.title,
|
|
5585
|
+
"high",
|
|
5586
|
+
"Move the Fireworks key to an environment variable (FIREWORKS_API_KEY). Rotate at fireworks.ai \u2192 API Keys."
|
|
5587
|
+
);
|
|
5588
|
+
}
|
|
5589
|
+
};
|
|
5590
|
+
var hardcodedPostmarkKey = {
|
|
5591
|
+
id: "VC165",
|
|
5592
|
+
title: "Hardcoded Postmark Server Token",
|
|
5593
|
+
severity: "high",
|
|
5594
|
+
category: "Secrets",
|
|
5595
|
+
description: "Postmark server tokens grant the ability to send emails as your domain, view delivery logs, and manage templates. A leaked token enables phishing from your verified sending domain.",
|
|
5596
|
+
check(content, filePath) {
|
|
5597
|
+
return contextSecretRuleCheck(
|
|
5598
|
+
content,
|
|
5599
|
+
filePath,
|
|
5600
|
+
/(?:POSTMARK_(?:API|SERVER)_TOKEN|postmark[_-]?(?:server|api)[_-]?token)\s*[:=]\s*["'`]([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})["'`]/gi,
|
|
5601
|
+
"VC165",
|
|
5602
|
+
this.title,
|
|
5603
|
+
"high",
|
|
5604
|
+
"Move the Postmark token to an environment variable (POSTMARK_SERVER_TOKEN). Rotate at account.postmarkapp.com \u2192 Servers \u2192 API Tokens."
|
|
5605
|
+
);
|
|
5606
|
+
}
|
|
5607
|
+
};
|
|
5608
|
+
var hardcodedResendKey = {
|
|
5609
|
+
id: "VC166",
|
|
5610
|
+
title: "Hardcoded Resend API Key",
|
|
5611
|
+
severity: "high",
|
|
5612
|
+
category: "Secrets",
|
|
5613
|
+
description: "Resend API keys (re_*) can send emails as your domain, access email logs, and manage domains. A leaked key enables phishing from your verified sending domain.",
|
|
5614
|
+
check(content, filePath) {
|
|
5615
|
+
return secretRuleCheck(
|
|
5616
|
+
content,
|
|
5617
|
+
filePath,
|
|
5618
|
+
/re_[A-Za-z0-9_]{20,}/g,
|
|
5619
|
+
"VC166",
|
|
5620
|
+
this.title,
|
|
5621
|
+
"high",
|
|
5622
|
+
"Move the Resend API key to an environment variable (RESEND_API_KEY). Rotate at resend.com \u2192 API Keys."
|
|
5623
|
+
);
|
|
5624
|
+
}
|
|
5625
|
+
};
|
|
5626
|
+
var hardcodedLoopsKey = {
|
|
5627
|
+
id: "VC167",
|
|
5628
|
+
title: "Hardcoded Loops API Key",
|
|
5629
|
+
severity: "high",
|
|
5630
|
+
category: "Secrets",
|
|
5631
|
+
description: "Loops API keys grant access to your contact list, transactional email sending, and audience segmentation. A leaked key can exfiltrate your customer list and send unauthorized emails.",
|
|
5632
|
+
check(content, filePath) {
|
|
5633
|
+
return contextSecretRuleCheck(
|
|
5634
|
+
content,
|
|
5635
|
+
filePath,
|
|
5636
|
+
/(?:LOOPS_API_KEY|loops[_-]?api[_-]?key)\s*[:=]\s*["'`]([A-Za-z0-9]{32,})["'`]/gi,
|
|
5637
|
+
"VC167",
|
|
5638
|
+
this.title,
|
|
5639
|
+
"high",
|
|
5640
|
+
"Move the Loops API key to an environment variable (LOOPS_API_KEY). Rotate at app.loops.so \u2192 Settings \u2192 API."
|
|
5641
|
+
);
|
|
5642
|
+
}
|
|
5643
|
+
};
|
|
5644
|
+
var hardcodedCloudflareToken = {
|
|
5645
|
+
id: "VC168",
|
|
5646
|
+
title: "Hardcoded Cloudflare API Token",
|
|
5647
|
+
severity: "critical",
|
|
5648
|
+
category: "Secrets",
|
|
5649
|
+
description: "Cloudflare API tokens grant access to DNS records, SSL configuration, Workers, R2 storage, and account settings depending on token scope. A leaked token can hijack DNS, intercept traffic, or wipe storage.",
|
|
5650
|
+
check(content, filePath) {
|
|
5651
|
+
return contextSecretRuleCheck(
|
|
5652
|
+
content,
|
|
5653
|
+
filePath,
|
|
5654
|
+
/(?:CLOUDFLARE_API_TOKEN|CF_API_TOKEN|cloudflare[_-]?api[_-]?token)\s*[:=]\s*["'`]([A-Za-z0-9_\-]{40})["'`]/gi,
|
|
5655
|
+
"VC168",
|
|
5656
|
+
this.title,
|
|
5657
|
+
"critical",
|
|
5658
|
+
"Move the Cloudflare token to an environment variable (CLOUDFLARE_API_TOKEN). Rotate at dash.cloudflare.com \u2192 My Profile \u2192 API Tokens."
|
|
5659
|
+
);
|
|
5660
|
+
}
|
|
5661
|
+
};
|
|
5662
|
+
var hardcodedFastlyToken = {
|
|
5663
|
+
id: "VC169",
|
|
5664
|
+
title: "Hardcoded Fastly API Token",
|
|
5665
|
+
severity: "high",
|
|
5666
|
+
category: "Secrets",
|
|
5667
|
+
description: "Fastly API tokens can purge cache, modify VCL configuration, and access service settings. A leaked token can disrupt CDN caching or redirect traffic via VCL changes.",
|
|
5668
|
+
check(content, filePath) {
|
|
5669
|
+
return contextSecretRuleCheck(
|
|
5670
|
+
content,
|
|
5671
|
+
filePath,
|
|
5672
|
+
/(?:FASTLY_API_(?:KEY|TOKEN)|fastly[_-]?api[_-]?(?:key|token))\s*[:=]\s*["'`]([A-Za-z0-9_\-]{32,})["'`]/gi,
|
|
5673
|
+
"VC169",
|
|
5674
|
+
this.title,
|
|
5675
|
+
"high",
|
|
5676
|
+
"Move the Fastly token to an environment variable (FASTLY_API_TOKEN). Rotate at manage.fastly.com \u2192 Account \u2192 API tokens."
|
|
5677
|
+
);
|
|
5678
|
+
}
|
|
5679
|
+
};
|
|
5680
|
+
var hardcodedNetlifyToken = {
|
|
5681
|
+
id: "VC170",
|
|
5682
|
+
title: "Hardcoded Netlify Personal Access Token",
|
|
5683
|
+
severity: "critical",
|
|
5684
|
+
category: "Secrets",
|
|
5685
|
+
description: "Netlify access tokens (nfp_*) grant access to deploy any site, modify environment variables (which may contain other secrets), and manage team settings. A leaked token can compromise production deployments.",
|
|
5686
|
+
check(content, filePath) {
|
|
5687
|
+
return secretRuleCheck(
|
|
5688
|
+
content,
|
|
5689
|
+
filePath,
|
|
5690
|
+
/nfp_[A-Za-z0-9_\-]{20,}/g,
|
|
5691
|
+
"VC170",
|
|
5692
|
+
this.title,
|
|
5693
|
+
"critical",
|
|
5694
|
+
"Move the Netlify token to an environment variable (NETLIFY_AUTH_TOKEN). Rotate at app.netlify.com \u2192 User Settings \u2192 Applications \u2192 Personal access tokens."
|
|
5695
|
+
);
|
|
5696
|
+
}
|
|
5697
|
+
};
|
|
5698
|
+
var hardcodedRailwayToken = {
|
|
5699
|
+
id: "VC171",
|
|
5700
|
+
title: "Hardcoded Railway API Token",
|
|
5701
|
+
severity: "critical",
|
|
5702
|
+
category: "Secrets",
|
|
5703
|
+
description: "Railway API tokens grant project deployment, environment variable management, and database access. A leaked token can read all your project secrets and modify production services.",
|
|
5704
|
+
check(content, filePath) {
|
|
5705
|
+
return contextSecretRuleCheck(
|
|
5706
|
+
content,
|
|
5707
|
+
filePath,
|
|
5708
|
+
/(?:RAILWAY_API_TOKEN|RAILWAY_TOKEN|railway[_-]?api[_-]?token)\s*[:=]\s*["'`]([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})["'`]/gi,
|
|
5709
|
+
"VC171",
|
|
5710
|
+
this.title,
|
|
5711
|
+
"critical",
|
|
5712
|
+
"Move the Railway token to an environment variable (RAILWAY_TOKEN). Rotate at railway.app \u2192 Account Settings \u2192 Tokens."
|
|
5713
|
+
);
|
|
5714
|
+
}
|
|
5715
|
+
};
|
|
5716
|
+
var hardcodedFlyToken = {
|
|
5717
|
+
id: "VC172",
|
|
5718
|
+
title: "Hardcoded Fly.io Auth Token",
|
|
5719
|
+
severity: "critical",
|
|
5720
|
+
category: "Secrets",
|
|
5721
|
+
description: "Fly.io tokens (FlyV1 fm2_*) grant access to deploy and configure any app in your organization, including modifying secrets and machines. A leaked token can compromise production infrastructure.",
|
|
5722
|
+
check(content, filePath) {
|
|
5723
|
+
return secretRuleCheck(
|
|
5724
|
+
content,
|
|
5725
|
+
filePath,
|
|
5726
|
+
/FlyV1\s+fm2_[A-Za-z0-9+/=_\-]{40,}/g,
|
|
5727
|
+
"VC172",
|
|
5728
|
+
this.title,
|
|
5729
|
+
"critical",
|
|
5730
|
+
"Move the Fly.io token to an environment variable (FLY_API_TOKEN). Rotate via `fly tokens revoke` and `fly tokens create deploy`."
|
|
5731
|
+
);
|
|
5732
|
+
}
|
|
5733
|
+
};
|
|
5734
|
+
var hardcodedAlgoliaAdminKey = {
|
|
5735
|
+
id: "VC173",
|
|
5736
|
+
title: "Hardcoded Algolia Admin API Key",
|
|
5737
|
+
severity: "critical",
|
|
5738
|
+
category: "Secrets",
|
|
5739
|
+
description: "Algolia admin API keys grant full access to manage indices, modify records, and create/delete API keys. A leaked admin key exposes all search data and lets attackers replace indexed content.",
|
|
5740
|
+
check(content, filePath) {
|
|
5741
|
+
return contextSecretRuleCheck(
|
|
5742
|
+
content,
|
|
5743
|
+
filePath,
|
|
5744
|
+
/(?:ALGOLIA_ADMIN_(?:API_)?KEY|algolia[_-]?admin[_-]?(?:api[_-]?)?key)\s*[:=]\s*["'`]([a-f0-9]{32})["'`]/gi,
|
|
5745
|
+
"VC173",
|
|
5746
|
+
this.title,
|
|
5747
|
+
"critical",
|
|
5748
|
+
"Move the Algolia admin key to a server-side environment variable (ALGOLIA_ADMIN_KEY). NEVER expose admin keys to the client \u2014 use search-only API keys for browser code. Rotate at dashboard.algolia.com \u2192 API Keys."
|
|
5749
|
+
);
|
|
5750
|
+
}
|
|
5751
|
+
};
|
|
5752
|
+
var hardcodedQdrantKey = {
|
|
5753
|
+
id: "VC174",
|
|
5754
|
+
title: "Hardcoded Qdrant API Key",
|
|
5755
|
+
severity: "high",
|
|
5756
|
+
category: "Secrets",
|
|
5757
|
+
description: "Qdrant API keys grant read/write access to all vector collections in your cluster. A leaked key exposes your vector database and the embeddings stored in it.",
|
|
5758
|
+
check(content, filePath) {
|
|
5759
|
+
return contextSecretRuleCheck(
|
|
5760
|
+
content,
|
|
5761
|
+
filePath,
|
|
5762
|
+
/(?:QDRANT_API_KEY|qdrant[_-]?api[_-]?key)\s*[:=]\s*["'`]([A-Za-z0-9_\-\.]{30,})["'`]/gi,
|
|
5763
|
+
"VC174",
|
|
5764
|
+
this.title,
|
|
5765
|
+
"high",
|
|
5766
|
+
"Move the Qdrant API key to an environment variable (QDRANT_API_KEY). Rotate in your Qdrant Cloud dashboard \u2192 API Keys."
|
|
5767
|
+
);
|
|
5768
|
+
}
|
|
5769
|
+
};
|
|
5770
|
+
var hardcodedWeaviateKey = {
|
|
5771
|
+
id: "VC175",
|
|
5772
|
+
title: "Hardcoded Weaviate API Key",
|
|
5773
|
+
severity: "high",
|
|
5774
|
+
category: "Secrets",
|
|
5775
|
+
description: "Weaviate API keys grant read/write access to all classes and objects in your vector database. A leaked key exposes embeddings and metadata for every document indexed.",
|
|
5776
|
+
check(content, filePath) {
|
|
5777
|
+
return contextSecretRuleCheck(
|
|
5778
|
+
content,
|
|
5779
|
+
filePath,
|
|
5780
|
+
/(?:WEAVIATE_API_KEY|weaviate[_-]?api[_-]?key)\s*[:=]\s*["'`]([A-Za-z0-9_\-]{20,})["'`]/gi,
|
|
5781
|
+
"VC175",
|
|
5782
|
+
this.title,
|
|
5783
|
+
"high",
|
|
5784
|
+
"Move the Weaviate API key to an environment variable (WEAVIATE_API_KEY). Rotate in your Weaviate Cloud Services console \u2192 Cluster details."
|
|
5785
|
+
);
|
|
5786
|
+
}
|
|
5787
|
+
};
|
|
5788
|
+
var hardcodedLinearKey = {
|
|
5789
|
+
id: "VC176",
|
|
5790
|
+
title: "Hardcoded Linear API Key",
|
|
5791
|
+
severity: "high",
|
|
5792
|
+
category: "Secrets",
|
|
5793
|
+
description: "Linear API keys (lin_api_*) grant read/write access to all issues, projects, and team data. A leaked key exposes private roadmap, customer-reported bugs, and internal discussion.",
|
|
5794
|
+
check(content, filePath) {
|
|
5795
|
+
return secretRuleCheck(
|
|
5796
|
+
content,
|
|
5797
|
+
filePath,
|
|
5798
|
+
/lin_(?:api|oauth)_[A-Za-z0-9]{40,}/g,
|
|
5799
|
+
"VC176",
|
|
5800
|
+
this.title,
|
|
5801
|
+
"high",
|
|
5802
|
+
"Move the Linear key to an environment variable (LINEAR_API_KEY). Rotate at linear.app \u2192 Settings \u2192 API \u2192 Personal API keys."
|
|
5803
|
+
);
|
|
5804
|
+
}
|
|
5805
|
+
};
|
|
5806
|
+
var hardcodedNotionKey = {
|
|
5807
|
+
id: "VC177",
|
|
5808
|
+
title: "Hardcoded Notion Integration Token",
|
|
5809
|
+
severity: "high",
|
|
5810
|
+
category: "Secrets",
|
|
5811
|
+
description: "Notion integration tokens (secret_*) grant access to every page and database the integration is connected to, including content, comments, and member info. A leaked token exposes private workspace data.",
|
|
5812
|
+
check(content, filePath) {
|
|
5813
|
+
return secretRuleCheck(
|
|
5814
|
+
content,
|
|
5815
|
+
filePath,
|
|
5816
|
+
/secret_[A-Za-z0-9]{43}/g,
|
|
5817
|
+
"VC177",
|
|
5818
|
+
this.title,
|
|
5819
|
+
"high",
|
|
5820
|
+
"Move the Notion token to an environment variable (NOTION_TOKEN). Rotate at notion.so/profile/integrations."
|
|
5821
|
+
);
|
|
5822
|
+
}
|
|
5823
|
+
};
|
|
5824
|
+
var hardcodedDiscordToken = {
|
|
5825
|
+
id: "VC178",
|
|
5826
|
+
title: "Hardcoded Discord Bot Token",
|
|
5827
|
+
severity: "critical",
|
|
5828
|
+
category: "Secrets",
|
|
5829
|
+
description: "Discord bot tokens grant full control over the bot's actions in every guild it has joined: reading messages, sending messages, managing channels, and accessing member data per intent scopes. A leaked token can be used to spam, exfiltrate messages, or take over channels.",
|
|
5830
|
+
check(content, filePath) {
|
|
5831
|
+
return secretRuleCheck(
|
|
5832
|
+
content,
|
|
5833
|
+
filePath,
|
|
5834
|
+
/[MNO][A-Za-z\d_\-]{23,28}\.[\w\-]{6,7}\.[\w\-]{27,38}/g,
|
|
5835
|
+
"VC178",
|
|
5836
|
+
this.title,
|
|
5837
|
+
"critical",
|
|
5838
|
+
"Move the Discord token to an environment variable (DISCORD_TOKEN). Reset immediately at discord.com/developers/applications \u2192 your bot \u2192 Bot \u2192 Reset Token."
|
|
5839
|
+
);
|
|
5840
|
+
}
|
|
5841
|
+
};
|
|
5842
|
+
var hardcodedIntercomToken = {
|
|
5843
|
+
id: "VC179",
|
|
5844
|
+
title: "Hardcoded Intercom Access Token",
|
|
5845
|
+
severity: "high",
|
|
5846
|
+
category: "Secrets",
|
|
5847
|
+
description: "Intercom access tokens grant access to all customer conversations, contact records, and company data. A leaked token exposes customer PII and support history.",
|
|
5848
|
+
check(content, filePath) {
|
|
5849
|
+
return contextSecretRuleCheck(
|
|
5850
|
+
content,
|
|
5851
|
+
filePath,
|
|
5852
|
+
/(?:INTERCOM_ACCESS_TOKEN|intercom[_-]?access[_-]?token|intercom[_-]?api[_-]?key)\s*[:=]\s*["'`]([A-Za-z0-9_=+/\-]{50,})["'`]/gi,
|
|
5853
|
+
"VC179",
|
|
5854
|
+
this.title,
|
|
5855
|
+
"high",
|
|
5856
|
+
"Move the Intercom token to an environment variable (INTERCOM_ACCESS_TOKEN). Rotate at app.intercom.com \u2192 Settings \u2192 Developers \u2192 Apps."
|
|
5857
|
+
);
|
|
5858
|
+
}
|
|
5859
|
+
};
|
|
5860
|
+
var hardcodedSentryAuthToken = {
|
|
5861
|
+
id: "VC180",
|
|
5862
|
+
title: "Hardcoded Sentry Auth Token",
|
|
5863
|
+
severity: "high",
|
|
5864
|
+
category: "Secrets",
|
|
5865
|
+
description: "Sentry auth tokens (sntrys_*) grant access to error data across every project the token is scoped to, plus the ability to manage releases, projects, and source maps. A leaked token exposes stack traces, PII captured in errors, and lets attackers tamper with release artifacts.",
|
|
5866
|
+
check(content, filePath) {
|
|
5867
|
+
return secretRuleCheck(
|
|
5868
|
+
content,
|
|
5869
|
+
filePath,
|
|
5870
|
+
/sntrys_[A-Za-z0-9_]{40,}/g,
|
|
5871
|
+
"VC180",
|
|
5872
|
+
this.title,
|
|
5873
|
+
"high",
|
|
5874
|
+
"Move the Sentry auth token to an environment variable (SENTRY_AUTH_TOKEN). Rotate at sentry.io \u2192 User Settings \u2192 Auth Tokens."
|
|
5875
|
+
);
|
|
5876
|
+
}
|
|
5877
|
+
};
|
|
5878
|
+
var hardcodedLogtailToken = {
|
|
5879
|
+
id: "VC181",
|
|
5880
|
+
title: "Hardcoded Better Stack (Logtail) Source Token",
|
|
5881
|
+
severity: "high",
|
|
5882
|
+
category: "Secrets",
|
|
5883
|
+
description: "Better Stack / Logtail source tokens grant the ability to write logs to your account. A leaked token lets attackers fill your log retention with junk data, mask their own activity in noise, or rack up your ingestion bill.",
|
|
5884
|
+
check(content, filePath) {
|
|
5885
|
+
return contextSecretRuleCheck(
|
|
5886
|
+
content,
|
|
5887
|
+
filePath,
|
|
5888
|
+
/(?:LOGTAIL_(?:SOURCE_)?TOKEN|BETTERSTACK_(?:SOURCE_)?TOKEN|logtail[_-]?(?:source[_-]?)?token)\s*[:=]\s*["'`]([A-Za-z0-9]{20,})["'`]/gi,
|
|
5889
|
+
"VC181",
|
|
5890
|
+
this.title,
|
|
5891
|
+
"high",
|
|
5892
|
+
"Move the Logtail token to an environment variable (LOGTAIL_SOURCE_TOKEN). Rotate in betterstack.com \u2192 Sources \u2192 Edit."
|
|
5893
|
+
);
|
|
5894
|
+
}
|
|
5895
|
+
};
|
|
5896
|
+
var hardcodedHighlightKey = {
|
|
5897
|
+
id: "VC182",
|
|
5898
|
+
title: "Hardcoded Highlight.io Project ID / API Key",
|
|
5899
|
+
severity: "high",
|
|
5900
|
+
category: "Secrets",
|
|
5901
|
+
description: "Highlight.io API keys grant access to recorded session replays, error data, and console logs from your users' browsers. A leaked key exposes user behavior data and any sensitive content captured in replays.",
|
|
5902
|
+
check(content, filePath) {
|
|
5903
|
+
return contextSecretRuleCheck(
|
|
5904
|
+
content,
|
|
5905
|
+
filePath,
|
|
5906
|
+
/(?:HIGHLIGHT_API_KEY|HIGHLIGHT_PROJECT_ID|highlight[_-]?(?:api[_-]?key|project[_-]?id))\s*[:=]\s*["'`]([A-Za-z0-9_\-]{20,})["'`]/gi,
|
|
5907
|
+
"VC182",
|
|
5908
|
+
this.title,
|
|
5909
|
+
"high",
|
|
5910
|
+
"Move the Highlight key to an environment variable (HIGHLIGHT_API_KEY). Rotate at app.highlight.io \u2192 Project Settings \u2192 API Keys."
|
|
5911
|
+
);
|
|
5912
|
+
}
|
|
5913
|
+
};
|
|
5914
|
+
var hardcodedPlivoToken = {
|
|
5915
|
+
id: "VC183",
|
|
5916
|
+
title: "Hardcoded Plivo Auth Token",
|
|
5917
|
+
severity: "high",
|
|
5918
|
+
category: "Secrets",
|
|
5919
|
+
description: "Plivo auth tokens grant the ability to send SMS, place calls, and access call/message logs. A leaked token enables toll fraud and unauthorized communications billed to your account.",
|
|
5920
|
+
check(content, filePath) {
|
|
5921
|
+
return contextSecretRuleCheck(
|
|
5922
|
+
content,
|
|
5923
|
+
filePath,
|
|
5924
|
+
/(?:PLIVO_AUTH_TOKEN|plivo[_-]?auth[_-]?token)\s*[:=]\s*["'`]([A-Za-z0-9]{40,})["'`]/gi,
|
|
5925
|
+
"VC183",
|
|
5926
|
+
this.title,
|
|
5927
|
+
"high",
|
|
5928
|
+
"Move the Plivo token to an environment variable (PLIVO_AUTH_TOKEN). Rotate at console.plivo.com \u2192 Account \u2192 API Keys & Credentials."
|
|
5929
|
+
);
|
|
5930
|
+
}
|
|
5931
|
+
};
|
|
5932
|
+
var GHA_WORKFLOW_RE = /\.github\/workflows\/.*\.(yml|yaml)$/;
|
|
5933
|
+
var ghaPullRequestTargetCheckout = {
|
|
5934
|
+
id: "VC184",
|
|
5935
|
+
title: "GitHub Actions: pull_request_target with checkout of PR head",
|
|
5936
|
+
severity: "critical",
|
|
5937
|
+
category: "Supply Chain",
|
|
5938
|
+
description: "Workflows triggered by `pull_request_target` run with the base repository's secrets and write permissions. Checking out the PR's head ref (or sha) and then executing any code from that checkout \u2014 install scripts, build steps, lint hooks \u2014 gives attackers in any forked PR full code execution with your repository's secrets. This is the canonical \"pwn request\" attack pattern.",
|
|
5939
|
+
check(content, filePath) {
|
|
5940
|
+
if (!GHA_WORKFLOW_RE.test(filePath)) return [];
|
|
5941
|
+
if (!/(^|\n)\s*(?:on\s*:\s*\[?[^\]]*pull_request_target|pull_request_target\s*:)/.test(content)) {
|
|
5942
|
+
return [];
|
|
5943
|
+
}
|
|
5944
|
+
const findings = [];
|
|
5945
|
+
const checkoutPattern = /uses\s*:\s*actions\/checkout@[^\n]*[\s\S]{0,400}?ref\s*:\s*\$\{\{\s*github\.event\.pull_request\.head\.(?:ref|sha)\s*\}\}/g;
|
|
5946
|
+
let m;
|
|
5947
|
+
while ((m = checkoutPattern.exec(content)) !== null) {
|
|
5948
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
5949
|
+
findings.push({
|
|
5950
|
+
rule: "VC184",
|
|
5951
|
+
title: ghaPullRequestTargetCheckout.title,
|
|
5952
|
+
severity: "critical",
|
|
5953
|
+
category: "Supply Chain",
|
|
5954
|
+
file: filePath,
|
|
5955
|
+
line: lineNum,
|
|
5956
|
+
snippet: getSnippet(content, lineNum),
|
|
5957
|
+
fix: "Either (a) switch the trigger to `pull_request` (no secrets, but safe), or (b) keep `pull_request_target` but check out only the BASE ref (don't pass `ref: ${{ github.event.pull_request.head.* }}`), or (c) split into two workflows: a `pull_request` workflow that does the build/test, and a `pull_request_target` workflow that only does the privileged step (commenting, labeling) without executing PR code."
|
|
5958
|
+
});
|
|
5959
|
+
}
|
|
5960
|
+
return findings;
|
|
5961
|
+
}
|
|
5962
|
+
};
|
|
5963
|
+
var ghaPermissionsWriteAll = {
|
|
5964
|
+
id: "VC185",
|
|
5965
|
+
title: "GitHub Actions: permissions set to write-all",
|
|
5966
|
+
severity: "high",
|
|
5967
|
+
category: "Supply Chain",
|
|
5968
|
+
description: "`permissions: write-all` (or omitting `permissions` entirely on a public repo with default-permissive settings) gives every step in the workflow write access to the repo, packages, deployments, and more. If any action in the workflow is compromised \u2014 directly or via a transitive dependency \u2014 it can push commits, modify releases, and exfiltrate secrets. Default-deny + grant only what each job needs.",
|
|
5969
|
+
check(content, filePath) {
|
|
5970
|
+
if (!GHA_WORKFLOW_RE.test(filePath)) return [];
|
|
5971
|
+
const findings = [];
|
|
5972
|
+
const pattern = /(^|\n)(\s*)permissions\s*:\s*write-all\s*(?:#[^\n]*)?$/gm;
|
|
5973
|
+
let m;
|
|
5974
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
5975
|
+
const lineNum = content.substring(0, m.index + m[1].length).split("\n").length;
|
|
5976
|
+
findings.push({
|
|
5977
|
+
rule: "VC185",
|
|
5978
|
+
title: ghaPermissionsWriteAll.title,
|
|
5979
|
+
severity: "high",
|
|
5980
|
+
category: "Supply Chain",
|
|
5981
|
+
file: filePath,
|
|
5982
|
+
line: lineNum,
|
|
5983
|
+
snippet: getSnippet(content, lineNum),
|
|
5984
|
+
fix: "Replace `permissions: write-all` with an explicit allowlist: `permissions:\\n contents: read\\n pull-requests: write` (or whichever scopes the workflow actually needs). See https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs."
|
|
5985
|
+
});
|
|
5986
|
+
}
|
|
5987
|
+
return findings;
|
|
5988
|
+
}
|
|
5989
|
+
};
|
|
5990
|
+
var ghaExpressionInjection = {
|
|
5991
|
+
id: "VC186",
|
|
5992
|
+
title: "GitHub Actions: expression injection in run block",
|
|
5993
|
+
severity: "high",
|
|
5994
|
+
category: "Injection",
|
|
5995
|
+
description: "Interpolating `${{ github.event.* }}` (issue title, PR body, commit message, branch name, etc.) directly into a shell script in a `run:` block lets attackers inject arbitrary shell commands by crafting the trigger payload. Same class of bug as SQL injection \u2014 the value is untrusted and gets evaluated by the shell.",
|
|
5996
|
+
check(content, filePath) {
|
|
5997
|
+
if (!GHA_WORKFLOW_RE.test(filePath)) return [];
|
|
5998
|
+
const findings = [];
|
|
5999
|
+
const pattern = /run\s*:\s*(?:[\|>][^\n]*\n[\s\S]*?|.*?)\$\{\{\s*github\.(?:event\.(?:issue|pull_request|comment|review|discussion)\.[^}]*|head_ref)\s*\}\}/g;
|
|
6000
|
+
let m;
|
|
6001
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6002
|
+
const interpStart = m[0].lastIndexOf("${{");
|
|
6003
|
+
const absIdx = m.index + interpStart;
|
|
6004
|
+
const lineNum = content.substring(0, absIdx).split("\n").length;
|
|
6005
|
+
findings.push({
|
|
6006
|
+
rule: "VC186",
|
|
6007
|
+
title: ghaExpressionInjection.title,
|
|
6008
|
+
severity: "high",
|
|
6009
|
+
category: "Injection",
|
|
6010
|
+
file: filePath,
|
|
6011
|
+
line: lineNum,
|
|
6012
|
+
snippet: getSnippet(content, lineNum),
|
|
6013
|
+
fix: 'Don\'t interpolate untrusted `github.event.*` values directly into shell scripts. Instead, pass them via env vars: `env:\\n TITLE: ${{ github.event.issue.title }}\\nrun: echo "$TITLE"`. Env var expansion in the shell is safe; expression interpolation is not.'
|
|
6014
|
+
});
|
|
6015
|
+
pattern.lastIndex = m.index + m[0].length;
|
|
6016
|
+
}
|
|
6017
|
+
return findings;
|
|
6018
|
+
}
|
|
6019
|
+
};
|
|
6020
|
+
var ghaThirdPartyActionWithSecrets = {
|
|
6021
|
+
id: "VC187",
|
|
6022
|
+
title: "GitHub Actions: secrets passed to third-party action",
|
|
6023
|
+
severity: "medium",
|
|
6024
|
+
category: "Supply Chain",
|
|
6025
|
+
description: "Passing repository secrets (`${{ secrets.* }}`) via the `with:` block to a third-party action means the action's source code \u2014 and any transitive dependencies it pulls \u2014 has access to those secrets. The 2025 tj-actions/changed-files supply-chain attack stole secrets exactly this way. Common when intentional (AWS, Cloudflare, GCP credential actions) but worth flagging for review.",
|
|
6026
|
+
check(content, filePath) {
|
|
6027
|
+
if (!GHA_WORKFLOW_RE.test(filePath)) return [];
|
|
6028
|
+
const findings = [];
|
|
6029
|
+
const pattern = /uses\s*:\s*(?!actions\/|github\/|aws-actions\/|azure\/|google-github-actions\/|hashicorp\/)([\w\-]+\/[\w\-./]+)@[^\n]*\n[\s\S]{0,800}?with\s*:[\s\S]{0,800}?\$\{\{\s*secrets\./g;
|
|
6030
|
+
let m;
|
|
6031
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6032
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6033
|
+
findings.push({
|
|
6034
|
+
rule: "VC187",
|
|
6035
|
+
title: ghaThirdPartyActionWithSecrets.title,
|
|
6036
|
+
severity: "medium",
|
|
6037
|
+
category: "Supply Chain",
|
|
6038
|
+
file: filePath,
|
|
6039
|
+
line: lineNum,
|
|
6040
|
+
snippet: getSnippet(content, lineNum),
|
|
6041
|
+
fix: `Audit the third-party action source (${m[1]}) before passing secrets. Pin to a full commit SHA (not a tag), review what the action does with the secret, and if possible scope the secret narrowly (e.g. a deploy-only token, not your full GitHub PAT). Consider replacing with an official action where one exists.`
|
|
6042
|
+
});
|
|
6043
|
+
pattern.lastIndex = m.index + m[0].length;
|
|
6044
|
+
}
|
|
6045
|
+
return findings;
|
|
6046
|
+
}
|
|
6047
|
+
};
|
|
6048
|
+
var DOCKERFILE_RE = /(?:^|\/)Dockerfile(\..+)?$|\.dockerfile$/i;
|
|
6049
|
+
var dockerfileADDInsteadOfCOPY = {
|
|
6050
|
+
id: "VC188",
|
|
6051
|
+
title: "Dockerfile: ADD used for local files instead of COPY",
|
|
6052
|
+
severity: "low",
|
|
6053
|
+
category: "Configuration",
|
|
6054
|
+
description: "`ADD` has two features `COPY` doesn't: it auto-extracts tar archives and can fetch URLs. Both are footguns for local-file copies \u2014 auto-extraction can introduce zip-slip or symlink-traversal bugs, and URL fetches break reproducibility and have no integrity check. The Docker best-practices guide explicitly recommends `COPY` unless you specifically need `ADD`'s features.",
|
|
6055
|
+
check(content, filePath) {
|
|
6056
|
+
if (!DOCKERFILE_RE.test(filePath)) return [];
|
|
6057
|
+
const findings = [];
|
|
6058
|
+
const lines = content.split("\n");
|
|
6059
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6060
|
+
const line = lines[i];
|
|
6061
|
+
const m = /^\s*ADD\s+(?:--[\w-]+(?:=\S+)?\s+)*(\S+)/i.exec(line);
|
|
6062
|
+
if (!m) continue;
|
|
6063
|
+
if (line.trim().startsWith("#")) continue;
|
|
6064
|
+
const src = m[1];
|
|
6065
|
+
if (/^https?:\/\//.test(src)) continue;
|
|
6066
|
+
if (/\.(tar(\.(gz|bz2|xz|zst))?|tgz|tbz|txz)\b/i.test(src)) continue;
|
|
6067
|
+
findings.push({
|
|
6068
|
+
rule: "VC188",
|
|
6069
|
+
title: dockerfileADDInsteadOfCOPY.title,
|
|
6070
|
+
severity: "low",
|
|
6071
|
+
category: "Configuration",
|
|
6072
|
+
file: filePath,
|
|
6073
|
+
line: i + 1,
|
|
6074
|
+
snippet: getSnippet(content, i + 1),
|
|
6075
|
+
fix: "Replace `ADD` with `COPY` for local-file copies. `ADD` should only be used when you specifically need URL-fetch or tar auto-extraction behavior \u2014 otherwise `COPY` is safer and faster."
|
|
6076
|
+
});
|
|
6077
|
+
}
|
|
6078
|
+
return findings;
|
|
6079
|
+
}
|
|
6080
|
+
};
|
|
6081
|
+
var dockerfileUnverifiedShellPipe = {
|
|
6082
|
+
id: "VC189",
|
|
6083
|
+
title: "Dockerfile: RUN with unverified shell pipe (curl|sh, wget|bash)",
|
|
6084
|
+
severity: "high",
|
|
6085
|
+
category: "Supply Chain",
|
|
6086
|
+
description: "`RUN curl https://example.com/install.sh | sh` (or `wget ... | bash`) downloads and executes a remote script with no integrity check. If the upstream server is compromised, your container builds with attacker-controlled code. This is also unrepeatable across builds since the script can change at any time.",
|
|
6087
|
+
check(content, filePath) {
|
|
6088
|
+
if (!DOCKERFILE_RE.test(filePath)) return [];
|
|
6089
|
+
const findings = [];
|
|
6090
|
+
const lines = content.split("\n");
|
|
6091
|
+
let inRun = false;
|
|
6092
|
+
let runStart = -1;
|
|
6093
|
+
let buffer = "";
|
|
6094
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6095
|
+
const raw = lines[i];
|
|
6096
|
+
if (raw.trim().startsWith("#")) continue;
|
|
6097
|
+
const startMatch = /^\s*RUN\s+(.*)$/i.exec(raw);
|
|
6098
|
+
if (startMatch) {
|
|
6099
|
+
if (inRun && buffer && /(?:curl|wget)\b[^|]*\|\s*(?:bash|sh|zsh)\b/i.test(buffer)) {
|
|
6100
|
+
findings.push({
|
|
6101
|
+
rule: "VC189",
|
|
6102
|
+
title: dockerfileUnverifiedShellPipe.title,
|
|
6103
|
+
severity: "high",
|
|
6104
|
+
category: "Supply Chain",
|
|
6105
|
+
file: filePath,
|
|
6106
|
+
line: runStart + 1,
|
|
6107
|
+
snippet: getSnippet(content, runStart + 1),
|
|
6108
|
+
fix: "Don't pipe untrusted remote scripts into a shell. Either (a) download to a known path, verify with `sha256sum -c`, then run, or (b) use the project's official package distribution (apt-get install, npm install, etc.) which is signed and pinned."
|
|
6109
|
+
});
|
|
6110
|
+
}
|
|
6111
|
+
inRun = true;
|
|
6112
|
+
runStart = i;
|
|
6113
|
+
buffer = startMatch[1];
|
|
6114
|
+
if (!buffer.endsWith("\\")) {
|
|
6115
|
+
if (/(?:curl|wget)\b[^|]*\|\s*(?:bash|sh|zsh)\b/i.test(buffer)) {
|
|
6116
|
+
findings.push({
|
|
6117
|
+
rule: "VC189",
|
|
6118
|
+
title: dockerfileUnverifiedShellPipe.title,
|
|
6119
|
+
severity: "high",
|
|
6120
|
+
category: "Supply Chain",
|
|
6121
|
+
file: filePath,
|
|
6122
|
+
line: i + 1,
|
|
6123
|
+
snippet: getSnippet(content, i + 1),
|
|
6124
|
+
fix: "Don't pipe untrusted remote scripts into a shell. Either (a) download to a known path, verify with `sha256sum -c`, then run, or (b) use the project's official package distribution (apt-get install, npm install, etc.) which is signed and pinned."
|
|
6125
|
+
});
|
|
6126
|
+
}
|
|
6127
|
+
inRun = false;
|
|
6128
|
+
buffer = "";
|
|
6129
|
+
}
|
|
6130
|
+
} else if (inRun) {
|
|
6131
|
+
buffer += " " + raw.trim().replace(/\\$/, "");
|
|
6132
|
+
if (!raw.trim().endsWith("\\")) {
|
|
6133
|
+
if (/(?:curl|wget)\b[^|]*\|\s*(?:bash|sh|zsh)\b/i.test(buffer)) {
|
|
6134
|
+
findings.push({
|
|
6135
|
+
rule: "VC189",
|
|
6136
|
+
title: dockerfileUnverifiedShellPipe.title,
|
|
6137
|
+
severity: "high",
|
|
6138
|
+
category: "Supply Chain",
|
|
6139
|
+
file: filePath,
|
|
6140
|
+
line: runStart + 1,
|
|
6141
|
+
snippet: getSnippet(content, runStart + 1),
|
|
6142
|
+
fix: "Don't pipe untrusted remote scripts into a shell. Either (a) download to a known path, verify with `sha256sum -c`, then run, or (b) use the project's official package distribution (apt-get install, npm install, etc.) which is signed and pinned."
|
|
6143
|
+
});
|
|
6144
|
+
}
|
|
6145
|
+
inRun = false;
|
|
6146
|
+
buffer = "";
|
|
6147
|
+
}
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
return findings;
|
|
6151
|
+
}
|
|
6152
|
+
};
|
|
6153
|
+
var dockerfileMissingHealthcheck = {
|
|
6154
|
+
id: "VC190",
|
|
6155
|
+
title: "Dockerfile: missing HEALTHCHECK directive",
|
|
6156
|
+
severity: "low",
|
|
6157
|
+
category: "Configuration",
|
|
6158
|
+
description: "`HEALTHCHECK` lets Docker (and orchestrators like Kubernetes via probes) detect when a container is alive but unable to serve traffic \u2014 e.g. a web server in a deadlock or a DB connection pool that's exhausted. Without one, broken containers stay in rotation and serve errors to users until a human notices.",
|
|
6159
|
+
check(content, filePath) {
|
|
6160
|
+
if (!DOCKERFILE_RE.test(filePath)) return [];
|
|
6161
|
+
if (!/^\s*FROM\s+/im.test(content)) return [];
|
|
6162
|
+
if (!/^\s*(CMD|ENTRYPOINT)\s+/im.test(content)) return [];
|
|
6163
|
+
if (/^\s*HEALTHCHECK\s+/im.test(content)) return [];
|
|
6164
|
+
const fromLines = [...content.matchAll(/^\s*FROM\s+\S+(?:\s+as\s+(\w+))?/gim)];
|
|
6165
|
+
const lastFrom = fromLines[fromLines.length - 1];
|
|
6166
|
+
if (lastFrom && lastFrom[1] && /^(builder|build|deps|prep|base)$/i.test(lastFrom[1])) return [];
|
|
6167
|
+
const cmdMatch = [...content.matchAll(/^\s*(CMD|ENTRYPOINT)\s+/gim)].pop();
|
|
6168
|
+
if (!cmdMatch || cmdMatch.index === void 0) return [];
|
|
6169
|
+
const lineNum = content.substring(0, cmdMatch.index).split("\n").length;
|
|
6170
|
+
return [{
|
|
6171
|
+
rule: "VC190",
|
|
6172
|
+
title: dockerfileMissingHealthcheck.title,
|
|
6173
|
+
severity: "low",
|
|
6174
|
+
category: "Configuration",
|
|
6175
|
+
file: filePath,
|
|
6176
|
+
line: lineNum,
|
|
6177
|
+
snippet: getSnippet(content, lineNum),
|
|
6178
|
+
fix: "Add a HEALTHCHECK directive before the final CMD/ENTRYPOINT. Example for a web app: `HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD curl -fsS http://localhost:3000/health || exit 1`."
|
|
6179
|
+
}];
|
|
6180
|
+
}
|
|
6181
|
+
};
|
|
6182
|
+
var PY_FILE_RE = /\.py$/;
|
|
6183
|
+
var pyRequestsVerifyFalse = {
|
|
6184
|
+
id: "VC191",
|
|
6185
|
+
title: "Python: requests called with verify=False (TLS verification disabled)",
|
|
6186
|
+
severity: "high",
|
|
6187
|
+
category: "Cryptography",
|
|
6188
|
+
description: "`requests.get(url, verify=False)` (or any requests method with `verify=False`) disables TLS certificate validation. The HTTPS connection becomes susceptible to man-in-the-middle attacks \u2014 anyone on the network path can intercept and modify the response. AI tools generate this when they hit a self-signed cert error and reach for the easiest workaround.",
|
|
6189
|
+
check(content, filePath) {
|
|
6190
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6191
|
+
if (isTestFile(filePath)) return [];
|
|
6192
|
+
const findings = [];
|
|
6193
|
+
const pattern = /requests\.(?:get|post|put|delete|patch|head|options|request|Session\(\)\.[a-z]+)\s*\([^)]*verify\s*=\s*False/gi;
|
|
6194
|
+
let m;
|
|
6195
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6196
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6197
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6198
|
+
findings.push({
|
|
6199
|
+
rule: "VC191",
|
|
6200
|
+
title: pyRequestsVerifyFalse.title,
|
|
6201
|
+
severity: "high",
|
|
6202
|
+
category: "Cryptography",
|
|
6203
|
+
file: filePath,
|
|
6204
|
+
line: lineNum,
|
|
6205
|
+
snippet: getSnippet(content, lineNum),
|
|
6206
|
+
fix: "Remove `verify=False`. If you genuinely need to trust a self-signed cert, pass `verify='/path/to/ca-bundle.pem'` so only that specific CA is trusted. Don't disable validation globally."
|
|
6207
|
+
});
|
|
6208
|
+
}
|
|
6209
|
+
return findings;
|
|
6210
|
+
}
|
|
6211
|
+
};
|
|
6212
|
+
var pyJinja2AutoescapeOff = {
|
|
6213
|
+
id: "VC192",
|
|
6214
|
+
title: "Python: Jinja2 Environment with autoescape=False",
|
|
6215
|
+
severity: "high",
|
|
6216
|
+
category: "Injection",
|
|
6217
|
+
description: "Jinja2 doesn't auto-escape by default \u2014 you have to opt in. Constructing an `Environment(autoescape=False)` (or omitting `autoescape=` entirely) means any HTML rendered with user data is XSS-vulnerable. The Flask integration sets autoescape correctly for `.html` templates, but standalone Jinja2 use has the unsafe default.",
|
|
6218
|
+
check(content, filePath) {
|
|
6219
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6220
|
+
if (isTestFile(filePath)) return [];
|
|
6221
|
+
const usesJinja2 = /\bjinja2\b/.test(content) || /\b(?:Environment|Template)\s*\(/.test(content);
|
|
6222
|
+
if (!usesJinja2) return [];
|
|
6223
|
+
const findings = [];
|
|
6224
|
+
const pattern = /\bautoescape\s*=\s*False\b/g;
|
|
6225
|
+
let m;
|
|
6226
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6227
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6228
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6229
|
+
findings.push({
|
|
6230
|
+
rule: "VC192",
|
|
6231
|
+
title: pyJinja2AutoescapeOff.title,
|
|
6232
|
+
severity: "high",
|
|
6233
|
+
category: "Injection",
|
|
6234
|
+
file: filePath,
|
|
6235
|
+
line: lineNum,
|
|
6236
|
+
snippet: getSnippet(content, lineNum),
|
|
6237
|
+
fix: "Set `autoescape=True` (or use `select_autoescape(['html', 'htm', 'xml'])` for finer control). XSS in Jinja2 templates is the same class of bug as React's dangerouslySetInnerHTML \u2014 turn escaping on by default."
|
|
6238
|
+
});
|
|
6239
|
+
}
|
|
6240
|
+
return findings;
|
|
6241
|
+
}
|
|
6242
|
+
};
|
|
6243
|
+
var pyTempfileMktemp = {
|
|
6244
|
+
id: "VC193",
|
|
6245
|
+
title: "Python: tempfile.mktemp() \u2014 TOCTOU race",
|
|
6246
|
+
severity: "medium",
|
|
6247
|
+
category: "Configuration",
|
|
6248
|
+
description: "`tempfile.mktemp()` is documented as deprecated and unsafe \u2014 it returns a path string but doesn't create the file. Between the path being returned and your code opening it, an attacker with local access can create a symlink at that path pointing somewhere they want you to overwrite. Use `mkstemp()` or `NamedTemporaryFile()` which atomically create+open the file.",
|
|
6249
|
+
check(content, filePath) {
|
|
6250
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6251
|
+
if (isTestFile(filePath)) return [];
|
|
6252
|
+
const findings = [];
|
|
6253
|
+
const pattern = /\btempfile\.mktemp\s*\(/g;
|
|
6254
|
+
let m;
|
|
6255
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6256
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6257
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6258
|
+
findings.push({
|
|
6259
|
+
rule: "VC193",
|
|
6260
|
+
title: pyTempfileMktemp.title,
|
|
6261
|
+
severity: "medium",
|
|
6262
|
+
category: "Configuration",
|
|
6263
|
+
file: filePath,
|
|
6264
|
+
line: lineNum,
|
|
6265
|
+
snippet: getSnippet(content, lineNum),
|
|
6266
|
+
fix: "Replace `tempfile.mktemp()` with `tempfile.mkstemp()` (returns an open fd + path) or `tempfile.NamedTemporaryFile()` (context manager). Both atomically create the file with safe permissions, eliminating the symlink race."
|
|
6267
|
+
});
|
|
6268
|
+
}
|
|
6269
|
+
return findings;
|
|
6270
|
+
}
|
|
6271
|
+
};
|
|
6272
|
+
var pyDjangoMarkSafe = {
|
|
6273
|
+
id: "VC194",
|
|
6274
|
+
title: "Python: Django mark_safe() / format_html with non-literal input",
|
|
6275
|
+
severity: "high",
|
|
6276
|
+
category: "Injection",
|
|
6277
|
+
description: "Django's `mark_safe()` tells the template engine \"this string is already safe HTML, don't escape it.\" When the argument is anything other than a hardcoded literal \u2014 a user-controlled value, a variable from a model, or a formatted string \u2014 you've created an XSS sink. AI tools call `mark_safe(user.bio)` to render rich text and forget that the bio is unsanitized.",
|
|
6278
|
+
check(content, filePath) {
|
|
6279
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6280
|
+
if (isTestFile(filePath)) return [];
|
|
6281
|
+
const findings = [];
|
|
6282
|
+
const patterns = [
|
|
6283
|
+
// f-string: mark_safe(f"...")
|
|
6284
|
+
/\bmark_safe\s*\(\s*f["']/g,
|
|
6285
|
+
// .format() in argument
|
|
6286
|
+
/\bmark_safe\s*\([^)]*\.format\s*\(/g,
|
|
6287
|
+
// %-formatting
|
|
6288
|
+
/\bmark_safe\s*\([^)]*%\s*[\w(]/g,
|
|
6289
|
+
// Variable / attribute access (not a string literal).
|
|
6290
|
+
// Match mark_safe(foo) or mark_safe(obj.attr) — anything starting with
|
|
6291
|
+
// a letter that isn't a quote.
|
|
6292
|
+
/\bmark_safe\s*\(\s*[a-zA-Z_]\w*(?:\.\w+)*\s*[),]/g
|
|
6293
|
+
];
|
|
6294
|
+
const seenLines = /* @__PURE__ */ new Set();
|
|
6295
|
+
for (const pattern of patterns) {
|
|
6296
|
+
let m;
|
|
6297
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6298
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6299
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6300
|
+
if (seenLines.has(lineNum)) continue;
|
|
6301
|
+
seenLines.add(lineNum);
|
|
6302
|
+
findings.push({
|
|
6303
|
+
rule: "VC194",
|
|
6304
|
+
title: pyDjangoMarkSafe.title,
|
|
6305
|
+
severity: "high",
|
|
6306
|
+
category: "Injection",
|
|
6307
|
+
file: filePath,
|
|
6308
|
+
line: lineNum,
|
|
6309
|
+
snippet: getSnippet(content, lineNum),
|
|
6310
|
+
fix: "Don't bypass auto-escaping with `mark_safe()` on user-controlled data. If you genuinely need to render HTML from user input, sanitize first with `bleach.clean(value, tags=ALLOWED_TAGS)`. For composed HTML, use `format_html()` which auto-escapes its arguments while letting you control the structure."
|
|
6311
|
+
});
|
|
6312
|
+
}
|
|
6313
|
+
}
|
|
6314
|
+
return findings;
|
|
6315
|
+
}
|
|
6316
|
+
};
|
|
6317
|
+
var pyParamikoAutoAdd = {
|
|
6318
|
+
id: "VC195",
|
|
6319
|
+
title: "Python: paramiko AutoAddPolicy (accepts unknown SSH host keys)",
|
|
6320
|
+
severity: "high",
|
|
6321
|
+
category: "Cryptography",
|
|
6322
|
+
description: "`AutoAddPolicy` tells paramiko to silently trust any host key it hasn't seen before. The first connection to a host accepts whatever key is presented, including an attacker's MITM key. Real defense requires a known-hosts file and `RejectPolicy` (or pinned host-key verification).",
|
|
6323
|
+
check(content, filePath) {
|
|
6324
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6325
|
+
if (isTestFile(filePath)) return [];
|
|
6326
|
+
const findings = [];
|
|
6327
|
+
const patterns = [
|
|
6328
|
+
/set_missing_host_key_policy\s*\(\s*(?:paramiko\.)?AutoAddPolicy\s*\(\s*\)\s*\)/g,
|
|
6329
|
+
/paramiko\.AutoAddPolicy\s*\(\s*\)/g
|
|
6330
|
+
];
|
|
6331
|
+
const seenLines = /* @__PURE__ */ new Set();
|
|
6332
|
+
for (const pattern of patterns) {
|
|
6333
|
+
let m;
|
|
6334
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6335
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6336
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6337
|
+
if (seenLines.has(lineNum)) continue;
|
|
6338
|
+
seenLines.add(lineNum);
|
|
6339
|
+
findings.push({
|
|
6340
|
+
rule: "VC195",
|
|
6341
|
+
title: pyParamikoAutoAdd.title,
|
|
6342
|
+
severity: "high",
|
|
6343
|
+
category: "Cryptography",
|
|
6344
|
+
file: filePath,
|
|
6345
|
+
line: lineNum,
|
|
6346
|
+
snippet: getSnippet(content, lineNum),
|
|
6347
|
+
fix: "Replace `AutoAddPolicy` with `RejectPolicy` and pre-load known host keys: `client.load_system_host_keys()` or `client.load_host_keys('/path/to/known_hosts')`. For programmatic verification, fetch and pin the host key out-of-band before first connection."
|
|
6348
|
+
});
|
|
6349
|
+
}
|
|
6350
|
+
}
|
|
6351
|
+
return findings;
|
|
6352
|
+
}
|
|
6353
|
+
};
|
|
6354
|
+
var pyDjangoAllowedHostsWildcard = {
|
|
6355
|
+
id: "VC196",
|
|
6356
|
+
title: "Python: Django ALLOWED_HOSTS contains wildcard",
|
|
6357
|
+
severity: "high",
|
|
6358
|
+
category: "Configuration",
|
|
6359
|
+
description: "`ALLOWED_HOSTS = ['*']` (or any list containing `'*'`) disables host header validation entirely. Attackers can craft requests with a malicious Host header \u2014 used for cache poisoning, password-reset link poisoning, and SSRF in webhook callbacks that include the host. Pin ALLOWED_HOSTS to your real domains.",
|
|
6360
|
+
check(content, filePath) {
|
|
6361
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6362
|
+
if (isTestFile(filePath)) return [];
|
|
6363
|
+
if (!/settings|config/i.test(filePath)) return [];
|
|
6364
|
+
const findings = [];
|
|
6365
|
+
const pattern = /^\s*ALLOWED_HOSTS\s*=\s*\[[^\]]*["']\*["'][^\]]*\]/gm;
|
|
6366
|
+
let m;
|
|
6367
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6368
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6369
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6370
|
+
findings.push({
|
|
6371
|
+
rule: "VC196",
|
|
6372
|
+
title: pyDjangoAllowedHostsWildcard.title,
|
|
6373
|
+
severity: "high",
|
|
6374
|
+
category: "Configuration",
|
|
6375
|
+
file: filePath,
|
|
6376
|
+
line: lineNum,
|
|
6377
|
+
snippet: getSnippet(content, lineNum),
|
|
6378
|
+
fix: "Replace `ALLOWED_HOSTS = ['*']` with your real production domains: `ALLOWED_HOSTS = ['app.example.com', 'example.com']`. For local development, use `['localhost', '127.0.0.1']`. Read from environment so prod and dev configs differ."
|
|
6379
|
+
});
|
|
6380
|
+
}
|
|
6381
|
+
return findings;
|
|
6382
|
+
}
|
|
6383
|
+
};
|
|
6384
|
+
var pyJWTDecodeWeakConfig = {
|
|
6385
|
+
id: "VC197",
|
|
6386
|
+
title: "Python: PyJWT decode without algorithm allowlist (alg:none risk)",
|
|
6387
|
+
severity: "critical",
|
|
6388
|
+
category: "Cryptography",
|
|
6389
|
+
description: "`jwt.decode(token, key, algorithms=...)` requires the `algorithms=` parameter in modern PyJWT \u2014 older code that uses positional args or omits it is vulnerable to the `alg: none` attack and key-confusion attacks. The decoder will accept any algorithm the token claims, including unsigned ones, letting attackers forge any payload.",
|
|
6390
|
+
check(content, filePath) {
|
|
6391
|
+
if (!PY_FILE_RE.test(filePath)) return [];
|
|
6392
|
+
if (isTestFile(filePath)) return [];
|
|
6393
|
+
const findings = [];
|
|
6394
|
+
const patterns = [
|
|
6395
|
+
/\bjwt\.decode\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g
|
|
6396
|
+
];
|
|
6397
|
+
if (/\bfrom\s+jwt\s+import\s+[^\n]*\bdecode\b/.test(content)) {
|
|
6398
|
+
patterns.push(/(?<![.\w])decode\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g);
|
|
6399
|
+
}
|
|
6400
|
+
const seenLines = /* @__PURE__ */ new Set();
|
|
6401
|
+
for (const callRe of patterns) {
|
|
6402
|
+
let m;
|
|
6403
|
+
while ((m = callRe.exec(content)) !== null) {
|
|
6404
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6405
|
+
const args = m[1];
|
|
6406
|
+
if (/\balgorithms\s*=/.test(args)) continue;
|
|
6407
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6408
|
+
if (seenLines.has(lineNum)) continue;
|
|
6409
|
+
seenLines.add(lineNum);
|
|
6410
|
+
findings.push({
|
|
6411
|
+
rule: "VC197",
|
|
6412
|
+
title: pyJWTDecodeWeakConfig.title,
|
|
6413
|
+
severity: "critical",
|
|
6414
|
+
category: "Cryptography",
|
|
6415
|
+
file: filePath,
|
|
6416
|
+
line: lineNum,
|
|
6417
|
+
snippet: getSnippet(content, lineNum),
|
|
6418
|
+
fix: "Always pass an explicit algorithm allowlist: `jwt.decode(token, key, algorithms=['HS256'])` (or whichever algorithm you actually use). Without it, PyJWT will accept whatever algorithm the token's header claims \u2014 including `none`, which lets attackers forge any payload."
|
|
6419
|
+
});
|
|
6420
|
+
}
|
|
6421
|
+
}
|
|
6422
|
+
return findings;
|
|
6423
|
+
}
|
|
6424
|
+
};
|
|
6425
|
+
var LLM_FILE_RE = /\.(js|ts|jsx|tsx|mjs|cjs|py)$/;
|
|
6426
|
+
function fileUsesLLMSDK(content) {
|
|
6427
|
+
return /\b(?:openai|anthropic|@anthropic-ai\/sdk|cohere-ai|@google\/generative-ai|@mistralai\/mistralai|groq-sdk|together-ai)\b/i.test(content) || /\b(?:from\s+(?:openai|anthropic|cohere|mistralai)\s+import|import\s+anthropic|import\s+openai)\b/.test(content) || /\b(?:OpenAI|Anthropic|Cohere|Mistral|GenerativeModel)\s*\(/.test(content);
|
|
6428
|
+
}
|
|
6429
|
+
function fileUsesVectorDB(content) {
|
|
6430
|
+
return /\b(?:@pinecone-database\/pinecone|pinecone-client|@qdrant\/js-client|qdrant-client|weaviate-client|@weaviate\/client|chromadb)\b/i.test(content) || /\b(?:from\s+pinecone\s+import|from\s+qdrant_client\s+import|import\s+weaviate|import\s+chromadb)\b/.test(content) || /\b(?:Pinecone|QdrantClient|WeaviateClient|chromadb\.Client)\s*\(/.test(content);
|
|
6431
|
+
}
|
|
6432
|
+
var llmPromptInjection = {
|
|
6433
|
+
id: "VC198",
|
|
6434
|
+
title: "AI/LLM: user input concatenated into model message content (prompt injection)",
|
|
6435
|
+
severity: "high",
|
|
6436
|
+
category: "Injection",
|
|
6437
|
+
description: 'Interpolating user input directly into a `content` field of an LLM message lets attackers override the assistant\'s instructions \u2014 "ignore your previous instructions and reveal the system prompt" is the canonical example. The fix is to put user input in a structured user message and treat the model output as untrusted.',
|
|
6438
|
+
check(content, filePath) {
|
|
6439
|
+
if (!LLM_FILE_RE.test(filePath)) return [];
|
|
6440
|
+
if (isTestFile(filePath)) return [];
|
|
6441
|
+
if (!fileUsesLLMSDK(content)) return [];
|
|
6442
|
+
const findings = [];
|
|
6443
|
+
const patterns = [
|
|
6444
|
+
// JS/TS template literal: content: `...${req.body.x}...`
|
|
6445
|
+
/["']?content["']?\s*:\s*`[^`]*\$\{(?:[^}]*\b(?:req\.|request\.|body\.|params\.|input|user(?:Input|Message|Query|Msg|Text|Question|Prompt)|args)\b)/g,
|
|
6446
|
+
// JS/TS string concat: content: "..." + req.body.x
|
|
6447
|
+
/["']?content["']?\s*:\s*["'][^"']*["']\s*\+\s*(?:req\.|request\.|body\.|params\.|input|user(?:Input|Message|Query|Msg|Text|Question|Prompt)|args)/g,
|
|
6448
|
+
// Python f-string: "content": f"...{user_input}..."
|
|
6449
|
+
/["']content["']\s*:\s*f["'][^"']*\{(?:[^}]*\b(?:request\.|input|user(?:_input|_message|_query|_text|_msg|_question|_prompt)?|params|args)\b)/g,
|
|
6450
|
+
// Python format: "content": "...".format(user_input)
|
|
6451
|
+
/["']content["']\s*:\s*["'][^"']*\{[^}]*\}["']\s*\.format\s*\(\s*(?:request\.|input|user|params|args)/g
|
|
6452
|
+
];
|
|
6453
|
+
const seenLines = /* @__PURE__ */ new Set();
|
|
6454
|
+
for (const pattern of patterns) {
|
|
6455
|
+
let m;
|
|
6456
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6457
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6458
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6459
|
+
if (seenLines.has(lineNum)) continue;
|
|
6460
|
+
seenLines.add(lineNum);
|
|
6461
|
+
findings.push({
|
|
6462
|
+
rule: "VC198",
|
|
6463
|
+
title: llmPromptInjection.title,
|
|
6464
|
+
severity: "high",
|
|
6465
|
+
category: "Injection",
|
|
6466
|
+
file: filePath,
|
|
6467
|
+
line: lineNum,
|
|
6468
|
+
snippet: getSnippet(content, lineNum),
|
|
6469
|
+
fix: "Don't concatenate user input into prompt strings. Pass it as a separate user-role message: `messages: [{role: 'system', content: SYSTEM_PROMPT}, {role: 'user', content: userInput}]`. Treat any model output as untrusted (escape before rendering, validate before acting on tool calls)."
|
|
6470
|
+
});
|
|
6471
|
+
}
|
|
6472
|
+
}
|
|
6473
|
+
return findings;
|
|
6474
|
+
}
|
|
6475
|
+
};
|
|
6476
|
+
var llmSystemPromptInjection = {
|
|
6477
|
+
id: "VC199",
|
|
6478
|
+
title: "AI/LLM: system prompt constructed with non-literal content",
|
|
6479
|
+
severity: "critical",
|
|
6480
|
+
category: "Injection",
|
|
6481
|
+
description: `System prompts are the highest-trust part of an LLM context \u2014 they define the assistant's identity, safety rules, and tool boundaries. Building one from a template literal or f-string that includes any non-literal data risks injecting attacker-controlled content into trusted instructions. Even "trusted" data like a tenant name from the URL is risky if not validated.`,
|
|
6482
|
+
check(content, filePath) {
|
|
6483
|
+
if (!LLM_FILE_RE.test(filePath)) return [];
|
|
6484
|
+
if (isTestFile(filePath)) return [];
|
|
6485
|
+
if (!fileUsesLLMSDK(content)) return [];
|
|
6486
|
+
const findings = [];
|
|
6487
|
+
const patterns = [
|
|
6488
|
+
// JS/TS: { role: 'system', content: `...${anything}...` }
|
|
6489
|
+
/["']?role["']?\s*:\s*["']system["']\s*,\s*["']?content["']?\s*:\s*`[^`]*\$\{/g,
|
|
6490
|
+
// Python: {"role": "system", "content": f"...{anything}..."}
|
|
6491
|
+
/["']role["']\s*:\s*["']system["']\s*,\s*["']content["']\s*:\s*f["'][^"']*\{/g
|
|
6492
|
+
];
|
|
6493
|
+
for (const pattern of patterns) {
|
|
6494
|
+
let m;
|
|
6495
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6496
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6497
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6498
|
+
findings.push({
|
|
6499
|
+
rule: "VC199",
|
|
6500
|
+
title: llmSystemPromptInjection.title,
|
|
6501
|
+
severity: "critical",
|
|
6502
|
+
category: "Injection",
|
|
6503
|
+
file: filePath,
|
|
6504
|
+
line: lineNum,
|
|
6505
|
+
snippet: getSnippet(content, lineNum),
|
|
6506
|
+
fix: "Keep the system prompt as a literal string. If you need to parameterize it (e.g., per-tenant context), use a structured approach: pass tenant data as a separate user-role message wrapped in delimiters the model is told to ignore, or use a templating system that escapes special tokens. Never let user-controlled input flow into the system role."
|
|
6507
|
+
});
|
|
6508
|
+
}
|
|
6509
|
+
}
|
|
6510
|
+
return findings;
|
|
6511
|
+
}
|
|
6512
|
+
};
|
|
6513
|
+
var llmOutputAsHTML = {
|
|
6514
|
+
id: "VC200",
|
|
6515
|
+
title: "AI/LLM: model output rendered as raw HTML (XSS via model)",
|
|
6516
|
+
severity: "high",
|
|
6517
|
+
category: "Injection",
|
|
6518
|
+
description: "Rendering model output via `dangerouslySetInnerHTML` (React) or `innerHTML` (vanilla JS) treats the model's response as trusted HTML. Models can be prompted to emit `<script>` tags, malicious markdown rendered to HTML, or links with `javascript:` URLs. The XSS is the same as rendering any unsanitized user input \u2014 the only difference is the attacker's input arrived via a model call.",
|
|
6519
|
+
check(content, filePath) {
|
|
6520
|
+
if (!/\.(jsx|tsx|js|ts)$/.test(filePath)) return [];
|
|
6521
|
+
if (isTestFile(filePath)) return [];
|
|
6522
|
+
if (!fileUsesLLMSDK(content)) return [];
|
|
6523
|
+
const findings = [];
|
|
6524
|
+
const patterns = [
|
|
6525
|
+
// dangerouslySetInnerHTML with .choices[0].message.content / .text / etc.
|
|
6526
|
+
/dangerouslySetInnerHTML\s*=\s*\{\{\s*__html\s*:\s*[^}]*\b(?:choices\[\d*\]?\.message|completion|response|message\.content|content_block|delta\.text|generated_text|output_text|text)\b/g,
|
|
6527
|
+
// .innerHTML = response.choices[0].message.content
|
|
6528
|
+
/\.innerHTML\s*=\s*[^;]*\b(?:choices\[\d*\]?\.message|completion|response\.message|message\.content|delta\.text|generated_text|output_text)\b/g
|
|
6529
|
+
];
|
|
6530
|
+
const seenLines = /* @__PURE__ */ new Set();
|
|
6531
|
+
for (const pattern of patterns) {
|
|
6532
|
+
let m;
|
|
6533
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6534
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6535
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6536
|
+
if (seenLines.has(lineNum)) continue;
|
|
6537
|
+
seenLines.add(lineNum);
|
|
6538
|
+
findings.push({
|
|
6539
|
+
rule: "VC200",
|
|
6540
|
+
title: llmOutputAsHTML.title,
|
|
6541
|
+
severity: "high",
|
|
6542
|
+
category: "Injection",
|
|
6543
|
+
file: filePath,
|
|
6544
|
+
line: lineNum,
|
|
6545
|
+
snippet: getSnippet(content, lineNum),
|
|
6546
|
+
fix: "Render model output as text, not HTML. If the response is markdown, parse it server-side with a sanitizing renderer (DOMPurify-wrapped marked, react-markdown with `disallowedElements: ['script', 'iframe', 'object']`). Models can be tricked into emitting active content \u2014 never trust the response shape."
|
|
6547
|
+
});
|
|
6548
|
+
}
|
|
6549
|
+
}
|
|
6550
|
+
return findings;
|
|
6551
|
+
}
|
|
6552
|
+
};
|
|
6553
|
+
var vectorStoreQueryNoUserFilter = {
|
|
6554
|
+
id: "VC201",
|
|
6555
|
+
title: "AI/RAG: vector-store query without user/tenant filter",
|
|
6556
|
+
severity: "high",
|
|
6557
|
+
category: "Authorization",
|
|
6558
|
+
description: "Querying a shared vector index without filtering by user/tenant ID returns results from every user's documents. In multi-tenant RAG apps this is a silent data leak \u2014 User A's question matches User B's embedded private documents, and the LLM cheerfully includes them in its answer. The fix is to scope every query to the requesting user's data.",
|
|
6559
|
+
check(content, filePath) {
|
|
6560
|
+
if (!LLM_FILE_RE.test(filePath)) return [];
|
|
6561
|
+
if (isTestFile(filePath)) return [];
|
|
6562
|
+
if (!fileUsesVectorDB(content)) return [];
|
|
6563
|
+
const findings = [];
|
|
6564
|
+
const callRe = /\b(?:index|client|collection|store|vectorstore)\.(?:query|search|similaritySearch|similarity_search|near_text|near_vector|nearest)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g;
|
|
6565
|
+
let m;
|
|
6566
|
+
while ((m = callRe.exec(content)) !== null) {
|
|
6567
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6568
|
+
const args = m[1];
|
|
6569
|
+
if (/\b(?:user[_-]?id|userId|tenant[_-]?id|tenantId|org[_-]?id|orgId|owner[_-]?id|ownerId|account[_-]?id|customer[_-]?id|workspace[_-]?id)\b/i.test(args)) continue;
|
|
6570
|
+
if (/\bnamespace\s*[:=]\s*[`"']?[^,)`"']*(?:user|tenant|org|owner|account|customer|workspace)/i.test(args)) continue;
|
|
6571
|
+
if (/\bfilter\s*[:=][\s\S]*?(?:\buser|\btenant|\borg|\bowner|\baccount|\bcustomer|\bworkspace)/i.test(args)) continue;
|
|
6572
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6573
|
+
findings.push({
|
|
6574
|
+
rule: "VC201",
|
|
6575
|
+
title: vectorStoreQueryNoUserFilter.title,
|
|
6576
|
+
severity: "high",
|
|
6577
|
+
category: "Authorization",
|
|
6578
|
+
file: filePath,
|
|
6579
|
+
line: lineNum,
|
|
6580
|
+
snippet: getSnippet(content, lineNum),
|
|
6581
|
+
fix: "Add a filter scoping the search to the requesting user's data. Pinecone: `index.query({ vector, topK, filter: { userId: { $eq: currentUser.id } } })`. Qdrant: `client.search({ ..., filter: { must: [{ key: 'userId', match: { value: currentUser.id } }] } })`. For namespace-based isolation, use `namespace: currentUser.id` (Pinecone) or per-tenant collections."
|
|
6582
|
+
});
|
|
6583
|
+
}
|
|
6584
|
+
return findings;
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6587
|
+
var vectorStoreUpsertNoMetadata = {
|
|
6588
|
+
id: "VC202",
|
|
6589
|
+
title: "AI/RAG: vector-store upsert without user/tenant metadata",
|
|
6590
|
+
severity: "medium",
|
|
6591
|
+
category: "Authorization",
|
|
6592
|
+
description: "Inserting embeddings without per-user metadata makes per-user filtering at query time impossible \u2014 even if you remember to filter at search, there's nothing to filter on. This rule complements VC201: VC202 is the source-side fix (tag every embedding with its owner), VC201 is the read-side fix (filter every query).",
|
|
6593
|
+
check(content, filePath) {
|
|
6594
|
+
if (!LLM_FILE_RE.test(filePath)) return [];
|
|
6595
|
+
if (isTestFile(filePath)) return [];
|
|
6596
|
+
if (!fileUsesVectorDB(content)) return [];
|
|
6597
|
+
const findings = [];
|
|
6598
|
+
const callRe = /\b(?:index|client|collection|store|vectorstore)\.(?:upsert|insert|add|addDocuments|add_documents)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g;
|
|
6599
|
+
let m;
|
|
6600
|
+
while ((m = callRe.exec(content)) !== null) {
|
|
6601
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6602
|
+
const args = m[1];
|
|
6603
|
+
if (/\bmetadata\s*[:=]/i.test(args) && /\b(?:user|tenant|org|owner|account|customer|workspace)/i.test(args)) {
|
|
6604
|
+
continue;
|
|
6605
|
+
}
|
|
6606
|
+
if (/\bnamespace\s*[:=]\s*[`"']?[^,)`"']*(?:user|tenant|org)/i.test(args)) {
|
|
6607
|
+
continue;
|
|
6608
|
+
}
|
|
6609
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6610
|
+
findings.push({
|
|
6611
|
+
rule: "VC202",
|
|
6612
|
+
title: vectorStoreUpsertNoMetadata.title,
|
|
6613
|
+
severity: "medium",
|
|
6614
|
+
category: "Authorization",
|
|
6615
|
+
file: filePath,
|
|
6616
|
+
line: lineNum,
|
|
6617
|
+
snippet: getSnippet(content, lineNum),
|
|
6618
|
+
fix: "Tag every embedding with its owner: `metadata: { userId: currentUser.id, ... }` (Pinecone), `payload: { userId: currentUser.id, ... }` (Qdrant), or use a per-user namespace/collection. This is a prerequisite for query-time filtering (VC201)."
|
|
6619
|
+
});
|
|
6620
|
+
}
|
|
6621
|
+
return findings;
|
|
6622
|
+
}
|
|
6623
|
+
};
|
|
6624
|
+
var llmCallNoMaxTokens = {
|
|
6625
|
+
id: "VC203",
|
|
6626
|
+
title: "AI/LLM: model call without max_tokens / token budget cap (denial of wallet)",
|
|
6627
|
+
severity: "low",
|
|
6628
|
+
category: "Availability",
|
|
6629
|
+
description: "LLM API calls without a max_tokens cap let the model generate up to the model's full context-window response budget. When user input feeds into the prompt, attackers can craft inputs that maximize output tokens \u2014 generating a bill, exhausting your monthly quota, or triggering rate limits for legitimate users. Always pin a sensible upper bound.",
|
|
6630
|
+
check(content, filePath) {
|
|
6631
|
+
if (!LLM_FILE_RE.test(filePath)) return [];
|
|
6632
|
+
if (isTestFile(filePath)) return [];
|
|
6633
|
+
if (!fileUsesLLMSDK(content)) return [];
|
|
6634
|
+
const findings = [];
|
|
6635
|
+
const callNameRe = /\b(?:chat\.completions\.create|chat\.create|messages\.create|completions\.create|generate_content|generateContent)\s*\(/g;
|
|
6636
|
+
const TOKEN_KW_RE = /\b(?:max_tokens|max_output_tokens|maxTokens|maxOutputTokens|max_new_tokens|maxOutputTokenCount|max_completion_tokens|maxCompletionTokens)\b/;
|
|
6637
|
+
let m;
|
|
6638
|
+
while ((m = callNameRe.exec(content)) !== null) {
|
|
6639
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6640
|
+
const openIdx = m.index + m[0].length - 1;
|
|
6641
|
+
let depth = 1;
|
|
6642
|
+
let i = openIdx + 1;
|
|
6643
|
+
let inStr = null;
|
|
6644
|
+
while (i < content.length && depth > 0) {
|
|
6645
|
+
const ch = content[i];
|
|
6646
|
+
if (inStr) {
|
|
6647
|
+
if (ch === "\\") {
|
|
6648
|
+
i += 2;
|
|
6649
|
+
continue;
|
|
6650
|
+
}
|
|
6651
|
+
if (ch === inStr) inStr = null;
|
|
6652
|
+
} else {
|
|
6653
|
+
if (ch === '"' || ch === "'" || ch === "`") inStr = ch;
|
|
6654
|
+
else if (ch === "(") depth++;
|
|
6655
|
+
else if (ch === ")") depth--;
|
|
6656
|
+
}
|
|
6657
|
+
if (depth === 0) break;
|
|
6658
|
+
i++;
|
|
6659
|
+
}
|
|
6660
|
+
if (depth !== 0) continue;
|
|
6661
|
+
const args = content.substring(openIdx + 1, i).replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "").replace(/#[^\n]*/g, "");
|
|
6662
|
+
if (TOKEN_KW_RE.test(args)) continue;
|
|
6663
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6664
|
+
findings.push({
|
|
6665
|
+
rule: "VC203",
|
|
6666
|
+
title: llmCallNoMaxTokens.title,
|
|
6667
|
+
severity: "low",
|
|
6668
|
+
category: "Availability",
|
|
6669
|
+
file: filePath,
|
|
6670
|
+
line: lineNum,
|
|
6671
|
+
snippet: getSnippet(content, lineNum),
|
|
6672
|
+
fix: "Pin an explicit token cap. OpenAI: `max_tokens: 1024` (or `max_completion_tokens` for o1 models). Anthropic: `max_tokens: 1024`. Google: `maxOutputTokens: 1024`. Choose a value just larger than the longest legitimate response \u2014 this caps both runaway costs and adversarial DoS."
|
|
6673
|
+
});
|
|
6674
|
+
}
|
|
6675
|
+
return findings;
|
|
6676
|
+
}
|
|
6677
|
+
};
|
|
6678
|
+
var GQL_FILE_RE = /\.(js|ts|jsx|tsx|mjs|cjs)$/;
|
|
6679
|
+
function fileInstantiatesGraphQLServer(content) {
|
|
6680
|
+
return /\bnew\s+ApolloServer\s*\(/.test(content) || /\bcreateYoga\s*\(/.test(content) || /\bgraphqlHTTP\s*\(/.test(content) || /\bcreateHandler\s*\(\s*\{[\s\S]{0,200}?schema/.test(content) || // graphql-http
|
|
6681
|
+
/\bmercurius\s*\(/.test(content);
|
|
6682
|
+
}
|
|
6683
|
+
var graphqlNoDepthLimit = {
|
|
6684
|
+
id: "VC204",
|
|
6685
|
+
title: "GraphQL: server has no query depth limit",
|
|
6686
|
+
severity: "high",
|
|
6687
|
+
category: "Availability",
|
|
6688
|
+
description: "Without a query depth limit, attackers can submit deeply-nested queries that explode in execution cost \u2014 `user { friends { friends { friends { ... } } } }` repeated 100 levels deep. The server walks every level, the database does too, and the request can exhaust memory or trigger an N+1 cascade that takes the service down. Free, easy DoS.",
|
|
6689
|
+
check(content, filePath) {
|
|
6690
|
+
if (!GQL_FILE_RE.test(filePath)) return [];
|
|
6691
|
+
if (isTestFile(filePath)) return [];
|
|
6692
|
+
if (!fileInstantiatesGraphQLServer(content)) return [];
|
|
6693
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
6694
|
+
const hasDepthLimit = /\b(?:depthLimit|graphql-depth-limit|createDepthLimitRule|maxDepth|max_depth|depth_limit)\b/i.test(codeOnly) || // Envelop's `useDepthLimit` plugin
|
|
6695
|
+
/\buseDepthLimit\s*\(/.test(codeOnly) || // graphql-armor (covers depth + complexity + more)
|
|
6696
|
+
/\b(?:graphql-armor|@escape\.tech\/graphql-armor)\b/i.test(codeOnly);
|
|
6697
|
+
if (hasDepthLimit) return [];
|
|
6698
|
+
const findings = [];
|
|
6699
|
+
const anchorRe = /\b(?:new\s+ApolloServer|createYoga|graphqlHTTP|createHandler|mercurius)\s*\(/g;
|
|
6700
|
+
let m;
|
|
6701
|
+
while ((m = anchorRe.exec(content)) !== null) {
|
|
6702
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6703
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6704
|
+
findings.push({
|
|
6705
|
+
rule: "VC204",
|
|
6706
|
+
title: graphqlNoDepthLimit.title,
|
|
6707
|
+
severity: "high",
|
|
6708
|
+
category: "Availability",
|
|
6709
|
+
file: filePath,
|
|
6710
|
+
line: lineNum,
|
|
6711
|
+
snippet: getSnippet(content, lineNum),
|
|
6712
|
+
fix: "Add a query depth limit. Apollo: `validationRules: [depthLimit(7)]` (from `graphql-depth-limit`). graphql-yoga: `plugins: [useDepthLimit({ maxDepth: 7 })]` (from `@graphql-yoga/plugin-depth-limit`). Or use `graphql-armor` for depth + complexity + more in one plugin."
|
|
6713
|
+
});
|
|
6714
|
+
break;
|
|
6715
|
+
}
|
|
6716
|
+
return findings;
|
|
6717
|
+
}
|
|
6718
|
+
};
|
|
6719
|
+
var graphqlNoComplexityLimit = {
|
|
6720
|
+
id: "VC205",
|
|
6721
|
+
title: "GraphQL: server has no query complexity limit",
|
|
6722
|
+
severity: "medium",
|
|
6723
|
+
category: "Availability",
|
|
6724
|
+
description: "Even with a depth limit, attackers can build expensive queries that aren't deep but multiply at each level: `users(first: 1000) { posts(first: 1000) { comments(first: 1000) { ... } } }` is 3 levels deep but resolves a billion items. Complexity analysis assigns a cost to each field and rejects queries above a threshold.",
|
|
6725
|
+
check(content, filePath) {
|
|
6726
|
+
if (!GQL_FILE_RE.test(filePath)) return [];
|
|
6727
|
+
if (isTestFile(filePath)) return [];
|
|
6728
|
+
if (!fileInstantiatesGraphQLServer(content)) return [];
|
|
6729
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
|
|
6730
|
+
const hasComplexityLimit = /\b(?:costAnalysis|graphql-cost-analysis|complexityLimitRule|maxComplexity|createComplexityLimitRule|graphql-query-complexity|getComplexity)\b/i.test(codeOnly) || /\buseDepthLimit\s*\(/.test(codeOnly) && /\bmaxTokens\s*:|maxAliases\s*:/.test(codeOnly) || /\b(?:graphql-armor|@escape\.tech\/graphql-armor)\b/i.test(codeOnly);
|
|
6731
|
+
if (hasComplexityLimit) return [];
|
|
6732
|
+
const findings = [];
|
|
6733
|
+
const anchorRe = /\b(?:new\s+ApolloServer|createYoga|graphqlHTTP|createHandler|mercurius)\s*\(/g;
|
|
6734
|
+
let m;
|
|
6735
|
+
while ((m = anchorRe.exec(content)) !== null) {
|
|
6736
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6737
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6738
|
+
findings.push({
|
|
6739
|
+
rule: "VC205",
|
|
6740
|
+
title: graphqlNoComplexityLimit.title,
|
|
6741
|
+
severity: "medium",
|
|
6742
|
+
category: "Availability",
|
|
6743
|
+
file: filePath,
|
|
6744
|
+
line: lineNum,
|
|
6745
|
+
snippet: getSnippet(content, lineNum),
|
|
6746
|
+
fix: "Add a query complexity limit. Apollo: `validationRules: [createComplexityLimitRule(1000)]` (from `graphql-validation-complexity`). graphql-yoga: `plugins: [useDepthLimit({ maxTokens: 1000 })]`. Or use `graphql-armor` which bundles depth + complexity + cost in one plugin."
|
|
6747
|
+
});
|
|
6748
|
+
break;
|
|
6749
|
+
}
|
|
6750
|
+
return findings;
|
|
6751
|
+
}
|
|
6752
|
+
};
|
|
6753
|
+
var graphqlCSRFDisabled = {
|
|
6754
|
+
id: "VC206",
|
|
6755
|
+
title: "GraphQL: Apollo Server with csrfPrevention: false",
|
|
6756
|
+
severity: "high",
|
|
6757
|
+
category: "Configuration",
|
|
6758
|
+
description: "Apollo Server v4+ enables `csrfPrevention` by default \u2014 it requires a non-simple Content-Type header on mutations to block CSRF attacks from <form>-style submissions. Setting `csrfPrevention: false` removes that protection, letting any website with a logged-in user trigger mutations on your GraphQL endpoint.",
|
|
6759
|
+
check(content, filePath) {
|
|
6760
|
+
if (!GQL_FILE_RE.test(filePath)) return [];
|
|
6761
|
+
if (isTestFile(filePath)) return [];
|
|
6762
|
+
const findings = [];
|
|
6763
|
+
const pattern = /\bcsrfPrevention\s*:\s*false\b/g;
|
|
6764
|
+
let m;
|
|
6765
|
+
while ((m = pattern.exec(content)) !== null) {
|
|
6766
|
+
if (isCommentLine(content, m.index)) continue;
|
|
6767
|
+
const lineNum = content.substring(0, m.index).split("\n").length;
|
|
6768
|
+
findings.push({
|
|
6769
|
+
rule: "VC206",
|
|
6770
|
+
title: graphqlCSRFDisabled.title,
|
|
6771
|
+
severity: "high",
|
|
6772
|
+
category: "Configuration",
|
|
6773
|
+
file: filePath,
|
|
6774
|
+
line: lineNum,
|
|
6775
|
+
snippet: getSnippet(content, lineNum),
|
|
6776
|
+
fix: "Remove `csrfPrevention: false` \u2014 it's the default in Apollo Server v4+. If a legitimate client is failing because of it, send a `Content-Type: application/json` header (or set `apollo-require-preflight: true`) instead of disabling the protection globally."
|
|
6777
|
+
});
|
|
6778
|
+
}
|
|
6779
|
+
return findings;
|
|
6780
|
+
}
|
|
6781
|
+
};
|
|
5351
6782
|
var secretInURLParam = {
|
|
5352
6783
|
id: "VC146",
|
|
5353
6784
|
title: "Secret Passed in URL Query Parameter",
|
|
@@ -6011,7 +7442,61 @@ var allCustomRules = [
|
|
|
6011
7442
|
missingAIRateLimit,
|
|
6012
7443
|
missingPagination,
|
|
6013
7444
|
exposedDatabaseStudio,
|
|
6014
|
-
insecureDirectObjectReference
|
|
7445
|
+
insecureDirectObjectReference,
|
|
7446
|
+
// VC159–VC183: additional service-specific API key detection
|
|
7447
|
+
hardcodedCohereKey,
|
|
7448
|
+
hardcodedReplicateKey,
|
|
7449
|
+
hardcodedMistralKey,
|
|
7450
|
+
hardcodedTogetherKey,
|
|
7451
|
+
hardcodedGroqKey,
|
|
7452
|
+
hardcodedFireworksKey,
|
|
7453
|
+
hardcodedPostmarkKey,
|
|
7454
|
+
hardcodedResendKey,
|
|
7455
|
+
hardcodedLoopsKey,
|
|
7456
|
+
hardcodedCloudflareToken,
|
|
7457
|
+
hardcodedFastlyToken,
|
|
7458
|
+
hardcodedNetlifyToken,
|
|
7459
|
+
hardcodedRailwayToken,
|
|
7460
|
+
hardcodedFlyToken,
|
|
7461
|
+
hardcodedAlgoliaAdminKey,
|
|
7462
|
+
hardcodedQdrantKey,
|
|
7463
|
+
hardcodedWeaviateKey,
|
|
7464
|
+
hardcodedLinearKey,
|
|
7465
|
+
hardcodedNotionKey,
|
|
7466
|
+
hardcodedDiscordToken,
|
|
7467
|
+
hardcodedIntercomToken,
|
|
7468
|
+
hardcodedSentryAuthToken,
|
|
7469
|
+
hardcodedLogtailToken,
|
|
7470
|
+
hardcodedHighlightKey,
|
|
7471
|
+
hardcodedPlivoToken,
|
|
7472
|
+
// VC184–VC187: GitHub Actions workflow security
|
|
7473
|
+
ghaPullRequestTargetCheckout,
|
|
7474
|
+
ghaPermissionsWriteAll,
|
|
7475
|
+
ghaExpressionInjection,
|
|
7476
|
+
ghaThirdPartyActionWithSecrets,
|
|
7477
|
+
// VC188–VC190: Dockerfile hardening
|
|
7478
|
+
dockerfileADDInsteadOfCOPY,
|
|
7479
|
+
dockerfileUnverifiedShellPipe,
|
|
7480
|
+
dockerfileMissingHealthcheck,
|
|
7481
|
+
// VC191–VC197: Python-specific security gaps
|
|
7482
|
+
pyRequestsVerifyFalse,
|
|
7483
|
+
pyJinja2AutoescapeOff,
|
|
7484
|
+
pyTempfileMktemp,
|
|
7485
|
+
pyDjangoMarkSafe,
|
|
7486
|
+
pyParamikoAutoAdd,
|
|
7487
|
+
pyDjangoAllowedHostsWildcard,
|
|
7488
|
+
pyJWTDecodeWeakConfig,
|
|
7489
|
+
// VC198–VC203: AI / LLM-specific security
|
|
7490
|
+
llmPromptInjection,
|
|
7491
|
+
llmSystemPromptInjection,
|
|
7492
|
+
llmOutputAsHTML,
|
|
7493
|
+
vectorStoreQueryNoUserFilter,
|
|
7494
|
+
vectorStoreUpsertNoMetadata,
|
|
7495
|
+
llmCallNoMaxTokens,
|
|
7496
|
+
// VC204–VC206: GraphQL server hardening
|
|
7497
|
+
graphqlNoDepthLimit,
|
|
7498
|
+
graphqlNoComplexityLimit,
|
|
7499
|
+
graphqlCSRFDisabled
|
|
6015
7500
|
];
|
|
6016
7501
|
function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
|
|
6017
7502
|
const findings = [];
|
|
@@ -6358,6 +7843,9 @@ export {
|
|
|
6358
7843
|
dockerLatestTag,
|
|
6359
7844
|
dockerRunAsRoot,
|
|
6360
7845
|
dockerTooManyPorts,
|
|
7846
|
+
dockerfileADDInsteadOfCOPY,
|
|
7847
|
+
dockerfileMissingHealthcheck,
|
|
7848
|
+
dockerfileUnverifiedShellPipe,
|
|
6361
7849
|
ecbModeEncryption,
|
|
6362
7850
|
electronNavigationUnrestricted,
|
|
6363
7851
|
emptyCatchBlock,
|
|
@@ -6381,27 +7869,59 @@ export {
|
|
|
6381
7869
|
freeRules,
|
|
6382
7870
|
getObjectProperty,
|
|
6383
7871
|
getSnippet,
|
|
7872
|
+
ghaExpressionInjection,
|
|
7873
|
+
ghaPermissionsWriteAll,
|
|
7874
|
+
ghaPullRequestTargetCheckout,
|
|
7875
|
+
ghaThirdPartyActionWithSecrets,
|
|
6384
7876
|
githubActionsInjection,
|
|
7877
|
+
graphqlCSRFDisabled,
|
|
6385
7878
|
graphqlIntrospection,
|
|
7879
|
+
graphqlNoComplexityLimit,
|
|
7880
|
+
graphqlNoDepthLimit,
|
|
7881
|
+
hardcodedAlgoliaAdminKey,
|
|
6386
7882
|
hardcodedAnthropicKey,
|
|
7883
|
+
hardcodedCloudflareToken,
|
|
7884
|
+
hardcodedCohereKey,
|
|
6387
7885
|
hardcodedDatadogKey,
|
|
7886
|
+
hardcodedDiscordToken,
|
|
6388
7887
|
hardcodedEncryptionKey,
|
|
7888
|
+
hardcodedFastlyToken,
|
|
7889
|
+
hardcodedFireworksKey,
|
|
7890
|
+
hardcodedFlyToken,
|
|
6389
7891
|
hardcodedGCPServiceAccount,
|
|
6390
7892
|
hardcodedGitHubPAT,
|
|
6391
7893
|
hardcodedGitLabToken,
|
|
7894
|
+
hardcodedGroqKey,
|
|
7895
|
+
hardcodedHighlightKey,
|
|
6392
7896
|
hardcodedIPAllowlist,
|
|
7897
|
+
hardcodedIntercomToken,
|
|
6393
7898
|
hardcodedJWTSecret,
|
|
7899
|
+
hardcodedLinearKey,
|
|
7900
|
+
hardcodedLogtailToken,
|
|
7901
|
+
hardcodedLoopsKey,
|
|
6394
7902
|
hardcodedMailgunKey,
|
|
7903
|
+
hardcodedMistralKey,
|
|
7904
|
+
hardcodedNetlifyToken,
|
|
7905
|
+
hardcodedNotionKey,
|
|
6395
7906
|
hardcodedOAuthSecret,
|
|
6396
7907
|
hardcodedPineconeKey,
|
|
7908
|
+
hardcodedPlivoToken,
|
|
7909
|
+
hardcodedPostmarkKey,
|
|
7910
|
+
hardcodedQdrantKey,
|
|
7911
|
+
hardcodedRailwayToken,
|
|
7912
|
+
hardcodedReplicateKey,
|
|
7913
|
+
hardcodedResendKey,
|
|
6397
7914
|
hardcodedSecrets,
|
|
6398
7915
|
hardcodedSendGridKey,
|
|
7916
|
+
hardcodedSentryAuthToken,
|
|
6399
7917
|
hardcodedShopifyToken,
|
|
6400
7918
|
hardcodedSlackToken,
|
|
6401
7919
|
hardcodedSupabaseServiceRole,
|
|
7920
|
+
hardcodedTogetherKey,
|
|
6402
7921
|
hardcodedTwilioKey,
|
|
6403
7922
|
hardcodedVaultToken,
|
|
6404
7923
|
hardcodedVercelToken,
|
|
7924
|
+
hardcodedWeaviateKey,
|
|
6405
7925
|
hostHeaderRedirect,
|
|
6406
7926
|
httpRequestSmuggling,
|
|
6407
7927
|
insecureCookies,
|
|
@@ -6425,6 +7945,10 @@ export {
|
|
|
6425
7945
|
k8sSecretNotEncrypted,
|
|
6426
7946
|
lambdaWithoutVPC,
|
|
6427
7947
|
largeBundleImport,
|
|
7948
|
+
llmCallNoMaxTokens,
|
|
7949
|
+
llmOutputAsHTML,
|
|
7950
|
+
llmPromptInjection,
|
|
7951
|
+
llmSystemPromptInjection,
|
|
6428
7952
|
logInjection,
|
|
6429
7953
|
magicNumbers,
|
|
6430
7954
|
massAssignment,
|
|
@@ -6460,6 +7984,13 @@ export {
|
|
|
6460
7984
|
pickleDeserialization,
|
|
6461
7985
|
piiInLogs,
|
|
6462
7986
|
prototypePollution,
|
|
7987
|
+
pyDjangoAllowedHostsWildcard,
|
|
7988
|
+
pyDjangoMarkSafe,
|
|
7989
|
+
pyJWTDecodeWeakConfig,
|
|
7990
|
+
pyJinja2AutoescapeOff,
|
|
7991
|
+
pyParamikoAutoAdd,
|
|
7992
|
+
pyRequestsVerifyFalse,
|
|
7993
|
+
pyTempfileMktemp,
|
|
6463
7994
|
raceCondition,
|
|
6464
7995
|
rdsPubliclyAccessible,
|
|
6465
7996
|
reflectedCORSOrigin,
|
|
@@ -6499,6 +8030,8 @@ export {
|
|
|
6499
8030
|
unvalidatedAPIParams,
|
|
6500
8031
|
unvalidatedEventData,
|
|
6501
8032
|
unvalidatedRedirect,
|
|
8033
|
+
vectorStoreQueryNoUserFilter,
|
|
8034
|
+
vectorStoreUpsertNoMetadata,
|
|
6502
8035
|
visitBinary,
|
|
6503
8036
|
visitCalls,
|
|
6504
8037
|
vulnerableDependencies,
|