xploitscan-shared-rules 2.4.10 → 2.4.11
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 +185 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +184 -29
- 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.11";
|
|
163
164
|
|
|
164
165
|
// src/snippet.ts
|
|
165
166
|
var cacheContent = null;
|
|
@@ -674,7 +675,7 @@ function isTestPath(filePath) {
|
|
|
674
675
|
if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
|
|
675
676
|
return false;
|
|
676
677
|
}
|
|
677
|
-
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
678
|
+
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.(?:json|xml)|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
678
679
|
function isSbomPath(filePath) {
|
|
679
680
|
return SBOM_FILE_RE.test(normalize(filePath));
|
|
680
681
|
}
|
|
@@ -2012,13 +2013,40 @@ function dbUrlLacksRealCredential(url) {
|
|
|
2012
2013
|
const userinfo = rest.slice(0, at);
|
|
2013
2014
|
const colon = userinfo.indexOf(":");
|
|
2014
2015
|
const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
|
|
2015
|
-
const
|
|
2016
|
+
const rawPass = colon < 0 ? "" : userinfo.slice(colon + 1);
|
|
2017
|
+
const pass = colon < 0 ? "" : decodeURIComponentSafe(rawPass);
|
|
2016
2018
|
if (!pass) return true;
|
|
2019
|
+
const portShaped = /^(\d{1,5})(?:\/[\w.-]{0,64})?[?#"'`][^@]*$/.exec(rawPass);
|
|
2020
|
+
if (portShaped && Number(portShaped[1]) <= 65535) return true;
|
|
2017
2021
|
if (isFormatPlaceholder(pass)) return true;
|
|
2018
2022
|
if (isPlaceholderSecret(pass)) return true;
|
|
2019
2023
|
if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
|
|
2020
2024
|
return false;
|
|
2021
2025
|
}
|
|
2026
|
+
var LOOPBACK_DEV_USER_RE = /^(?:postgres|root|admin|user|test|dev|mysql|mongo|mongodb|redis|sa|guest|app|example)$/i;
|
|
2027
|
+
function isLoopbackDevDefault(url) {
|
|
2028
|
+
const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
|
|
2029
|
+
const at = rest.lastIndexOf("@");
|
|
2030
|
+
if (at < 0) return false;
|
|
2031
|
+
const userinfo = rest.slice(0, at);
|
|
2032
|
+
const colon = userinfo.indexOf(":");
|
|
2033
|
+
if (colon < 0) return false;
|
|
2034
|
+
const user = userinfo.slice(0, colon);
|
|
2035
|
+
const pass = decodeURIComponentSafe(userinfo.slice(colon + 1));
|
|
2036
|
+
if (user !== pass || !LOOPBACK_DEV_USER_RE.test(user)) return false;
|
|
2037
|
+
let host = rest.slice(at + 1);
|
|
2038
|
+
const cut = host.search(/[/?#]/);
|
|
2039
|
+
if (cut >= 0) host = host.slice(0, cut);
|
|
2040
|
+
if (host.startsWith("[")) {
|
|
2041
|
+
const end = host.indexOf("]");
|
|
2042
|
+
host = end >= 0 ? host.slice(1, end) : host;
|
|
2043
|
+
} else {
|
|
2044
|
+
const port = host.lastIndexOf(":");
|
|
2045
|
+
if (port >= 0) host = host.slice(0, port);
|
|
2046
|
+
}
|
|
2047
|
+
const h = host.toLowerCase();
|
|
2048
|
+
return h === "localhost" || h === "::1" || h === "0.0.0.0" || h === "host.docker.internal" || /^127(?:\.\d{1,3}){0,3}$/.test(h);
|
|
2049
|
+
}
|
|
2022
2050
|
function decodeURIComponentSafe(value) {
|
|
2023
2051
|
try {
|
|
2024
2052
|
return decodeURIComponent(value);
|
|
@@ -2027,10 +2055,12 @@ function decodeURIComponentSafe(value) {
|
|
|
2027
2055
|
}
|
|
2028
2056
|
}
|
|
2029
2057
|
var FORMAT_PLACEHOLDER_MAX = 256;
|
|
2058
|
+
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
2059
|
function isFormatPlaceholder(value) {
|
|
2031
2060
|
const v = value.trim();
|
|
2032
2061
|
if (!v) return true;
|
|
2033
2062
|
if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
|
|
2063
|
+
if (FORMAT_FIELD_RE.test(v)) return true;
|
|
2034
2064
|
if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
|
|
2035
2065
|
if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
|
|
2036
2066
|
return false;
|
|
@@ -2215,7 +2245,12 @@ var hardcodedSecrets = {
|
|
|
2215
2245
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
2216
2246
|
}
|
|
2217
2247
|
}
|
|
2218
|
-
if (pi === 10
|
|
2248
|
+
if (pi === 10) {
|
|
2249
|
+
const url = matchedText[ri] ?? "";
|
|
2250
|
+
if (dbUrlLacksRealCredential(url)) continue;
|
|
2251
|
+
matches.push(isLoopbackDevDefault(url) ? { ...rm, severity: "low" } : textHasLiveCredential(url) ? { ...rm, live: true } : rm);
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2219
2254
|
const matched = matchedText[ri] ?? "";
|
|
2220
2255
|
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
2221
2256
|
}
|
|
@@ -2636,6 +2671,22 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
|
|
|
2636
2671
|
}
|
|
2637
2672
|
return hits;
|
|
2638
2673
|
}
|
|
2674
|
+
var SERVER_ACTION_WRITE_RE = [
|
|
2675
|
+
/\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*\(/,
|
|
2676
|
+
/\b(?:stripe|paypal|braintree|lemonsqueezy|paddle)\s*\.\s*\w{1,40}\s*\.\s*(?:create|update|del|cancel|capture|refund)\w{0,10}\s*\(/,
|
|
2677
|
+
/\bfetch\s*\([^;]{0,400}?\bmethod\s*(?::\s*(?=["'`](?:POST|PUT|PATCH|DELETE)\b|`\$\{|[A-Za-z_$(\[])|(?=[,}]))/i,
|
|
2678
|
+
/\b(?:fs(?:\.promises)?\s*\.\s*)?(?:writeFile|appendFile|unlink|rm|rmdir|rename|copyFile)(?:Sync)?\s*\(/,
|
|
2679
|
+
/\.\s*(?:del|deleteOne|deleteMany|insertOne|insertMany|updateOne|updateMany|replaceOne|bulkWrite|upsert|increment|decrement|destroy|truncate)\s*\(/,
|
|
2680
|
+
/cookies\(\)\)?\s*\.\s*set\(\s*["'`][\w-]*(?:session|token|auth|jwt|sid|role|user|admin)/i,
|
|
2681
|
+
...TANSTACK_MUTATION_RE,
|
|
2682
|
+
/\b(?:prisma|db|tx)\s*\.\s*\w{1,64}\s*\.\s*(?:create|createMany|insert\w{0,10})\s*\(/,
|
|
2683
|
+
/\b(?:db|tx)\s*\.\s*insert\s*\(\s*\w/,
|
|
2684
|
+
/\.from\(\s*["'`][\w.-]{1,64}["'`]\s*\)\s*\.\s*insert\s*\(/,
|
|
2685
|
+
/\bINSERT\s+INTO\b/i,
|
|
2686
|
+
/\.collection\(\s*["'`][\w.-]{1,64}["'`]\s*\)\s*\.\s*(?:insert\w{0,8}|update\w{0,8}|delete\w{0,8}|replaceOne|findOneAndUpdate|findOneAndDelete)\s*\(/,
|
|
2687
|
+
/\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*\(/,
|
|
2688
|
+
/\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*\(/
|
|
2689
|
+
];
|
|
2639
2690
|
var missingAuthMiddleware = {
|
|
2640
2691
|
id: "VC003",
|
|
2641
2692
|
title: "API Route Missing Authentication",
|
|
@@ -2661,8 +2712,9 @@ var missingAuthMiddleware = {
|
|
|
2661
2712
|
/module\.exports\s*=\s*(?:async\s+)?(?:function\b|\()/g
|
|
2662
2713
|
);
|
|
2663
2714
|
}
|
|
2715
|
+
const useServerPatterns = [];
|
|
2664
2716
|
if (USE_SERVER_DIRECTIVE_RE.test(content)) {
|
|
2665
|
-
|
|
2717
|
+
useServerPatterns.push(
|
|
2666
2718
|
/export\s+(?:async\s+)?function\s+\w+\s*\(/g,
|
|
2667
2719
|
/export\s+const\s+\w+\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?\(/g
|
|
2668
2720
|
);
|
|
@@ -2748,24 +2800,33 @@ var missingAuthMiddleware = {
|
|
|
2748
2800
|
);
|
|
2749
2801
|
const maskedForScope = maskOutboundAuthNoise(maskComments(content));
|
|
2750
2802
|
const codeForAuth = maskOutboundAuthNoise(codeOnly);
|
|
2751
|
-
const
|
|
2803
|
+
const scopeCache = /* @__PURE__ */ new Map();
|
|
2804
|
+
const scopeAt = (index) => {
|
|
2805
|
+
const cached = scopeCache.get(index);
|
|
2806
|
+
if (cached !== void 0) return cached;
|
|
2752
2807
|
const bodyStart = maskedForScope.indexOf("{", index);
|
|
2753
2808
|
const probe = bodyStart === -1 ? index : bodyStart + 1;
|
|
2754
2809
|
const scope = enclosingHandler(maskedForScope, probe);
|
|
2810
|
+
scopeCache.set(index, scope);
|
|
2811
|
+
return scope;
|
|
2812
|
+
};
|
|
2813
|
+
const handlerHasAuth = (index) => {
|
|
2814
|
+
const scope = scopeAt(index);
|
|
2755
2815
|
if (scope === null) return handlerAuthPatterns.some((p) => p.test(codeForAuth));
|
|
2756
2816
|
return handlerAuthPatterns.some((p) => p.test(scope));
|
|
2757
2817
|
};
|
|
2758
2818
|
const matches = [];
|
|
2819
|
+
const routeLines = /* @__PURE__ */ new Set();
|
|
2820
|
+
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
2821
|
for (const pattern of serverSide ? routePatterns : []) {
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
);
|
|
2822
|
+
const found = findMatches(content, pattern, missingAuthMiddleware, filePath, () => authFix);
|
|
2823
|
+
for (const foundMatch of found) routeLines.add(foundMatch.line);
|
|
2824
|
+
matches.push(...found);
|
|
2825
|
+
}
|
|
2826
|
+
if (serverSide) {
|
|
2827
|
+
for (const pattern of useServerPatterns) {
|
|
2828
|
+
matches.push(...findMatches(content, pattern, missingAuthMiddleware, filePath, () => authFix));
|
|
2829
|
+
}
|
|
2769
2830
|
}
|
|
2770
2831
|
if (matches.length === 0 && serverSide && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
|
|
2771
2832
|
const fnName = supabaseFunctionName(filePath);
|
|
@@ -2794,7 +2855,12 @@ var missingAuthMiddleware = {
|
|
|
2794
2855
|
const isPublicRootGet = (index) => /\.\s*get\s*\(\s*["'`]\/["'`]\s*,/i.test(content.slice(index, index + 240));
|
|
2795
2856
|
const unauthenticated = matches.filter((m) => {
|
|
2796
2857
|
const index = indexOfLine(m.line);
|
|
2797
|
-
|
|
2858
|
+
if (isPublicRootGet(index) || handlerHasAuth(index)) return false;
|
|
2859
|
+
if (useServerPatterns.length > 0 && !routeLines.has(m.line)) {
|
|
2860
|
+
const scope = scopeAt(index);
|
|
2861
|
+
if (scope !== null && !SERVER_ACTION_WRITE_RE.some((re) => re.test(scope))) return false;
|
|
2862
|
+
}
|
|
2863
|
+
return true;
|
|
2798
2864
|
});
|
|
2799
2865
|
if (serverSide || tanstackCandidate) {
|
|
2800
2866
|
for (const idx of unauthenticatedTanStackHandlers(maskedForScope, filePath)) {
|
|
@@ -3194,6 +3260,9 @@ var noRateLimiting = {
|
|
|
3194
3260
|
check(content, filePath) {
|
|
3195
3261
|
const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
|
|
3196
3262
|
if (!isEntryFile) return [];
|
|
3263
|
+
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)) {
|
|
3264
|
+
return [];
|
|
3265
|
+
}
|
|
3197
3266
|
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
3267
|
/\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
3268
|
if (!isServer) return [];
|
|
@@ -3533,6 +3602,28 @@ var unvalidatedRedirect = {
|
|
|
3533
3602
|
var CLIENT_PREFERENCE_COOKIE_NAME_RE = /(?:consent|preferences?|prefs?)/i;
|
|
3534
3603
|
var CLIENT_PREFERENCE_COOKIE_VALUE_RE = /(?:choice|consent|preferences?|prefs?|accepted|essential(?:-only)?|declined|rejected|granted|denied|opt(?:ed)?[-_ ]?(?:in|out))/i;
|
|
3535
3604
|
var SENSITIVE_CLIENT_COOKIE_RE = /(?:auth|session|token|jwt|bearer|credential|password|passwd|secret|csrf|xsrf|refresh)/i;
|
|
3605
|
+
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;
|
|
3606
|
+
var UI_FLAG_COOKIE_ASSIGN_RE = /\b(?:document\s*\.\s*)?cookie\s*=\s*(["'`])([^"'`]*)\1/gi;
|
|
3607
|
+
var UI_FLAG_SENSITIVE_NAME_RE = /(?:sess|sid(?!ebar)|login|user|uid|key|account|admin|role|remember|__host-|__secure-)/i;
|
|
3608
|
+
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;
|
|
3609
|
+
function isConstantUiFlagCookieWrite(line, nextLine) {
|
|
3610
|
+
const next = nextLine.trimStart();
|
|
3611
|
+
if (next.startsWith("+") || next.startsWith(".") || next.startsWith("`")) return false;
|
|
3612
|
+
if (/\bset-cookie\b|\bsetCookie\b|res\.cookie\s*\(/i.test(line)) return false;
|
|
3613
|
+
const re = new RegExp(UI_FLAG_COOKIE_ASSIGN_RE.source, "gi");
|
|
3614
|
+
let saw = false;
|
|
3615
|
+
let assignment;
|
|
3616
|
+
while ((assignment = re.exec(line)) !== null) {
|
|
3617
|
+
saw = true;
|
|
3618
|
+
const body = assignment[2];
|
|
3619
|
+
if (!UI_FLAG_COOKIE_BODY_RE.test(body)) return false;
|
|
3620
|
+
if (SENSITIVE_CLIENT_COOKIE_RE.test(body)) return false;
|
|
3621
|
+
const name = body.split("=")[0];
|
|
3622
|
+
if (!UI_FLAG_COOKIE_NAME_RE.test(name)) return false;
|
|
3623
|
+
if (UI_FLAG_SENSITIVE_NAME_RE.test(name)) return false;
|
|
3624
|
+
}
|
|
3625
|
+
return saw;
|
|
3626
|
+
}
|
|
3536
3627
|
function isClearlyNonSensitivePreferenceCookieWrite(content, line) {
|
|
3537
3628
|
const assignment = /\bdocument\s*\.\s*cookie\s*=\s*(.+)$/i.exec(line);
|
|
3538
3629
|
if (!assignment) return false;
|
|
@@ -3564,7 +3655,7 @@ var insecureCookies = {
|
|
|
3564
3655
|
check(content, filePath) {
|
|
3565
3656
|
if (isTestFile(filePath)) return [];
|
|
3566
3657
|
if (!/cookie/i.test(content)) return [];
|
|
3567
|
-
const setCookiePattern = /(
|
|
3658
|
+
const setCookiePattern = /(?:\bset-cookie|\bsetCookie|\bcookie\s*=|res\.cookie\s*\()/i;
|
|
3568
3659
|
if (!setCookiePattern.test(content)) return [];
|
|
3569
3660
|
const hasHttpOnly = /httpOnly\s*:\s*true|httponly/i.test(content);
|
|
3570
3661
|
const hasSecure = /secure\s*:\s*(?!false\b)\S/i.test(content) || /;\s*secure/i.test(content);
|
|
@@ -3583,12 +3674,18 @@ var insecureCookies = {
|
|
|
3583
3674
|
() => `Add missing cookie flags: ${missing.join(", ")}. Example: { httpOnly: true, secure: true, sameSite: 'lax' }`
|
|
3584
3675
|
);
|
|
3585
3676
|
const lines = content.split("\n");
|
|
3677
|
+
const uiFlagMemo = /* @__PURE__ */ new Map();
|
|
3586
3678
|
for (const match of rawMatches) {
|
|
3587
3679
|
const line = lines[match.line - 1] ?? "";
|
|
3588
3680
|
if (!hasHttpOnly && isClearlyNonSensitivePreferenceCookieWrite(content, line)) {
|
|
3589
3681
|
continue;
|
|
3590
3682
|
}
|
|
3591
|
-
|
|
3683
|
+
let info = uiFlagMemo.get(match.line);
|
|
3684
|
+
if (info === void 0) {
|
|
3685
|
+
info = isConstantUiFlagCookieWrite(line, lines[match.line] ?? "");
|
|
3686
|
+
uiFlagMemo.set(match.line, info);
|
|
3687
|
+
}
|
|
3688
|
+
matches.push(info ? { ...match, severity: "info" } : match);
|
|
3592
3689
|
}
|
|
3593
3690
|
}
|
|
3594
3691
|
return matches;
|
|
@@ -3734,19 +3831,49 @@ var missingHTTPS = {
|
|
|
3734
3831
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3735
3832
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
3736
3833
|
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
|
-
);
|
|
3834
|
+
const httpIndexes = [];
|
|
3835
|
+
const rawMatches = findMatches(content, httpPattern, missingHTTPS, filePath, (m) => {
|
|
3836
|
+
httpIndexes.push(m.index);
|
|
3837
|
+
return "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains";
|
|
3838
|
+
});
|
|
3744
3839
|
const lines = rawMatches.length > 0 ? content.split("\n") : [];
|
|
3745
|
-
|
|
3840
|
+
const lineStarts = [];
|
|
3841
|
+
if (rawMatches.length > 0) {
|
|
3842
|
+
let acc = 0;
|
|
3843
|
+
for (const line of lines) {
|
|
3844
|
+
lineStarts.push(acc);
|
|
3845
|
+
acc += line.length + 1;
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
const schemaKeyOnLine = /* @__PURE__ */ new Map();
|
|
3849
|
+
const tsaOnLine = /* @__PURE__ */ new Map();
|
|
3850
|
+
const firstSchemaKey = (line, lineNo) => {
|
|
3851
|
+
const cached = schemaKeyOnLine.get(lineNo);
|
|
3852
|
+
if (cached !== void 0) return cached;
|
|
3853
|
+
const key = /(?<![\w$])["']?\$(?:schema|id|ref)["']?\s*:/.exec(line);
|
|
3854
|
+
const at = key ? key.index : -1;
|
|
3855
|
+
schemaKeyOnLine.set(lineNo, at);
|
|
3856
|
+
return at;
|
|
3857
|
+
};
|
|
3858
|
+
for (let i = 0; i < rawMatches.length; i++) {
|
|
3859
|
+
const rm = rawMatches[i];
|
|
3746
3860
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3747
3861
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3748
|
-
if (
|
|
3749
|
-
|
|
3862
|
+
if (firstSchemaKey(matchText, rm.line) >= 0) {
|
|
3863
|
+
const col = httpIndexes[i] - (lineStarts[rm.line - 1] ?? 0);
|
|
3864
|
+
const lookback = matchText.slice(Math.max(0, col - 48), col);
|
|
3865
|
+
if (/(?<![\w$])["']?\$(?:schema|id)["']?\s*:\s*["']?\s*$/.test(lookback)) continue;
|
|
3866
|
+
if (/(?<![\w$])["']?\$ref["']?\s*:\s*["']?\s*$/.test(lookback)) {
|
|
3867
|
+
const host = (/https?:\/\/([^/"'\s:?#]+)/i.exec(matchText.slice(col, col + 300))?.[1] ?? "").toLowerCase();
|
|
3868
|
+
if (host === "json-schema.org" || host.endsWith(".json-schema.org")) continue;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
let tsa = tsaOnLine.get(rm.line);
|
|
3872
|
+
if (tsa === void 0) {
|
|
3873
|
+
tsa = /--\s*tsaurl\b|\btsaurl\b|timestamp\.(?:digicert|sectigo|comodoca|globalsign|entrust|geotrust|verisign|apple)\.|timestamp\.acs\.microsoft\.com|freetsa\.org/i.test(matchText);
|
|
3874
|
+
tsaOnLine.set(rm.line, tsa);
|
|
3875
|
+
}
|
|
3876
|
+
if (tsa) continue;
|
|
3750
3877
|
matches.push(rm);
|
|
3751
3878
|
}
|
|
3752
3879
|
return matches;
|
|
@@ -4676,12 +4803,13 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4676
4803
|
}
|
|
4677
4804
|
if (maxLineLen > 5e4) return findings;
|
|
4678
4805
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4679
|
-
|
|
4806
|
+
const sbomFile = isSbomPath(filePath);
|
|
4680
4807
|
const vendoredFile = isVendoredPath(filePath);
|
|
4681
4808
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4682
4809
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
4683
4810
|
for (const rule of ruleset) {
|
|
4684
4811
|
if (disabledRules.includes(rule.id)) continue;
|
|
4812
|
+
if (sbomFile && rule.category !== "Secrets") continue;
|
|
4685
4813
|
const matches = rule.check(content, filePath, project);
|
|
4686
4814
|
const compliance = complianceMap[rule.id];
|
|
4687
4815
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
@@ -5094,6 +5222,30 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5094
5222
|
}
|
|
5095
5223
|
|
|
5096
5224
|
// src/entropy-scanner.ts
|
|
5225
|
+
function orderedAlphabetRatio(value) {
|
|
5226
|
+
if (value.length === 0) return 0;
|
|
5227
|
+
let ordered = 0;
|
|
5228
|
+
let run = 1;
|
|
5229
|
+
const cls = (c) => {
|
|
5230
|
+
if (c >= 48 && c <= 57) return 1;
|
|
5231
|
+
if (c >= 65 && c <= 90) return 2;
|
|
5232
|
+
if (c >= 97 && c <= 122) return 3;
|
|
5233
|
+
return 0;
|
|
5234
|
+
};
|
|
5235
|
+
for (let i = 1; i < value.length; i++) {
|
|
5236
|
+
const a = value.charCodeAt(i - 1);
|
|
5237
|
+
const b = value.charCodeAt(i);
|
|
5238
|
+
const ca = cls(a);
|
|
5239
|
+
if (ca !== 0 && ca === cls(b) && b === a + 1) {
|
|
5240
|
+
run++;
|
|
5241
|
+
if (run === 4) ordered += 4;
|
|
5242
|
+
else if (run > 4) ordered++;
|
|
5243
|
+
} else {
|
|
5244
|
+
run = 1;
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
return ordered / value.length;
|
|
5248
|
+
}
|
|
5097
5249
|
function shannonEntropy(str) {
|
|
5098
5250
|
const freq = {};
|
|
5099
5251
|
for (const ch of str) {
|
|
@@ -5333,6 +5485,7 @@ function scanEntropy(files) {
|
|
|
5333
5485
|
const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,256})\1/g;
|
|
5334
5486
|
let match;
|
|
5335
5487
|
while ((match = stringPattern.exec(line)) !== null) {
|
|
5488
|
+
if (match[1] === "`" && /(?:^|[\s(]):[a-z][\w-]{0,20}:$/.test(line.slice(Math.max(0, match.index - 23), match.index + 1))) continue;
|
|
5336
5489
|
let beforeAssign = line.substring(0, match.index);
|
|
5337
5490
|
if (structured) beforeAssign = beforeAssign.slice(Math.max(beforeAssign.lastIndexOf(","), beforeAssign.lastIndexOf("{")) + 1);
|
|
5338
5491
|
candidates.push({ value: match[2], beforeAssign });
|
|
@@ -5345,6 +5498,8 @@ function scanEntropy(files) {
|
|
|
5345
5498
|
if (value.includes("${")) continue;
|
|
5346
5499
|
if (value.includes("\\(")) continue;
|
|
5347
5500
|
if (value.includes("#{") || value.includes("{{")) continue;
|
|
5501
|
+
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;
|
|
5502
|
+
if (orderedAlphabetRatio(value) >= 0.9) continue;
|
|
5348
5503
|
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
5504
|
if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
|
|
5350
5505
|
if (HASH_PREFIX_RE.test(value)) continue;
|
|
@@ -9877,6 +10032,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9877
10032
|
QUALITY_EXAMPLES,
|
|
9878
10033
|
RULE_IMPACTS,
|
|
9879
10034
|
SCANNER_VERSION,
|
|
10035
|
+
SERVER_ACTION_WRITE_RE,
|
|
9880
10036
|
TEST_FILE_PATTERN,
|
|
9881
10037
|
TOTAL_RULE_COUNT,
|
|
9882
10038
|
allRules,
|