xploitscan-shared-rules 2.4.9 → 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 +201 -40
- 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 +200 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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;
|
|
@@ -2085,11 +2115,14 @@ var hardcodedSecrets = {
|
|
|
2085
2115
|
/\b(?:password|passwd|pwd)\s*:\s*["'`]([a-zA-Z0-9_\-!@#$%^&*.\/:\-]{8,})["'`]/gi,
|
|
2086
2116
|
// Private keys
|
|
2087
2117
|
/-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/g,
|
|
2088
|
-
// Database URLs with credentials.
|
|
2089
|
-
//
|
|
2090
|
-
//
|
|
2091
|
-
//
|
|
2092
|
-
|
|
2118
|
+
// Database URLs with credentials. Align with Pro VC049: `postgresql://`
|
|
2119
|
+
// and `postgresql+asyncpg://` (and mysql/mongodb+srv) are what providers
|
|
2120
|
+
// actually hand out — `postgres://` alone missed Supabase/Prisma URLs.
|
|
2121
|
+
// The user and password cannot cross whitespace or a newline, and each
|
|
2122
|
+
// is capped at 1024 characters, so a localhost URL cannot run forward
|
|
2123
|
+
// to a later `@` and a run of `postgres://a:b` with no `@` cannot
|
|
2124
|
+
// backtrack.
|
|
2125
|
+
/(?:postgres(?:ql)?(?:\+[a-z0-9]{1,20})?|mysql|mongodb(?:\+srv)?):\/\/[^:@\s/]{1,1024}:[^@\s]{1,1024}@[^/\s"'`]{1,256}/gi,
|
|
2093
2126
|
// ── [11]–[14] Fixed-prefix AI-provider and payment keys ──
|
|
2094
2127
|
// These match the token itself, so they fire whatever it is bound to:
|
|
2095
2128
|
// `const k = "…"`, a positional `new OpenAI("…")`, an unquoted .env
|
|
@@ -2204,15 +2237,20 @@ var hardcodedSecrets = {
|
|
|
2204
2237
|
}
|
|
2205
2238
|
if (pi === 6) {
|
|
2206
2239
|
const valMatch = lineText.match(/[:=]\s*["'`]([^"'`]+)["'`]/);
|
|
2207
|
-
const nameMatch =
|
|
2240
|
+
const nameMatch = (matchedText[ri] ?? "").match(/^[A-Z][A-Z0-9_]{0,64}_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD)\b/);
|
|
2208
2241
|
if (valMatch && nameMatch) {
|
|
2209
2242
|
const value = valMatch[1];
|
|
2210
|
-
const isKeySuffix = nameMatch[
|
|
2211
|
-
const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[
|
|
2243
|
+
const isKeySuffix = nameMatch[0].endsWith("_KEY");
|
|
2244
|
+
const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[0], value));
|
|
2212
2245
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
2213
2246
|
}
|
|
2214
2247
|
}
|
|
2215
|
-
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
|
+
}
|
|
2216
2254
|
const matched = matchedText[ri] ?? "";
|
|
2217
2255
|
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
2218
2256
|
}
|
|
@@ -2633,6 +2671,22 @@ function unauthenticatedTanStackHandlers(masked, filePath) {
|
|
|
2633
2671
|
}
|
|
2634
2672
|
return hits;
|
|
2635
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
|
+
];
|
|
2636
2690
|
var missingAuthMiddleware = {
|
|
2637
2691
|
id: "VC003",
|
|
2638
2692
|
title: "API Route Missing Authentication",
|
|
@@ -2658,8 +2712,9 @@ var missingAuthMiddleware = {
|
|
|
2658
2712
|
/module\.exports\s*=\s*(?:async\s+)?(?:function\b|\()/g
|
|
2659
2713
|
);
|
|
2660
2714
|
}
|
|
2715
|
+
const useServerPatterns = [];
|
|
2661
2716
|
if (USE_SERVER_DIRECTIVE_RE.test(content)) {
|
|
2662
|
-
|
|
2717
|
+
useServerPatterns.push(
|
|
2663
2718
|
/export\s+(?:async\s+)?function\s+\w+\s*\(/g,
|
|
2664
2719
|
/export\s+const\s+\w+\s*(?::[^=\n]{0,120})?=\s*(?:async\s*)?\(/g
|
|
2665
2720
|
);
|
|
@@ -2745,24 +2800,33 @@ var missingAuthMiddleware = {
|
|
|
2745
2800
|
);
|
|
2746
2801
|
const maskedForScope = maskOutboundAuthNoise(maskComments(content));
|
|
2747
2802
|
const codeForAuth = maskOutboundAuthNoise(codeOnly);
|
|
2748
|
-
const
|
|
2803
|
+
const scopeCache = /* @__PURE__ */ new Map();
|
|
2804
|
+
const scopeAt = (index) => {
|
|
2805
|
+
const cached = scopeCache.get(index);
|
|
2806
|
+
if (cached !== void 0) return cached;
|
|
2749
2807
|
const bodyStart = maskedForScope.indexOf("{", index);
|
|
2750
2808
|
const probe = bodyStart === -1 ? index : bodyStart + 1;
|
|
2751
2809
|
const scope = enclosingHandler(maskedForScope, probe);
|
|
2810
|
+
scopeCache.set(index, scope);
|
|
2811
|
+
return scope;
|
|
2812
|
+
};
|
|
2813
|
+
const handlerHasAuth = (index) => {
|
|
2814
|
+
const scope = scopeAt(index);
|
|
2752
2815
|
if (scope === null) return handlerAuthPatterns.some((p) => p.test(codeForAuth));
|
|
2753
2816
|
return handlerAuthPatterns.some((p) => p.test(scope));
|
|
2754
2817
|
};
|
|
2755
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.";
|
|
2756
2821
|
for (const pattern of serverSide ? routePatterns : []) {
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
);
|
|
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
|
+
}
|
|
2766
2830
|
}
|
|
2767
2831
|
if (matches.length === 0 && serverSide && SUPABASE_EDGE_FN_RE.test(filePath) && isDenoEdgeEntry(codeOnly) && !isPublicByDesignEdgePath(filePath)) {
|
|
2768
2832
|
const fnName = supabaseFunctionName(filePath);
|
|
@@ -2791,7 +2855,12 @@ var missingAuthMiddleware = {
|
|
|
2791
2855
|
const isPublicRootGet = (index) => /\.\s*get\s*\(\s*["'`]\/["'`]\s*,/i.test(content.slice(index, index + 240));
|
|
2792
2856
|
const unauthenticated = matches.filter((m) => {
|
|
2793
2857
|
const index = indexOfLine(m.line);
|
|
2794
|
-
|
|
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;
|
|
2795
2864
|
});
|
|
2796
2865
|
if (serverSide || tanstackCandidate) {
|
|
2797
2866
|
for (const idx of unauthenticatedTanStackHandlers(maskedForScope, filePath)) {
|
|
@@ -3191,6 +3260,9 @@ var noRateLimiting = {
|
|
|
3191
3260
|
check(content, filePath) {
|
|
3192
3261
|
const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
|
|
3193
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
|
+
}
|
|
3194
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.
|
|
3195
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);
|
|
3196
3268
|
if (!isServer) return [];
|
|
@@ -3530,6 +3602,28 @@ var unvalidatedRedirect = {
|
|
|
3530
3602
|
var CLIENT_PREFERENCE_COOKIE_NAME_RE = /(?:consent|preferences?|prefs?)/i;
|
|
3531
3603
|
var CLIENT_PREFERENCE_COOKIE_VALUE_RE = /(?:choice|consent|preferences?|prefs?|accepted|essential(?:-only)?|declined|rejected|granted|denied|opt(?:ed)?[-_ ]?(?:in|out))/i;
|
|
3532
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
|
+
}
|
|
3533
3627
|
function isClearlyNonSensitivePreferenceCookieWrite(content, line) {
|
|
3534
3628
|
const assignment = /\bdocument\s*\.\s*cookie\s*=\s*(.+)$/i.exec(line);
|
|
3535
3629
|
if (!assignment) return false;
|
|
@@ -3561,7 +3655,7 @@ var insecureCookies = {
|
|
|
3561
3655
|
check(content, filePath) {
|
|
3562
3656
|
if (isTestFile(filePath)) return [];
|
|
3563
3657
|
if (!/cookie/i.test(content)) return [];
|
|
3564
|
-
const setCookiePattern = /(
|
|
3658
|
+
const setCookiePattern = /(?:\bset-cookie|\bsetCookie|\bcookie\s*=|res\.cookie\s*\()/i;
|
|
3565
3659
|
if (!setCookiePattern.test(content)) return [];
|
|
3566
3660
|
const hasHttpOnly = /httpOnly\s*:\s*true|httponly/i.test(content);
|
|
3567
3661
|
const hasSecure = /secure\s*:\s*(?!false\b)\S/i.test(content) || /;\s*secure/i.test(content);
|
|
@@ -3580,12 +3674,18 @@ var insecureCookies = {
|
|
|
3580
3674
|
() => `Add missing cookie flags: ${missing.join(", ")}. Example: { httpOnly: true, secure: true, sameSite: 'lax' }`
|
|
3581
3675
|
);
|
|
3582
3676
|
const lines = content.split("\n");
|
|
3677
|
+
const uiFlagMemo = /* @__PURE__ */ new Map();
|
|
3583
3678
|
for (const match of rawMatches) {
|
|
3584
3679
|
const line = lines[match.line - 1] ?? "";
|
|
3585
3680
|
if (!hasHttpOnly && isClearlyNonSensitivePreferenceCookieWrite(content, line)) {
|
|
3586
3681
|
continue;
|
|
3587
3682
|
}
|
|
3588
|
-
|
|
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);
|
|
3589
3689
|
}
|
|
3590
3690
|
}
|
|
3591
3691
|
return matches;
|
|
@@ -3731,19 +3831,49 @@ var missingHTTPS = {
|
|
|
3731
3831
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3732
3832
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
3733
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;
|
|
3734
|
-
const
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
() => "Use https:// instead of http:// for all production URLs. Add HSTS header: Strict-Transport-Security: max-age=31536000; includeSubDomains"
|
|
3740
|
-
);
|
|
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
|
+
});
|
|
3741
3839
|
const lines = rawMatches.length > 0 ? content.split("\n") : [];
|
|
3742
|
-
|
|
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];
|
|
3743
3860
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3744
3861
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3745
|
-
if (
|
|
3746
|
-
|
|
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;
|
|
3747
3877
|
matches.push(rm);
|
|
3748
3878
|
}
|
|
3749
3879
|
return matches;
|
|
@@ -4673,12 +4803,13 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4673
4803
|
}
|
|
4674
4804
|
if (maxLineLen > 5e4) return findings;
|
|
4675
4805
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4676
|
-
|
|
4806
|
+
const sbomFile = isSbomPath(filePath);
|
|
4677
4807
|
const vendoredFile = isVendoredPath(filePath);
|
|
4678
4808
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4679
4809
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
4680
4810
|
for (const rule of ruleset) {
|
|
4681
4811
|
if (disabledRules.includes(rule.id)) continue;
|
|
4812
|
+
if (sbomFile && rule.category !== "Secrets") continue;
|
|
4682
4813
|
const matches = rule.check(content, filePath, project);
|
|
4683
4814
|
const compliance = complianceMap[rule.id];
|
|
4684
4815
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
@@ -5091,6 +5222,30 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
|
|
|
5091
5222
|
}
|
|
5092
5223
|
|
|
5093
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
|
+
}
|
|
5094
5249
|
function shannonEntropy(str) {
|
|
5095
5250
|
const freq = {};
|
|
5096
5251
|
for (const ch of str) {
|
|
@@ -5330,6 +5485,7 @@ function scanEntropy(files) {
|
|
|
5330
5485
|
const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,256})\1/g;
|
|
5331
5486
|
let match;
|
|
5332
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;
|
|
5333
5489
|
let beforeAssign = line.substring(0, match.index);
|
|
5334
5490
|
if (structured) beforeAssign = beforeAssign.slice(Math.max(beforeAssign.lastIndexOf(","), beforeAssign.lastIndexOf("{")) + 1);
|
|
5335
5491
|
candidates.push({ value: match[2], beforeAssign });
|
|
@@ -5342,7 +5498,10 @@ function scanEntropy(files) {
|
|
|
5342
5498
|
if (value.includes("${")) continue;
|
|
5343
5499
|
if (value.includes("\\(")) continue;
|
|
5344
5500
|
if (value.includes("#{") || value.includes("{{")) continue;
|
|
5345
|
-
if (
|
|
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;
|
|
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);
|
|
5504
|
+
if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
|
|
5346
5505
|
if (HASH_PREFIX_RE.test(value)) continue;
|
|
5347
5506
|
if (SAFE_VAR_NAMES.test(beforeAssign)) continue;
|
|
5348
5507
|
if (/^https?:\/\/[^:@]*$/.test(value)) continue;
|
|
@@ -5353,9 +5512,10 @@ function scanEntropy(files) {
|
|
|
5353
5512
|
if (isHex) threshold = 3;
|
|
5354
5513
|
else if (isBase64) threshold = 4.5;
|
|
5355
5514
|
if (value.length < 20) continue;
|
|
5356
|
-
const entropy = shannonEntropy(value);
|
|
5357
|
-
if (entropy < threshold) continue;
|
|
5358
5515
|
const varName = variableName || dotenvName || beforeAssign.match(/["']([^"']+)["']\s*$/)?.[1] || beforeAssign.match(/([\w$-]+)\s*$/)?.[1] || "";
|
|
5516
|
+
if (isUuidShape && !isSecretVariableName(varName)) continue;
|
|
5517
|
+
const entropy = shannonEntropy(value);
|
|
5518
|
+
if (entropy < threshold && !(isUuidShape && isSecretVariableName(varName))) continue;
|
|
5359
5519
|
if (HUMAN_READABLE_ENV_REFERENCE_RE.test(value) && !isSecretVariableName(varName)) {
|
|
5360
5520
|
continue;
|
|
5361
5521
|
}
|
|
@@ -9872,6 +10032,7 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9872
10032
|
QUALITY_EXAMPLES,
|
|
9873
10033
|
RULE_IMPACTS,
|
|
9874
10034
|
SCANNER_VERSION,
|
|
10035
|
+
SERVER_ACTION_WRITE_RE,
|
|
9875
10036
|
TEST_FILE_PATTERN,
|
|
9876
10037
|
TOTAL_RULE_COUNT,
|
|
9877
10038
|
allRules,
|