xploitscan-shared-rules 2.4.10 → 2.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +389 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +388 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
QUALITY_EXAMPLES: () => QUALITY_EXAMPLES,
|
|
47
47
|
RULE_IMPACTS: () => RULE_IMPACTS,
|
|
48
48
|
SCANNER_VERSION: () => SCANNER_VERSION,
|
|
49
|
+
SERVER_ACTION_WRITE_RE: () => SERVER_ACTION_WRITE_RE,
|
|
49
50
|
TEST_FILE_PATTERN: () => TEST_FILE_PATTERN,
|
|
50
51
|
TOTAL_RULE_COUNT: () => TOTAL_RULE_COUNT,
|
|
51
52
|
allRules: () => allRules,
|
|
@@ -159,7 +160,7 @@ __export(index_exports, {
|
|
|
159
160
|
module.exports = __toCommonJS(index_exports);
|
|
160
161
|
|
|
161
162
|
// src/version.ts
|
|
162
|
-
var SCANNER_VERSION = "2.4.
|
|
163
|
+
var SCANNER_VERSION = "2.4.12";
|
|
163
164
|
|
|
164
165
|
// src/snippet.ts
|
|
165
166
|
var cacheContent = null;
|
|
@@ -505,6 +506,134 @@ function classifyExposure(filePath) {
|
|
|
505
506
|
return "unknown";
|
|
506
507
|
}
|
|
507
508
|
|
|
509
|
+
// src/route-delegation.ts
|
|
510
|
+
var ROUTE_FILE_RE = /(?:^|\/)app\/(?:[^/]+\/)*route\.[jt]sx?$/;
|
|
511
|
+
var METHOD = "(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)";
|
|
512
|
+
var HANDLER_EXPORT_RE = new RegExp(`\\bexport\\s+(?:(?:async\\s+)?function\\s+${METHOD}\\b|const\\s+${METHOD}\\s*=)`, "g");
|
|
513
|
+
var DELEGATING_HANDLER_RE = new RegExp(
|
|
514
|
+
`\\bexport\\s+(?:async\\s+)?function\\s+${METHOD}\\s*\\(\\s*([A-Za-z_$][\\w$]{0,40})[^()]{0,200}\\)[^{;]{0,80}\\{\\s*return\\s+(?:await\\s+)?([A-Za-z_$][\\w$]{0,64})\\s*\\(\\s*\\1\\s*\\)\\s*;?\\s*\\}`,
|
|
515
|
+
"y"
|
|
516
|
+
);
|
|
517
|
+
var HANDLER_HEAD_RE = new RegExp(
|
|
518
|
+
`\\bexport\\s+(?:(?:async\\s+)?function\\s+${METHOD}\\s*\\([^()]{0,200}\\)[^{;]{0,80}\\{|const\\s+${METHOD}\\s*(?::[^=;\\n]{0,80})?=\\s*(?:async\\s*)?\\([^()]{0,200}\\)[^{;=]{0,80}=>\\s*\\{)`,
|
|
519
|
+
"y"
|
|
520
|
+
);
|
|
521
|
+
var OTHER_EXPORT_RE = /\bexport\s+(?:let|var)\s+(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b|\bexport\s*\{|\bexport\s*\*/;
|
|
522
|
+
var STR = `"[^"\\n]{0,200}"|'[^'\\n]{0,200}'`;
|
|
523
|
+
var ID = `[A-Za-z_$][\\w$]{0,40}`;
|
|
524
|
+
var READ_DECL_RE = new RegExp(
|
|
525
|
+
`(?:const|let)\\s+(?:([A-Za-z_$][\\w$]{0,40})|\\{[\\s\\w$,]{1,200}\\})\\s*(?::[^=;\\n]{0,80})?=\\s*(?![^;\\n]{0,300}?process\\.env)(?:await\\s+[A-Za-z_$][\\w$]{0,40}\\.json\\(\\s*\\)|(\\[\\s*(?:(?:${STR})\\s*,\\s*){0,20}(?:(?:${STR})\\s*)?\\])|\\(\\s*await\\s+headers\\(\\s*\\)\\s*\\)\\.get\\(\\s*(?:${STR})\\s*\\)(?:\\s*(?:\\|\\||\\?\\?)\\s*(?:${STR}))?|[^;"'\`\\n{}()]{0,200}(?:\\.get\\(\\s*(?:${STR}|[\\w$.]{1,80})\\s*\\)[^;"'\`\\n{}()]{0,100})?);\\s*`,
|
|
526
|
+
"y"
|
|
527
|
+
);
|
|
528
|
+
var ENV_DOT = `process\\.env\\.`;
|
|
529
|
+
var ENV_PUBLIC_EXCL = `(?!(?:NEXT_PUBLIC|PUBLIC|VITE|EXPO_PUBLIC|REACT_APP)_)`;
|
|
530
|
+
var ENV_NAME_TAIL = `\\w{0,60}(?:SECRET|TOKEN|KEY)\\b`;
|
|
531
|
+
var ENV_SECRET = ENV_DOT + ENV_PUBLIC_EXCL + ENV_NAME_TAIL;
|
|
532
|
+
var OPERAND = `(?<![\\w$.])(?!(?:undefined|null)\\b)[A-Za-z_$][\\w$.?]{0,80}(?:\\(\\s*(?:${STR}|[\\w$.]{0,80})\\s*\\))?`;
|
|
533
|
+
var NOT_LIT = `(?!(?:undefined|null)\\b)[A-Za-z_$]`;
|
|
534
|
+
var CMP = `(?:${OPERAND}\\s*!==\\s*${ENV_SECRET}|${ENV_SECRET}\\s*!==\\s*${NOT_LIT}|!\\s*\\(\\s*${OPERAND}\\s*===\\s*${ENV_SECRET}\\s*\\)|!\\s*\\(\\s*${ENV_SECRET}\\s*===\\s*${NOT_LIT}|!\\s*(?:crypto\\s*\\.\\s*)?timingSafeEqual\\s*\\([^;\\n&]{0,300}?${ENV_SECRET})`;
|
|
535
|
+
var COND = `[^;\\n{}&]{0,300}?`;
|
|
536
|
+
var COND_REJECT = `(?![^\\n]{0,300}?!\\s*\\([^;\\n]{0,200}?!==)(?![^\\n]{0,300}?(?:[^!=<>]==(?!=)|!=(?!=)))`;
|
|
537
|
+
var INCLUDES_DECL_RE = new RegExp(
|
|
538
|
+
`(?:const|let)\\s+(${ID})\\s*(?::[^=;\\n]{0,80})?=\\s*(${ID})\\.includes\\(\\s*${ID}\\s*\\)\\s*;\\s*`,
|
|
539
|
+
"y"
|
|
540
|
+
);
|
|
541
|
+
var REJECT_HEAD = `\\)\\s*(?:\\{\\s*(?:console\\.(?:error|warn|log|info)\\s*\\(\\s*(?:${STR})\\s*\\)\\s*;\\s*)?)?(?:throw\\b|return\\b`;
|
|
542
|
+
var REJECT_CODE = `[^;\\n]{0,200}?(?:\\b40[13]\\b|`;
|
|
543
|
+
var REJECT_WORDS = `[Uu]nauthori[sz]ed|[Ff]orbidden))`;
|
|
544
|
+
var REJECT = REJECT_HEAD + REJECT_CODE + REJECT_WORDS;
|
|
545
|
+
var COND_TAIL = `(?:\\?\\.|(?!function\\b)[^;\\n{}&?]){0,300}?`;
|
|
546
|
+
var SECRET_GUARD_RE = new RegExp(`if\\s*\\(${COND_REJECT}${COND}${CMP}${COND_TAIL}${REJECT}`, "y");
|
|
547
|
+
var WS_RE = /(?:\s+|\/\/[^\n]{0,400}(?=\n|$)|\/\*(?:[^*]|\*(?!\/)){0,800}\*\/){0,40}/y;
|
|
548
|
+
var MAX_DECLS = 6;
|
|
549
|
+
function opensWithGuard(body) {
|
|
550
|
+
let i = 1;
|
|
551
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
552
|
+
for (let k = 0; ; k++) {
|
|
553
|
+
WS_RE.lastIndex = i;
|
|
554
|
+
WS_RE.exec(body);
|
|
555
|
+
i = WS_RE.lastIndex;
|
|
556
|
+
if (k === MAX_DECLS) break;
|
|
557
|
+
INCLUDES_DECL_RE.lastIndex = i;
|
|
558
|
+
const inc = INCLUDES_DECL_RE.exec(body);
|
|
559
|
+
if (inc !== null) {
|
|
560
|
+
if (!arrays.has(inc[2])) break;
|
|
561
|
+
arrays.delete(inc[1]);
|
|
562
|
+
i = INCLUDES_DECL_RE.lastIndex;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
READ_DECL_RE.lastIndex = i;
|
|
566
|
+
const d = READ_DECL_RE.exec(body);
|
|
567
|
+
if (d === null) break;
|
|
568
|
+
if (d[1] !== void 0) {
|
|
569
|
+
if (d[2] !== void 0) arrays.add(d[1]);
|
|
570
|
+
else arrays.delete(d[1]);
|
|
571
|
+
}
|
|
572
|
+
i = READ_DECL_RE.lastIndex;
|
|
573
|
+
}
|
|
574
|
+
SECRET_GUARD_RE.lastIndex = i;
|
|
575
|
+
return SECRET_GUARD_RE.test(body);
|
|
576
|
+
}
|
|
577
|
+
function firstMatches(text, re, max) {
|
|
578
|
+
const found = [];
|
|
579
|
+
re.lastIndex = 0;
|
|
580
|
+
for (let m = re.exec(text); m !== null && found.length < max; m = re.exec(text)) found.push(m);
|
|
581
|
+
re.lastIndex = 0;
|
|
582
|
+
return found;
|
|
583
|
+
}
|
|
584
|
+
var esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
585
|
+
function secretGuardedRoutes(files) {
|
|
586
|
+
const out = /* @__PURE__ */ new Set();
|
|
587
|
+
for (const f of files) {
|
|
588
|
+
if (!ROUTE_FILE_RE.test(f.path) || OTHER_EXPORT_RE.test(f.content)) continue;
|
|
589
|
+
const exported = firstMatches(f.content, HANDLER_EXPORT_RE, 8);
|
|
590
|
+
if (exported.length === 0 || exported.length > 7) continue;
|
|
591
|
+
const callees = /* @__PURE__ */ new Set();
|
|
592
|
+
let readable = true;
|
|
593
|
+
for (const e of exported) {
|
|
594
|
+
DELEGATING_HANDLER_RE.lastIndex = e.index;
|
|
595
|
+
const h = DELEGATING_HANDLER_RE.exec(f.content);
|
|
596
|
+
if (h !== null) {
|
|
597
|
+
callees.add(h[2]);
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
HANDLER_HEAD_RE.lastIndex = e.index;
|
|
601
|
+
const head = HANDLER_HEAD_RE.exec(f.content);
|
|
602
|
+
const open = head === null ? -1 : e.index + head[0].length - 1;
|
|
603
|
+
if (open === -1 || !opensWithGuard(f.content.slice(open, open + 4e3))) {
|
|
604
|
+
readable = false;
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (!readable) continue;
|
|
609
|
+
if ([...callees].every((fn) => calleeIsGuarded(fn, f.content, files))) out.add(f.path);
|
|
610
|
+
}
|
|
611
|
+
return out;
|
|
612
|
+
}
|
|
613
|
+
function calleeIsGuarded(fn, route, files) {
|
|
614
|
+
let spec = null;
|
|
615
|
+
for (const m of route.matchAll(/\bimport\s*\{([^{}]{0,1000})\}\s*from\s*["']([^"'\n]{1,200})["']/g)) {
|
|
616
|
+
if (m[1].split(",").some((n) => n.trim() === fn)) {
|
|
617
|
+
spec = m[2];
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if (spec === null) return false;
|
|
622
|
+
const tail = spec.replace(/^(?:@|~)\//, "").replace(/^(?:\.\.?\/)+/, "");
|
|
623
|
+
const tailRe = new RegExp(`(?:^|/)${esc(tail)}(?:\\.[jt]sx?|/index\\.[jt]sx?)$`);
|
|
624
|
+
const targets = files.filter((g) => tailRe.test(g.path));
|
|
625
|
+
if (targets.length !== 1) return false;
|
|
626
|
+
const F = esc(fn);
|
|
627
|
+
const defRe = new RegExp(
|
|
628
|
+
`\\bfunction\\s+${F}\\s*\\([^()]{0,200}\\)[^{;]{0,80}\\{|\\b(?:const|let)\\s+${F}\\s*(?::[^=;\\n]{0,80})?=\\s*(?:async\\s*)?\\([^()]{0,200}\\)[^{;=]{0,80}=>\\s*\\{`,
|
|
629
|
+
"g"
|
|
630
|
+
);
|
|
631
|
+
const defs = [...targets[0].content.matchAll(defRe)];
|
|
632
|
+
if (defs.length !== 1) return false;
|
|
633
|
+
const open = defs[0].index + defs[0][0].length - 1;
|
|
634
|
+
return opensWithGuard(targets[0].content.slice(open, open + 4e3));
|
|
635
|
+
}
|
|
636
|
+
|
|
508
637
|
// src/project-context.ts
|
|
509
638
|
var TOML_FN_SECTION_RE = /^\s*\[functions\.(?:"([^"]+)"|([A-Za-z0-9._-]+))\]\s*$/;
|
|
510
639
|
var TOML_VERIFY_JWT_RE = /^\s*verify_jwt\s*=\s*(true|false)\s*(?:#.*)?$/i;
|
|
@@ -538,6 +667,8 @@ function buildProjectContext(files) {
|
|
|
538
667
|
const parsed = parseSupabaseConfig(config.content);
|
|
539
668
|
if (parsed.size > 0) ctx.supabaseEdgeVerifyJwt = parsed;
|
|
540
669
|
}
|
|
670
|
+
const guarded = secretGuardedRoutes(files);
|
|
671
|
+
if (guarded.size > 0) ctx.secretGuardedRoutes = guarded;
|
|
541
672
|
return ctx;
|
|
542
673
|
}
|
|
543
674
|
|
|
@@ -674,7 +805,7 @@ function isTestPath(filePath) {
|
|
|
674
805
|
if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
|
|
675
806
|
return false;
|
|
676
807
|
}
|
|
677
|
-
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
808
|
+
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.(?:json|xml)|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
678
809
|
function isSbomPath(filePath) {
|
|
679
810
|
return SBOM_FILE_RE.test(normalize(filePath));
|
|
680
811
|
}
|
|
@@ -1902,8 +2033,20 @@ function isInsideFixMessage(content, matchIndex) {
|
|
|
1902
2033
|
function filterSilenced(matches, content, ruleId) {
|
|
1903
2034
|
if (matches.length === 0) return matches;
|
|
1904
2035
|
const lines = content.split("\n");
|
|
1905
|
-
const
|
|
1906
|
-
return matches.filter((m) =>
|
|
2036
|
+
const silencedByLine = /* @__PURE__ */ new Map();
|
|
2037
|
+
return matches.filter((m) => {
|
|
2038
|
+
let silenced = silencedByLine.get(m.line);
|
|
2039
|
+
if (silenced === void 0) {
|
|
2040
|
+
silenced = isLineSilenced(lines, m.line - 1, ruleId);
|
|
2041
|
+
silencedByLine.set(m.line, silenced);
|
|
2042
|
+
}
|
|
2043
|
+
return !silenced;
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
function lineStartOffsets(content) {
|
|
2047
|
+
const starts = [0];
|
|
2048
|
+
for (let i = content.indexOf("\n"); i !== -1; i = content.indexOf("\n", i + 1)) starts.push(i + 1);
|
|
2049
|
+
return starts;
|
|
1907
2050
|
}
|
|
1908
2051
|
function findMatches(content, pattern, rule, filePath, fixTemplate) {
|
|
1909
2052
|
const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
@@ -1926,12 +2069,24 @@ function findMatchesAt(content, found, rule, filePath, fixTemplate) {
|
|
|
1926
2069
|
let scanned = 0;
|
|
1927
2070
|
let lineNum = 1;
|
|
1928
2071
|
const MAX_MATCHES = 500;
|
|
2072
|
+
let skipLineStart = -1;
|
|
2073
|
+
let skipLine = false;
|
|
2074
|
+
let snippetLine = -1;
|
|
2075
|
+
let snippet = "";
|
|
1929
2076
|
for (const m of found) {
|
|
1930
|
-
|
|
1931
|
-
if (
|
|
2077
|
+
const lineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
2078
|
+
if (lineStart !== skipLineStart) {
|
|
2079
|
+
skipLineStart = lineStart;
|
|
2080
|
+
skipLine = isCommentLine(content, m.index) || isInsideFixMessage(content, m.index);
|
|
2081
|
+
}
|
|
2082
|
+
if (skipLine) continue;
|
|
1932
2083
|
for (; scanned < m.index; scanned++) {
|
|
1933
2084
|
if (content.charCodeAt(scanned) === 10) lineNum++;
|
|
1934
2085
|
}
|
|
2086
|
+
if (lineNum !== snippetLine) {
|
|
2087
|
+
snippetLine = lineNum;
|
|
2088
|
+
snippet = getSnippet(content, lineNum);
|
|
2089
|
+
}
|
|
1935
2090
|
matches.push({
|
|
1936
2091
|
rule: rule.id,
|
|
1937
2092
|
title: rule.title,
|
|
@@ -1939,7 +2094,7 @@ function findMatchesAt(content, found, rule, filePath, fixTemplate) {
|
|
|
1939
2094
|
category: rule.category,
|
|
1940
2095
|
file: filePath,
|
|
1941
2096
|
line: lineNum,
|
|
1942
|
-
snippet
|
|
2097
|
+
snippet,
|
|
1943
2098
|
fix: fixTemplate?.(m)
|
|
1944
2099
|
});
|
|
1945
2100
|
if (matches.length >= MAX_MATCHES) break;
|
|
@@ -2012,13 +2167,40 @@ function dbUrlLacksRealCredential(url) {
|
|
|
2012
2167
|
const userinfo = rest.slice(0, at);
|
|
2013
2168
|
const colon = userinfo.indexOf(":");
|
|
2014
2169
|
const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
|
|
2015
|
-
const
|
|
2170
|
+
const rawPass = colon < 0 ? "" : userinfo.slice(colon + 1);
|
|
2171
|
+
const pass = colon < 0 ? "" : decodeURIComponentSafe(rawPass);
|
|
2016
2172
|
if (!pass) return true;
|
|
2173
|
+
const portShaped = /^(\d{1,5})(?:\/[\w.-]{0,64})?[?#"'`][^@]*$/.exec(rawPass);
|
|
2174
|
+
if (portShaped && Number(portShaped[1]) <= 65535) return true;
|
|
2017
2175
|
if (isFormatPlaceholder(pass)) return true;
|
|
2018
2176
|
if (isPlaceholderSecret(pass)) return true;
|
|
2019
2177
|
if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
|
|
2020
2178
|
return false;
|
|
2021
2179
|
}
|
|
2180
|
+
var LOOPBACK_DEV_USER_RE = /^(?:postgres|root|admin|user|test|dev|mysql|mongo|mongodb|redis|sa|guest|app|example)$/i;
|
|
2181
|
+
function isLoopbackDevDefault(url) {
|
|
2182
|
+
const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
|
|
2183
|
+
const at = rest.lastIndexOf("@");
|
|
2184
|
+
if (at < 0) return false;
|
|
2185
|
+
const userinfo = rest.slice(0, at);
|
|
2186
|
+
const colon = userinfo.indexOf(":");
|
|
2187
|
+
if (colon < 0) return false;
|
|
2188
|
+
const user = userinfo.slice(0, colon);
|
|
2189
|
+
const pass = decodeURIComponentSafe(userinfo.slice(colon + 1));
|
|
2190
|
+
if (user !== pass || !LOOPBACK_DEV_USER_RE.test(user)) return false;
|
|
2191
|
+
let host = rest.slice(at + 1);
|
|
2192
|
+
const cut = host.search(/[/?#]/);
|
|
2193
|
+
if (cut >= 0) host = host.slice(0, cut);
|
|
2194
|
+
if (host.startsWith("[")) {
|
|
2195
|
+
const end = host.indexOf("]");
|
|
2196
|
+
host = end >= 0 ? host.slice(1, end) : host;
|
|
2197
|
+
} else {
|
|
2198
|
+
const port = host.lastIndexOf(":");
|
|
2199
|
+
if (port >= 0) host = host.slice(0, port);
|
|
2200
|
+
}
|
|
2201
|
+
const h = host.toLowerCase();
|
|
2202
|
+
return h === "localhost" || h === "::1" || h === "0.0.0.0" || h === "host.docker.internal" || /^127(?:\.\d{1,3}){0,3}$/.test(h);
|
|
2203
|
+
}
|
|
2022
2204
|
function decodeURIComponentSafe(value) {
|
|
2023
2205
|
try {
|
|
2024
2206
|
return decodeURIComponent(value);
|
|
@@ -2027,10 +2209,12 @@ function decodeURIComponentSafe(value) {
|
|
|
2027
2209
|
}
|
|
2028
2210
|
}
|
|
2029
2211
|
var FORMAT_PLACEHOLDER_MAX = 256;
|
|
2212
|
+
var FORMAT_FIELD_RE = /^\{(?:[a-z_][a-z0-9_]{0,63}|[A-Z_][A-Z0-9_]{0,63})(?:\.(?:[a-z_][a-z0-9_]{0,63}|[A-Z_][A-Z0-9_]{0,63})){0,4}(?:\[[\w'"]{1,64}\])?(?:![rsa])?(?::[<>=^]?\d{0,3}[sd]?)?\}$/;
|
|
2030
2213
|
function isFormatPlaceholder(value) {
|
|
2031
2214
|
const v = value.trim();
|
|
2032
2215
|
if (!v) return true;
|
|
2033
2216
|
if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
|
|
2217
|
+
if (FORMAT_FIELD_RE.test(v)) return true;
|
|
2034
2218
|
if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
|
|
2035
2219
|
if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
|
|
2036
2220
|
return false;
|
|
@@ -2215,7 +2399,12 @@ var hardcodedSecrets = {
|
|
|
2215
2399
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
2216
2400
|
}
|
|
2217
2401
|
}
|
|
2218
|
-
if (pi === 10
|
|
2402
|
+
if (pi === 10) {
|
|
2403
|
+
const url = matchedText[ri] ?? "";
|
|
2404
|
+
if (dbUrlLacksRealCredential(url)) continue;
|
|
2405
|
+
matches.push(isLoopbackDevDefault(url) ? { ...rm, severity: "low" } : textHasLiveCredential(url) ? { ...rm, live: true } : rm);
|
|
2406
|
+
continue;
|
|
2407
|
+
}
|
|
2219
2408
|
const matched = matchedText[ri] ?? "";
|
|
2220
2409
|
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
2221
2410
|
}
|
|
@@ -2636,6 +2825,23 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
|
|
|
2636
2825
|
}
|
|
2637
2826
|
return hits;
|
|
2638
2827
|
}
|
|
2828
|
+
var NAMED_ROUTE_EXPORT_RE = /export\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/i;
|
|
2829
|
+
var SERVER_ACTION_WRITE_RE = [
|
|
2830
|
+
/\b(?:kv|redis|cache|upstash)\s*\.\s*(?:set|del|hset|hdel|incr\w{0,4}|decr\w{0,4}|lpush|rpush|sadd|srem|zadd|expire|getdel)\s*\(/,
|
|
2831
|
+
/\b(?:stripe|paypal|braintree|lemonsqueezy|paddle)\s*\.\s*\w{1,40}\s*\.\s*(?:create|update|del|cancel|capture|refund)\w{0,10}\s*\(/,
|
|
2832
|
+
/\bfetch\s*\([^;]{0,400}?\bmethod\s*(?::\s*(?=["'`](?:POST|PUT|PATCH|DELETE)\b|`\$\{|[A-Za-z_$(\[])|(?=[,}]))/i,
|
|
2833
|
+
/\b(?:fs(?:\.promises)?\s*\.\s*)?(?:writeFile|appendFile|unlink|rm|rmdir|rename|copyFile)(?:Sync)?\s*\(/,
|
|
2834
|
+
/\.\s*(?:del|deleteOne|deleteMany|insertOne|insertMany|updateOne|updateMany|replaceOne|bulkWrite|upsert|increment|decrement|destroy|truncate)\s*\(/,
|
|
2835
|
+
/cookies\(\)\)?\s*\.\s*set\(\s*["'`][\w-]*(?:session|token|auth|jwt|sid|role|user|admin)/i,
|
|
2836
|
+
...TANSTACK_MUTATION_RE,
|
|
2837
|
+
/\b(?:prisma|db|tx)\s*\.\s*\w{1,64}\s*\.\s*(?:create|createMany|insert\w{0,10})\s*\(/,
|
|
2838
|
+
/\b(?:db|tx)\s*\.\s*insert\s*\(\s*\w/,
|
|
2839
|
+
/\.from\(\s*["'`][\w.-]{1,64}["'`]\s*\)\s*\.\s*insert\s*\(/,
|
|
2840
|
+
/\bINSERT\s+INTO\b/i,
|
|
2841
|
+
/\.collection\(\s*["'`][\w.-]{1,64}["'`]\s*\)\s*\.\s*(?:insert\w{0,8}|update\w{0,8}|delete\w{0,8}|replaceOne|findOneAndUpdate|findOneAndDelete)\s*\(/,
|
|
2842
|
+
/\b(?!(?:Object|Array|Promise|Reflect|Buffer|Math|JSON|Date|Intl|Symbol|Map|Set|WeakMap|Response|NextResponse|Request|URL|Error)\b)[A-Z]\w{0,40}\.(?:create|insertMany|updateOne|updateMany|deleteOne|deleteMany|findByIdAndUpdate|findByIdAndDelete|findOneAndUpdate|findOneAndDelete|destroy)\s*\(/,
|
|
2843
|
+
/\b(?:delete|remove|update|set|grant|revoke|ban|promote|demote|transfer|refund|cancel|reset|change)\w{0,20}(?:User|Account|Role|Admin|Order|Payment|Subscription|Member|Permission|Password|Email|Org|Organization|Team|Project|Invoice|Profile|Balance|Credits?|Plan|Post|Comment)s?\s*\(/
|
|
2844
|
+
];
|
|
2639
2845
|
var missingAuthMiddleware = {
|
|
2640
2846
|
id: "VC003",
|
|
2641
2847
|
title: "API Route Missing Authentication",
|
|
@@ -2661,8 +2867,9 @@ var missingAuthMiddleware = {
|
|
|
2661
2867
|
/module\.exports\s*=\s*(?:async\s+)?(?:function\b|\()/g
|
|
2662
2868
|
);
|
|
2663
2869
|
}
|
|
2870
|
+
const useServerPatterns = [];
|
|
2664
2871
|
if (USE_SERVER_DIRECTIVE_RE.test(content)) {
|
|
2665
|
-
|
|
2872
|
+
useServerPatterns.push(
|
|
2666
2873
|
/export\s+(?:async\s+)?function\s+\w+\s*\(/g,
|
|
2667
2874
|
/export\s+const\s+\w+\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?\(/g
|
|
2668
2875
|
);
|
|
@@ -2748,24 +2955,34 @@ var missingAuthMiddleware = {
|
|
|
2748
2955
|
);
|
|
2749
2956
|
const maskedForScope = maskOutboundAuthNoise(maskComments(content));
|
|
2750
2957
|
const codeForAuth = maskOutboundAuthNoise(codeOnly);
|
|
2751
|
-
const
|
|
2958
|
+
const scopeCache = /* @__PURE__ */ new Map();
|
|
2959
|
+
const scopeAt = (index) => {
|
|
2960
|
+
const cached = scopeCache.get(index);
|
|
2961
|
+
if (cached !== void 0) return cached;
|
|
2752
2962
|
const bodyStart = maskedForScope.indexOf("{", index);
|
|
2753
2963
|
const probe = bodyStart === -1 ? index : bodyStart + 1;
|
|
2754
2964
|
const scope = enclosingHandler(maskedForScope, probe);
|
|
2755
|
-
|
|
2965
|
+
scopeCache.set(index, scope);
|
|
2966
|
+
return scope;
|
|
2967
|
+
};
|
|
2968
|
+
let fileHasAuth;
|
|
2969
|
+
const handlerHasAuth = (index) => {
|
|
2970
|
+
const scope = scopeAt(index);
|
|
2971
|
+
if (scope === null) return fileHasAuth ??= handlerAuthPatterns.some((p) => p.test(codeForAuth));
|
|
2756
2972
|
return handlerAuthPatterns.some((p) => p.test(scope));
|
|
2757
2973
|
};
|
|
2758
2974
|
const matches = [];
|
|
2975
|
+
const routeLines = /* @__PURE__ */ new Set();
|
|
2976
|
+
const authFix = "Add authentication middleware to protect this route. Check the user's session/token before processing the request. If the endpoint is public by design (an OG image, an embeddable badge, a health check), add an inline `// VC003-OK: <reason>` comment above the handler to silence.";
|
|
2759
2977
|
for (const pattern of serverSide ? routePatterns : []) {
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
);
|
|
2978
|
+
const found = findMatches(content, pattern, missingAuthMiddleware, filePath, () => authFix);
|
|
2979
|
+
for (const foundMatch of found) routeLines.add(foundMatch.line);
|
|
2980
|
+
matches.push(...found);
|
|
2981
|
+
}
|
|
2982
|
+
if (serverSide) {
|
|
2983
|
+
for (const pattern of useServerPatterns) {
|
|
2984
|
+
matches.push(...findMatches(content, pattern, missingAuthMiddleware, filePath, () => authFix));
|
|
2985
|
+
}
|
|
2769
2986
|
}
|
|
2770
2987
|
if (matches.length === 0 && serverSide && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
|
|
2771
2988
|
const fnName = supabaseFunctionName(filePath);
|
|
@@ -2792,9 +3009,21 @@ var missingAuthMiddleware = {
|
|
|
2792
3009
|
}
|
|
2793
3010
|
const indexOfLine = (line) => lineStarts[Math.max(0, Math.min(line - 1, lineStarts.length - 1))];
|
|
2794
3011
|
const isPublicRootGet = (index) => /\.\s*get\s*\(\s*["'`]\/["'`]\s*,/i.test(content.slice(index, index + 240));
|
|
3012
|
+
const lineText = (index) => {
|
|
3013
|
+
const end = content.indexOf("\n", index);
|
|
3014
|
+
return content.slice(index, end === -1 ? content.length : end);
|
|
3015
|
+
};
|
|
3016
|
+
const secretGuarded = project?.secretGuardedRoutes?.has(filePath) === true;
|
|
2795
3017
|
const unauthenticated = matches.filter((m) => {
|
|
2796
3018
|
const index = indexOfLine(m.line);
|
|
2797
|
-
|
|
3019
|
+
if (isPublicRootGet(index) || handlerHasAuth(index)) return false;
|
|
3020
|
+
const namedExport = NAMED_ROUTE_EXPORT_RE.exec(lineText(index));
|
|
3021
|
+
if (namedExport && secretGuarded && /^[A-Z]+$/.test(namedExport[1])) return false;
|
|
3022
|
+
if (useServerPatterns.length > 0 && (!routeLines.has(m.line) || namedExport !== null && !/^[A-Z]+$/.test(namedExport[1]))) {
|
|
3023
|
+
const scope = scopeAt(index);
|
|
3024
|
+
if (scope !== null && !SERVER_ACTION_WRITE_RE.some((re) => re.test(scope))) return false;
|
|
3025
|
+
}
|
|
3026
|
+
return true;
|
|
2798
3027
|
});
|
|
2799
3028
|
if (serverSide || tanstackCandidate) {
|
|
2800
3029
|
for (const idx of unauthenticatedTanStackHandlers(maskedForScope, filePath)) {
|
|
@@ -3194,6 +3423,9 @@ var noRateLimiting = {
|
|
|
3194
3423
|
check(content, filePath) {
|
|
3195
3424
|
const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
|
|
3196
3425
|
if (!isEntryFile) return [];
|
|
3426
|
+
if (/(?:^|\/)(?:lib|libs|utils?|helpers?|components|hooks|shared|types)\/(?:[^/]+\/)*index\.[jt]sx?$/.test(filePath) && !/\.listen\s*\(|\bcreateServer\s*\(|\bexpress\s*\(\s*\)|\bFastify\s*\(|\bnew\s+(?:Koa|Hono)\b/.test(content)) {
|
|
3427
|
+
return [];
|
|
3428
|
+
}
|
|
3197
3429
|
const isServer = /(?:from\s+|require\s*\(\s*)["'`](?:express|hono|fastify|koa|koa-router|@koa\/[\w-]+|@hono\/[\w-]+|next(?:\/server)?|next-auth(?:\/[\w-]+)?|@clerk\/nextjs(?:\/server)?)["'`]/.test(content) || // Case-sensitive framework types — `adNext` and `nextLap` can't match.
|
|
3198
3430
|
/\b(?:NextApiRequest|NextApiResponse|NextRequest|NextResponse)\b/.test(content) || /\b(?:express|fastify|createServer)\s*\(/.test(content) || /\bnew\s+(?:Hono|Koa)\s*\(/.test(content) || /\b(?:Deno|Bun)\.serve\s*\(/.test(content) || /\.listen\s*\(/.test(content);
|
|
3199
3431
|
if (!isServer) return [];
|
|
@@ -3469,6 +3701,9 @@ var evalUsage = {
|
|
|
3469
3701
|
const hasEvalInString = /["'`]eval(?:-source-map|["'`])/i.test(content);
|
|
3470
3702
|
if (hasEvalInString && !/\beval\s*\([^)]{0,500}(?:req\.|body\.|input|params|user|data)/i.test(content)) return [];
|
|
3471
3703
|
const matches = [];
|
|
3704
|
+
let evalLineStarts;
|
|
3705
|
+
let evalLastLine = -1;
|
|
3706
|
+
let evalLastKeep = false;
|
|
3472
3707
|
for (const p of patterns) {
|
|
3473
3708
|
const rawMatches = findMatches(
|
|
3474
3709
|
content,
|
|
@@ -3478,11 +3713,18 @@ var evalUsage = {
|
|
|
3478
3713
|
() => "Replace eval() with JSON.parse() for data, or a proper parser for expressions. Never pass user input to eval()."
|
|
3479
3714
|
);
|
|
3480
3715
|
for (const rm of rawMatches) {
|
|
3481
|
-
|
|
3716
|
+
if (rm.line === evalLastLine) {
|
|
3717
|
+
if (evalLastKeep) matches.push(rm);
|
|
3718
|
+
continue;
|
|
3719
|
+
}
|
|
3720
|
+
evalLastLine = rm.line;
|
|
3721
|
+
evalLastKeep = false;
|
|
3722
|
+
const lineStart = (evalLineStarts ??= lineStartOffsets(content))[rm.line - 1];
|
|
3482
3723
|
const lineEnd = content.indexOf("\n", lineStart + 1);
|
|
3483
3724
|
const lineText = content.substring(lineStart, lineEnd === -1 ? content.length : lineEnd);
|
|
3484
3725
|
if (/devtool|source-map/i.test(lineText)) continue;
|
|
3485
3726
|
if (/(?:description|title|message)\s*[:=]/i.test(lineText)) continue;
|
|
3727
|
+
evalLastKeep = true;
|
|
3486
3728
|
matches.push(rm);
|
|
3487
3729
|
}
|
|
3488
3730
|
}
|
|
@@ -3501,14 +3743,22 @@ var unvalidatedRedirect = {
|
|
|
3501
3743
|
const matches = [];
|
|
3502
3744
|
const navPattern = /(?:window\.location(?:\.href)?\s*=\s*|window\.location\.(?:assign|replace)\s*\(\s*)([^;\n)]+)/g;
|
|
3503
3745
|
let m;
|
|
3746
|
+
let commentLineStart = -1;
|
|
3747
|
+
let commentLine = false;
|
|
3748
|
+
let silenceLines;
|
|
3504
3749
|
while ((m = navPattern.exec(content)) !== null) {
|
|
3505
|
-
|
|
3750
|
+
const navLineStart = content.lastIndexOf("\n", m.index - 1) + 1;
|
|
3751
|
+
if (navLineStart !== commentLineStart) {
|
|
3752
|
+
commentLineStart = navLineStart;
|
|
3753
|
+
commentLine = isCommentLine(content, m.index);
|
|
3754
|
+
}
|
|
3755
|
+
if (commentLine) continue;
|
|
3506
3756
|
const value = m[1].trim();
|
|
3507
3757
|
const hasInterpolation = /\$\{/.test(value);
|
|
3508
3758
|
const isPureLiteral = /^["'`][^"'`]*["'`]$/.test(value);
|
|
3509
3759
|
if (!hasInterpolation && isPureLiteral) continue;
|
|
3510
|
-
if (isInlineSilenced(content, m.index, "VC016")) continue;
|
|
3511
3760
|
const line = lineNumberAt(content, m.index);
|
|
3761
|
+
if (isLineSilenced(silenceLines ??= content.split("\n"), line - 1, "VC016")) continue;
|
|
3512
3762
|
matches.push({
|
|
3513
3763
|
rule: "VC016",
|
|
3514
3764
|
title: unvalidatedRedirect.title,
|
|
@@ -3533,6 +3783,28 @@ var unvalidatedRedirect = {
|
|
|
3533
3783
|
var CLIENT_PREFERENCE_COOKIE_NAME_RE = /(?:consent|preferences?|prefs?)/i;
|
|
3534
3784
|
var CLIENT_PREFERENCE_COOKIE_VALUE_RE = /(?:choice|consent|preferences?|prefs?|accepted|essential(?:-only)?|declined|rejected|granted|denied|opt(?:ed)?[-_ ]?(?:in|out))/i;
|
|
3535
3785
|
var SENSITIVE_CLIENT_COOKIE_RE = /(?:auth|session|token|jwt|bearer|credential|password|passwd|secret|csrf|xsrf|refresh)/i;
|
|
3786
|
+
var UI_FLAG_COOKIE_NAME_RE = /^(?:theme|color-?scheme|sidebar|welcome-toast|toast|locale|lang|language|dir|collapsed|expanded|layout|banner|dismissed|density|contrast|font|font-?size|motion|reduced-?motion|color-mode|dark-mode|ui)$/i;
|
|
3787
|
+
var UI_FLAG_COOKIE_ASSIGN_RE = /\b(?:document\s*\.\s*)?cookie\s*=\s*(["'`])([^"'`]*)\1/gi;
|
|
3788
|
+
var UI_FLAG_SENSITIVE_NAME_RE = /(?:sess|sid(?!ebar)|login|user|uid|key|account|admin|role|remember|__host-|__secure-)/i;
|
|
3789
|
+
var UI_FLAG_COOKIE_BODY_RE = /^[A-Za-z0-9_.-]+=[A-Za-z0-9_.-]+(?:\s*;\s*(?:max-age=-?\d{1,10}|path=\/[\w./-]{0,100}|expires=[\w ,:+-]{1,40}|samesite=(?:lax|strict|none)|secure|domain=\.?[\w.-]{1,100})){0,6}\s*;?\s*$/i;
|
|
3790
|
+
function isConstantUiFlagCookieWrite(line, nextLine) {
|
|
3791
|
+
const next = nextLine.trimStart();
|
|
3792
|
+
if (next.startsWith("+") || next.startsWith(".") || next.startsWith("`")) return false;
|
|
3793
|
+
if (/\bset-cookie\b|\bsetCookie\b|res\.cookie\s*\(/i.test(line)) return false;
|
|
3794
|
+
const re = new RegExp(UI_FLAG_COOKIE_ASSIGN_RE.source, "gi");
|
|
3795
|
+
let saw = false;
|
|
3796
|
+
let assignment;
|
|
3797
|
+
while ((assignment = re.exec(line)) !== null) {
|
|
3798
|
+
saw = true;
|
|
3799
|
+
const body = assignment[2];
|
|
3800
|
+
if (!UI_FLAG_COOKIE_BODY_RE.test(body)) return false;
|
|
3801
|
+
if (SENSITIVE_CLIENT_COOKIE_RE.test(body)) return false;
|
|
3802
|
+
const name = body.split("=")[0];
|
|
3803
|
+
if (!UI_FLAG_COOKIE_NAME_RE.test(name)) return false;
|
|
3804
|
+
if (UI_FLAG_SENSITIVE_NAME_RE.test(name)) return false;
|
|
3805
|
+
}
|
|
3806
|
+
return saw;
|
|
3807
|
+
}
|
|
3536
3808
|
function isClearlyNonSensitivePreferenceCookieWrite(content, line) {
|
|
3537
3809
|
const assignment = /\bdocument\s*\.\s*cookie\s*=\s*(.+)$/i.exec(line);
|
|
3538
3810
|
if (!assignment) return false;
|
|
@@ -3564,7 +3836,7 @@ var insecureCookies = {
|
|
|
3564
3836
|
check(content, filePath) {
|
|
3565
3837
|
if (isTestFile(filePath)) return [];
|
|
3566
3838
|
if (!/cookie/i.test(content)) return [];
|
|
3567
|
-
const setCookiePattern = /(
|
|
3839
|
+
const setCookiePattern = /(?:\bset-cookie|\bsetCookie|\bcookie\s*=|res\.cookie\s*\()/i;
|
|
3568
3840
|
if (!setCookiePattern.test(content)) return [];
|
|
3569
3841
|
const hasHttpOnly = /httpOnly\s*:\s*true|httponly/i.test(content);
|
|
3570
3842
|
const hasSecure = /secure\s*:\s*(?!false\b)\S/i.test(content) || /;\s*secure/i.test(content);
|
|
@@ -3583,12 +3855,18 @@ var insecureCookies = {
|
|
|
3583
3855
|
() => `Add missing cookie flags: ${missing.join(", ")}. Example: { httpOnly: true, secure: true, sameSite: 'lax' }`
|
|
3584
3856
|
);
|
|
3585
3857
|
const lines = content.split("\n");
|
|
3858
|
+
const uiFlagMemo = /* @__PURE__ */ new Map();
|
|
3586
3859
|
for (const match of rawMatches) {
|
|
3587
3860
|
const line = lines[match.line - 1] ?? "";
|
|
3588
3861
|
if (!hasHttpOnly && isClearlyNonSensitivePreferenceCookieWrite(content, line)) {
|
|
3589
3862
|
continue;
|
|
3590
3863
|
}
|
|
3591
|
-
|
|
3864
|
+
let info = uiFlagMemo.get(match.line);
|
|
3865
|
+
if (info === void 0) {
|
|
3866
|
+
info = isConstantUiFlagCookieWrite(line, lines[match.line] ?? "");
|
|
3867
|
+
uiFlagMemo.set(match.line, info);
|
|
3868
|
+
}
|
|
3869
|
+
matches.push(info ? { ...match, severity: "info" } : match);
|
|
3592
3870
|
}
|
|
3593
3871
|
}
|
|
3594
3872
|
return matches;
|
|
@@ -3699,9 +3977,9 @@ var hardcodedJWTSecret = {
|
|
|
3699
3977
|
check(content, filePath) {
|
|
3700
3978
|
if (filePath.endsWith(".example") || filePath.endsWith(".template") || filePath.includes("test")) return [];
|
|
3701
3979
|
const patterns = [
|
|
3702
|
-
/jwt\.sign\s*\([^,]
|
|
3703
|
-
/jwt\.verify\s*\([^,]
|
|
3704
|
-
/jsonwebtoken
|
|
3980
|
+
/jwt\.sign\s*\([^,]{1,300},\s*["'`][^"'`]{3,}["'`]/g,
|
|
3981
|
+
/jwt\.verify\s*\([^,]{1,300},\s*["'`][^"'`]{3,}["'`]/g,
|
|
3982
|
+
/jsonwebtoken.{0,300}secret\s*[:=]\s*["'`][^"'`]{3,}["'`]/gi,
|
|
3705
3983
|
/JWT_SECRET\s*[:=]\s*["'`][^"'`]{3,}["'`]/g
|
|
3706
3984
|
];
|
|
3707
3985
|
const matches = [];
|
|
@@ -3734,19 +4012,49 @@ var missingHTTPS = {
|
|
|
3734
4012
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3735
4013
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
3736
4014
|
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;
|
|
3737
|
-
const
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
() => "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains"
|
|
3743
|
-
);
|
|
4015
|
+
const httpIndexes = [];
|
|
4016
|
+
const rawMatches = findMatches(content, httpPattern, missingHTTPS, filePath, (m) => {
|
|
4017
|
+
httpIndexes.push(m.index);
|
|
4018
|
+
return "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains";
|
|
4019
|
+
});
|
|
3744
4020
|
const lines = rawMatches.length > 0 ? content.split("\n") : [];
|
|
3745
|
-
|
|
4021
|
+
const lineStarts = [];
|
|
4022
|
+
if (rawMatches.length > 0) {
|
|
4023
|
+
let acc = 0;
|
|
4024
|
+
for (const line of lines) {
|
|
4025
|
+
lineStarts.push(acc);
|
|
4026
|
+
acc += line.length + 1;
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
const schemaKeyOnLine = /* @__PURE__ */ new Map();
|
|
4030
|
+
const tsaOnLine = /* @__PURE__ */ new Map();
|
|
4031
|
+
const firstSchemaKey = (line, lineNo) => {
|
|
4032
|
+
const cached = schemaKeyOnLine.get(lineNo);
|
|
4033
|
+
if (cached !== void 0) return cached;
|
|
4034
|
+
const key = /(?<![\w$])["']?\$(?:schema|id|ref)["']?\s*:/.exec(line);
|
|
4035
|
+
const at = key ? key.index : -1;
|
|
4036
|
+
schemaKeyOnLine.set(lineNo, at);
|
|
4037
|
+
return at;
|
|
4038
|
+
};
|
|
4039
|
+
for (let i = 0; i < rawMatches.length; i++) {
|
|
4040
|
+
const rm = rawMatches[i];
|
|
3746
4041
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3747
4042
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3748
|
-
if (
|
|
3749
|
-
|
|
4043
|
+
if (firstSchemaKey(matchText, rm.line) >= 0) {
|
|
4044
|
+
const col = httpIndexes[i] - (lineStarts[rm.line - 1] ?? 0);
|
|
4045
|
+
const lookback = matchText.slice(Math.max(0, col - 48), col);
|
|
4046
|
+
if (/(?<![\w$])["']?\$(?:schema|id)["']?\s*:\s*["']?\s*$/.test(lookback)) continue;
|
|
4047
|
+
if (/(?<![\w$])["']?\$ref["']?\s*:\s*["']?\s*$/.test(lookback)) {
|
|
4048
|
+
const host = (/https?:\/\/([^/"'\s:?#]+)/i.exec(matchText.slice(col, col + 300))?.[1] ?? "").toLowerCase();
|
|
4049
|
+
if (host === "json-schema.org" || host.endsWith(".json-schema.org")) continue;
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
let tsa = tsaOnLine.get(rm.line);
|
|
4053
|
+
if (tsa === void 0) {
|
|
4054
|
+
tsa = /--\s*tsaurl\b|\btsaurl\b|timestamp\.(?:digicert|sectigo|comodoca|globalsign|entrust|geotrust|verisign|apple)\.|timestamp\.acs\.microsoft\.com|freetsa\.org/i.test(matchText);
|
|
4055
|
+
tsaOnLine.set(rm.line, tsa);
|
|
4056
|
+
}
|
|
4057
|
+
if (tsa) continue;
|
|
3750
4058
|
matches.push(rm);
|
|
3751
4059
|
}
|
|
3752
4060
|
return matches;
|
|
@@ -3775,7 +4083,7 @@ var exposedDebugMode = {
|
|
|
3775
4083
|
// Debug endpoints that leak environment / process internals in the
|
|
3776
4084
|
// response body. Very high-signal — a production service shouldn't
|
|
3777
4085
|
// serialize process.env or process.version to callers.
|
|
3778
|
-
/res\.(?:json|send)\s*\([^)]
|
|
4086
|
+
/res\.(?:json|send)\s*\([^)]{0,500}process\.(?:env|version|pid|arch|platform)/gi,
|
|
3779
4087
|
/(?:env|environment)\s*:\s*process\.env\b/gi
|
|
3780
4088
|
];
|
|
3781
4089
|
for (const p of patterns) {
|
|
@@ -3875,8 +4183,8 @@ var exposedStackTraces = {
|
|
|
3875
4183
|
const matches = [];
|
|
3876
4184
|
const patterns = [
|
|
3877
4185
|
// Sending stack trace in response
|
|
3878
|
-
/(?:res\.(?:json|send|status)|c\.json|return
|
|
3879
|
-
/(?:res\.(?:json|send|status)|c\.json)\s*\([^)]
|
|
4186
|
+
/(?:res\.(?:json|send|status)|c\.json|return.{0,300}json)\s*\([^)]{0,500}(?:err\.stack|error\.stack|e\.stack)/gi,
|
|
4187
|
+
/(?:res\.(?:json|send|status)|c\.json)\s*\([^)]{0,500}(?:err\.message|error\.message|e\.message)/gi,
|
|
3880
4188
|
// Express-style error with stack
|
|
3881
4189
|
/(?:message|error)\s*:\s*(?:err|error|e)\.(?:stack|message)/gi
|
|
3882
4190
|
];
|
|
@@ -3927,11 +4235,11 @@ var weakHashing = {
|
|
|
3927
4235
|
if (/bcrypt|scrypt|argon2/i.test(content)) return [];
|
|
3928
4236
|
const matches = [];
|
|
3929
4237
|
const inlinePatterns = [
|
|
3930
|
-
/(?:md5|sha1|sha256|sha512)\s*\([^)]
|
|
3931
|
-
/createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\)
|
|
3932
|
-
/(?:password|passwd|pwd)
|
|
3933
|
-
/hashlib\.(?:md5|sha1|sha256)\s*\([^)]
|
|
3934
|
-
/Digest::(?:MD5|SHA1|SHA256)
|
|
4238
|
+
/(?:md5|sha1|sha256|sha512)\s*\([^)]{0,500}(?:password|passwd|pwd)/gi,
|
|
4239
|
+
/createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\).{0,500}(?:password|passwd|pwd)/gi,
|
|
4240
|
+
/(?:password|passwd|pwd).{0,500}createHash\s*\(\s*["'`](?:md5|sha1|sha256)["'`]\)/gi,
|
|
4241
|
+
/hashlib\.(?:md5|sha1|sha256)\s*\([^)]{0,500}(?:password|passwd|pwd)/gi,
|
|
4242
|
+
/Digest::(?:MD5|SHA1|SHA256).{0,500}(?:password|passwd|pwd)/gi
|
|
3935
4243
|
];
|
|
3936
4244
|
for (const p of inlinePatterns) {
|
|
3937
4245
|
matches.push(...findMatches(
|
|
@@ -3977,7 +4285,7 @@ var disabledTLSVerification = {
|
|
|
3977
4285
|
const patterns = [
|
|
3978
4286
|
/NODE_TLS_REJECT_UNAUTHORIZED\s*[:=]\s*["'`]?0["'`]?/g,
|
|
3979
4287
|
/rejectUnauthorized\s*:\s*false/g,
|
|
3980
|
-
/verify\s*[:=]\s*false
|
|
4288
|
+
/verify\s*[:=]\s*false.{0,300}(?:ssl|tls|cert|https)/gi,
|
|
3981
4289
|
/PYTHONHTTPSVERIFY\s*[:=]\s*["'`]?0["'`]?/g,
|
|
3982
4290
|
/ssl_verify\s*[:=]\s*false/gi,
|
|
3983
4291
|
/InsecureSkipVerify\s*:\s*true/g
|
|
@@ -4676,12 +4984,13 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4676
4984
|
}
|
|
4677
4985
|
if (maxLineLen > 5e4) return findings;
|
|
4678
4986
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4679
|
-
|
|
4987
|
+
const sbomFile = isSbomPath(filePath);
|
|
4680
4988
|
const vendoredFile = isVendoredPath(filePath);
|
|
4681
4989
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4682
4990
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
4683
4991
|
for (const rule of ruleset) {
|
|
4684
4992
|
if (disabledRules.includes(rule.id)) continue;
|
|
4993
|
+
if (sbomFile && rule.category !== "Secrets") continue;
|
|
4685
4994
|
const matches = rule.check(content, filePath, project);
|
|
4686
4995
|
const compliance = complianceMap[rule.id];
|
|
4687
4996
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
@@ -5094,6 +5403,30 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5094
5403
|
}
|
|
5095
5404
|
|
|
5096
5405
|
// src/entropy-scanner.ts
|
|
5406
|
+
function orderedAlphabetRatio(value) {
|
|
5407
|
+
if (value.length === 0) return 0;
|
|
5408
|
+
let ordered = 0;
|
|
5409
|
+
let run = 1;
|
|
5410
|
+
const cls = (c) => {
|
|
5411
|
+
if (c >= 48 && c <= 57) return 1;
|
|
5412
|
+
if (c >= 65 && c <= 90) return 2;
|
|
5413
|
+
if (c >= 97 && c <= 122) return 3;
|
|
5414
|
+
return 0;
|
|
5415
|
+
};
|
|
5416
|
+
for (let i = 1; i < value.length; i++) {
|
|
5417
|
+
const a = value.charCodeAt(i - 1);
|
|
5418
|
+
const b = value.charCodeAt(i);
|
|
5419
|
+
const ca = cls(a);
|
|
5420
|
+
if (ca !== 0 && ca === cls(b) && b === a + 1) {
|
|
5421
|
+
run++;
|
|
5422
|
+
if (run === 4) ordered += 4;
|
|
5423
|
+
else if (run > 4) ordered++;
|
|
5424
|
+
} else {
|
|
5425
|
+
run = 1;
|
|
5426
|
+
}
|
|
5427
|
+
}
|
|
5428
|
+
return ordered / value.length;
|
|
5429
|
+
}
|
|
5097
5430
|
function shannonEntropy(str) {
|
|
5098
5431
|
const freq = {};
|
|
5099
5432
|
for (const ch of str) {
|
|
@@ -5333,6 +5666,7 @@ function scanEntropy(files) {
|
|
|
5333
5666
|
const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,256})\1/g;
|
|
5334
5667
|
let match;
|
|
5335
5668
|
while ((match = stringPattern.exec(line)) !== null) {
|
|
5669
|
+
if (match[1] === "`" && /(?:^|[\s(]):[a-z][\w-]{0,20}:$/.test(line.slice(Math.max(0, match.index - 23), match.index + 1))) continue;
|
|
5336
5670
|
let beforeAssign = line.substring(0, match.index);
|
|
5337
5671
|
if (structured) beforeAssign = beforeAssign.slice(Math.max(beforeAssign.lastIndexOf(","), beforeAssign.lastIndexOf("{")) + 1);
|
|
5338
5672
|
candidates.push({ value: match[2], beforeAssign });
|
|
@@ -5345,6 +5679,8 @@ function scanEntropy(files) {
|
|
|
5345
5679
|
if (value.includes("${")) continue;
|
|
5346
5680
|
if (value.includes("\\(")) continue;
|
|
5347
5681
|
if (value.includes("#{") || value.includes("{{")) continue;
|
|
5682
|
+
if (/^(?:\$\w{1,64}|\$env\{\w{1,64}\}|%\w{1,64}%|~|\.{1,2})?[\/\\](?:[\w.@ -]{1,64}[\/\\]){1,20}[\w@ -][\w.@ -]{0,63}\.[A-Za-z0-9]{1,8}$/.test(value) && !/[A-Za-z0-9+]{24,}/.test(value)) continue;
|
|
5683
|
+
if (orderedAlphabetRatio(value) >= 0.9) continue;
|
|
5348
5684
|
const isUuidShape = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
5349
5685
|
if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
|
|
5350
5686
|
if (HASH_PREFIX_RE.test(value)) continue;
|
|
@@ -6001,6 +6337,7 @@ function getSnippet5(content, line) {
|
|
|
6001
6337
|
}
|
|
6002
6338
|
function scanMultiFile(files) {
|
|
6003
6339
|
files = files.filter((f) => !isSbomPath(f.path));
|
|
6340
|
+
const guarded = secretGuardedRoutes(files);
|
|
6004
6341
|
const findings = [];
|
|
6005
6342
|
const fileMap = /* @__PURE__ */ new Map();
|
|
6006
6343
|
for (const f of files) {
|
|
@@ -6016,6 +6353,7 @@ function scanMultiFile(files) {
|
|
|
6016
6353
|
if (!/(?:\/api\/|routes?\/|controllers?\/)/i.test(f.path)) continue;
|
|
6017
6354
|
if (/middleware/i.test(f.path)) continue;
|
|
6018
6355
|
if (/(?:health|status|ping|ready|live)\.(?:ts|js)/i.test(f.path)) continue;
|
|
6356
|
+
if (guarded.has(f.path)) continue;
|
|
6019
6357
|
const hasLocalAuth = /(?:requireAuth|isAuthenticated|authenticate|verify|getAuth|getSession|getServerSession|withAuth|jwt\.verify|clerk)/i.test(f.content);
|
|
6020
6358
|
const hasAuthImport = f.content.split("\n").some((line) => {
|
|
6021
6359
|
const at = line.search(/import/i);
|
|
@@ -9877,6 +10215,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9877
10215
|
QUALITY_EXAMPLES,
|
|
9878
10216
|
RULE_IMPACTS,
|
|
9879
10217
|
SCANNER_VERSION,
|
|
10218
|
+
SERVER_ACTION_WRITE_RE,
|
|
9880
10219
|
TEST_FILE_PATTERN,
|
|
9881
10220
|
TOTAL_RULE_COUNT,
|
|
9882
10221
|
allRules,
|