xploitscan-shared-rules 1.18.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +278 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -14
- package/dist/index.d.ts +102 -14
- package/dist/index.js +274 -12
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
PRO_RULE_COUNT: () => PRO_RULE_COUNT,
|
|
36
36
|
RULE_IMPACTS: () => RULE_IMPACTS,
|
|
37
37
|
TOTAL_RULE_COUNT: () => TOTAL_RULE_COUNT,
|
|
38
|
+
accountStateFromWebStorage: () => accountStateFromWebStorage,
|
|
38
39
|
allCustomRules: () => allCustomRules,
|
|
39
40
|
allRules: () => allRules,
|
|
40
41
|
androidDebuggable: () => androidDebuggable,
|
|
@@ -72,6 +73,7 @@ __export(index_exports, {
|
|
|
72
73
|
ecbModeEncryption: () => ecbModeEncryption,
|
|
73
74
|
electronNavigationUnrestricted: () => electronNavigationUnrestricted,
|
|
74
75
|
emptyCatchBlock: () => emptyCatchBlock,
|
|
76
|
+
entitlementFromWebStorage: () => entitlementFromWebStorage,
|
|
75
77
|
envNotGitignored: () => envNotGitignored,
|
|
76
78
|
evalUsage: () => evalUsage,
|
|
77
79
|
eventListenerLeak: () => eventListenerLeak,
|
|
@@ -86,6 +88,7 @@ __export(index_exports, {
|
|
|
86
88
|
exposedServerActions: () => exposedServerActions,
|
|
87
89
|
exposedSourceMaps: () => exposedSourceMaps,
|
|
88
90
|
exposedStackTraces: () => exposedStackTraces,
|
|
91
|
+
extractRoutes: () => extractRoutes,
|
|
89
92
|
extractScriptUrls: () => extractScriptUrls,
|
|
90
93
|
filterFalsePositives: () => filterFalsePositives,
|
|
91
94
|
findSourceMapRefs: () => findSourceMapRefs,
|
|
@@ -229,6 +232,7 @@ __export(index_exports, {
|
|
|
229
232
|
rdsPubliclyAccessible: () => rdsPubliclyAccessible,
|
|
230
233
|
reflectedCORSOrigin: () => reflectedCORSOrigin,
|
|
231
234
|
regexDos: () => regexDos,
|
|
235
|
+
routeForFile: () => routeForFile,
|
|
232
236
|
runCustomRules: () => runCustomRules,
|
|
233
237
|
s3BucketNoEncryption: () => s3BucketNoEncryption,
|
|
234
238
|
scanEntropy: () => scanEntropy,
|
|
@@ -541,7 +545,9 @@ var RULE_IMPACTS = {
|
|
|
541
545
|
VC209: "Webhooks are delivered at-least-once. Without de-duplicating on the event id, a retried or replayed delivery re-runs the side effect \u2014 a customer is charged twice, a record is duplicated, or an entitlement is granted again. Stripe and Svix both retry on any non-2xx, so this fires in normal operation, not just under attack.",
|
|
542
546
|
VC210: "If your auth middleware skips /api, those routes run with no gate unless each one re-checks auth itself. It is the most common way a Next.js app ends up with publicly callable API routes that everyone assumed the middleware was protecting.",
|
|
543
547
|
VC211: "A real credit card number in source is cardholder data sitting in git history, CI logs, and every backup \u2014 a direct PCI-DSS violation. Anyone with repo access can read it, and it cannot be un-leaked once committed; the card must be treated as compromised.",
|
|
544
|
-
VC212: "A hardcoded Social Security Number is regulated PII permanently embedded in your git history and backups. It exposes a real person to identity theft, and its presence in source can trigger breach-notification and privacy-law obligations the moment the repo is accessed."
|
|
548
|
+
VC212: "A hardcoded Social Security Number is regulated PII permanently embedded in your git history and backups. It exposes a real person to identity theft, and its presence in source can trigger breach-notification and privacy-law obligations the moment the repo is accessed.",
|
|
549
|
+
VC213: "Anything read from localStorage belongs to the user, not to you. If a plan, role or permission is read from browser storage and branched on, unlocking the feature takes one line in devtools \u2014 no exploit, no tooling, just typing. Every paid tier and admin panel gated this way is open to anyone who opens the console.",
|
|
550
|
+
VC214: "Browser storage is per-device and per-profile, so per-account state kept there resets on a fresh login, cleared cookies, a private window or a second machine \u2014 and the app greets a long-standing customer as brand new. It is not a security hole, it is a trust one: the product visibly does not remember who you are."
|
|
545
551
|
};
|
|
546
552
|
|
|
547
553
|
// src/exposure.ts
|
|
@@ -1221,6 +1227,69 @@ var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.
|
|
|
1221
1227
|
function isTestFile(filePath) {
|
|
1222
1228
|
return TEST_FILE_PATTERN.test(filePath);
|
|
1223
1229
|
}
|
|
1230
|
+
var HANDLER_HEADER_RE = /(?:\b(?:async\s+)?function\b|=>\s*$|=>\s*\{?\s*$|\.(?:get|post|put|patch|delete|use|all)\s*\(|\bexport\s+(?:async\s+)?(?:function|const)\s+(?:GET|POST|PUT|PATCH|DELETE)\b|\b(?:Deno\.)?serve\s*\()/i;
|
|
1231
|
+
function maskComments(content) {
|
|
1232
|
+
return content.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, " ")).replace(/(^|[^:])\/\/[^\n]*/gm, (m, p1) => p1 + " ".repeat(m.length - p1.length));
|
|
1233
|
+
}
|
|
1234
|
+
function queryScope(content, index) {
|
|
1235
|
+
const open = content.indexOf("(", index);
|
|
1236
|
+
if (open === -1 || open - index > 80) return null;
|
|
1237
|
+
let depth = 0;
|
|
1238
|
+
for (let i = open; i < content.length; i++) {
|
|
1239
|
+
const c = content[i];
|
|
1240
|
+
if (c === "(") depth++;
|
|
1241
|
+
else if (c === ")") {
|
|
1242
|
+
depth--;
|
|
1243
|
+
if (depth === 0) return content.slice(open, i + 1);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return null;
|
|
1247
|
+
}
|
|
1248
|
+
function enclosingHandler(content, index) {
|
|
1249
|
+
const MAX_LEVELS = 6;
|
|
1250
|
+
let searchFrom = index;
|
|
1251
|
+
for (let level = 0; level < MAX_LEVELS; level++) {
|
|
1252
|
+
let depth = 0;
|
|
1253
|
+
let open = -1;
|
|
1254
|
+
for (let i = searchFrom; i >= 0; i--) {
|
|
1255
|
+
const c = content[i];
|
|
1256
|
+
if (c === "}") depth++;
|
|
1257
|
+
else if (c === "{") {
|
|
1258
|
+
if (depth === 0) {
|
|
1259
|
+
open = i;
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
depth--;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
if (open === -1) return null;
|
|
1266
|
+
let fwd = 0;
|
|
1267
|
+
let close = -1;
|
|
1268
|
+
for (let i = open; i < content.length; i++) {
|
|
1269
|
+
const c = content[i];
|
|
1270
|
+
if (c === "{") fwd++;
|
|
1271
|
+
else if (c === "}") {
|
|
1272
|
+
fwd--;
|
|
1273
|
+
if (fwd === 0) {
|
|
1274
|
+
close = i;
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
if (close === -1 || close < index) return null;
|
|
1280
|
+
const rawStart = Math.max(0, open - 240);
|
|
1281
|
+
const window = content.slice(rawStart, open);
|
|
1282
|
+
const cut = Math.max(window.lastIndexOf("}"), window.lastIndexOf(";"));
|
|
1283
|
+
const headerStart = cut === -1 ? rawStart : rawStart + cut + 1;
|
|
1284
|
+
const header = content.slice(headerStart, open);
|
|
1285
|
+
if (HANDLER_HEADER_RE.test(header)) {
|
|
1286
|
+
return content.slice(headerStart, close + 1);
|
|
1287
|
+
}
|
|
1288
|
+
searchFrom = open - 1;
|
|
1289
|
+
if (searchFrom < 0) return null;
|
|
1290
|
+
}
|
|
1291
|
+
return null;
|
|
1292
|
+
}
|
|
1224
1293
|
var SERVER_SIDE_PATH_RE = new RegExp(
|
|
1225
1294
|
[
|
|
1226
1295
|
// Directory-style anchors — match with OR without leading slash so
|
|
@@ -4344,10 +4413,14 @@ function detectFramework(files) {
|
|
|
4344
4413
|
if (frameworks.size === 0) frameworks.add("unknown");
|
|
4345
4414
|
return [...frameworks];
|
|
4346
4415
|
}
|
|
4416
|
+
function describesRatherThanUses(lowerPath) {
|
|
4417
|
+
return /(^|\/)(public|static|assets|fixtures|__fixtures__|testdata|test-fixtures)\//.test(lowerPath) || /\.(md|mdx|txt|rst)$/.test(lowerPath);
|
|
4418
|
+
}
|
|
4347
4419
|
function detectPlatform(files) {
|
|
4348
4420
|
const platforms = /* @__PURE__ */ new Set();
|
|
4349
|
-
for (const { path, content } of files) {
|
|
4421
|
+
for (const { path, content: rawContent } of files) {
|
|
4350
4422
|
const p = path.toLowerCase();
|
|
4423
|
+
const content = describesRatherThanUses(p) ? "" : rawContent;
|
|
4351
4424
|
if (/(^|\/)lovable\.config\./.test(p) || /lovable-tagger/i.test(content) || /lovable\.dev/i.test(content)) {
|
|
4352
4425
|
platforms.add("lovable");
|
|
4353
4426
|
}
|
|
@@ -5314,8 +5387,13 @@ var complianceMap = {
|
|
|
5314
5387
|
// VC211–VC212: hardcoded sensitive personal data (PII) in source
|
|
5315
5388
|
VC211: { owasp: "A02:2021", cwe: "CWE-540" },
|
|
5316
5389
|
// hardcoded credit card number
|
|
5317
|
-
VC212: { owasp: "A02:2021", cwe: "CWE-540" }
|
|
5390
|
+
VC212: { owasp: "A02:2021", cwe: "CWE-540" },
|
|
5318
5391
|
// hardcoded US SSN
|
|
5392
|
+
// VC213–VC214: account state held in browser storage
|
|
5393
|
+
VC213: { owasp: "A01:2021", cwe: "CWE-602" },
|
|
5394
|
+
// entitlement from web storage (client-side enforcement)
|
|
5395
|
+
VC214: { owasp: "A04:2021", cwe: "CWE-1188" }
|
|
5396
|
+
// per-account state from web storage (insecure default state)
|
|
5319
5397
|
};
|
|
5320
5398
|
var consoleLogProduction = {
|
|
5321
5399
|
id: "VC097",
|
|
@@ -8113,6 +8191,74 @@ var webhookMissingIdempotency = {
|
|
|
8113
8191
|
}], content, "VC209");
|
|
8114
8192
|
}
|
|
8115
8193
|
};
|
|
8194
|
+
var ENTITLEMENT_KEY_RE = /(is_?admin|admin|role|is_?pro\b|premium|is_?paid|paid|plan|tier|subscri|entitle|licen[cs]e|permission|owner|is_?verified|credits?|quota)/i;
|
|
8195
|
+
var LIFECYCLE_KEY_RE = /(onboard|first[_-]?time|has[_-]?seen|seen[_-]?|dismiss|welcome|tour|intro|visited|new[_-]?user|completed[_-]?setup)/i;
|
|
8196
|
+
var USED_AS_CONDITION_RE = /===|!==|==|!=|\?|&&|\|\||if\s*\(|return\s/;
|
|
8197
|
+
function webStorageReads(content, keyRe) {
|
|
8198
|
+
const out = [];
|
|
8199
|
+
const re = /(?:localStorage|sessionStorage)\s*\.\s*getItem\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g;
|
|
8200
|
+
for (const m of content.matchAll(re)) {
|
|
8201
|
+
if (m.index === void 0) continue;
|
|
8202
|
+
if (!keyRe.test(m[1])) continue;
|
|
8203
|
+
const lineStart = content.lastIndexOf("\n", m.index) + 1;
|
|
8204
|
+
let lineEnd = content.indexOf("\n", m.index);
|
|
8205
|
+
if (lineEnd === -1) lineEnd = content.length;
|
|
8206
|
+
if (!USED_AS_CONDITION_RE.test(content.slice(lineStart, lineEnd))) continue;
|
|
8207
|
+
out.push({ key: m[1], index: m.index });
|
|
8208
|
+
}
|
|
8209
|
+
return out;
|
|
8210
|
+
}
|
|
8211
|
+
var entitlementFromWebStorage = {
|
|
8212
|
+
id: "VC213",
|
|
8213
|
+
title: "Entitlement or role read from browser storage",
|
|
8214
|
+
severity: "high",
|
|
8215
|
+
category: "Authorization",
|
|
8216
|
+
description: "A plan, role, or permission read from localStorage / sessionStorage and branched on is a client-side authorization check. The store belongs to the user: typing `localStorage.setItem('isPro','true')` into devtools grants the feature. Entitlement must be decided by the server on every request that depends on it.",
|
|
8217
|
+
check(content, filePath) {
|
|
8218
|
+
if (!/\.(jsx?|tsx?|vue|svelte)$/.test(filePath)) return [];
|
|
8219
|
+
if (isTestFile(filePath)) return [];
|
|
8220
|
+
const hits = webStorageReads(content, ENTITLEMENT_KEY_RE);
|
|
8221
|
+
if (hits.length === 0) return [];
|
|
8222
|
+
const first = hits[0];
|
|
8223
|
+
const line = lineNumberAt(content, first.index);
|
|
8224
|
+
return filterSilenced([{
|
|
8225
|
+
rule: "VC213",
|
|
8226
|
+
title: entitlementFromWebStorage.title,
|
|
8227
|
+
severity: "high",
|
|
8228
|
+
category: "Authorization",
|
|
8229
|
+
file: filePath,
|
|
8230
|
+
line,
|
|
8231
|
+
snippet: getSnippet(content, line),
|
|
8232
|
+
fix: `"${first.key}" is read from browser storage and branched on. A user can set it to anything. Decide entitlement server-side \u2014 from the session, a token claim, or a database read \u2014 and treat the cached copy as a display hint only. If this value is already re-verified on the server before anything is granted, add an inline \`// VC213-OK: <reason>\` comment.`
|
|
8233
|
+
}], content, "VC213");
|
|
8234
|
+
}
|
|
8235
|
+
};
|
|
8236
|
+
var accountStateFromWebStorage = {
|
|
8237
|
+
id: "VC214",
|
|
8238
|
+
title: "Per-account state decided by browser storage alone",
|
|
8239
|
+
severity: "info",
|
|
8240
|
+
category: "Logic",
|
|
8241
|
+
description: "Onboarding, 'first time here', 'already seen' and similar per-ACCOUNT state read only from localStorage / sessionStorage. Browser storage is per-device and per-profile: it is wiped by a fresh login, cleared cookies, a private window, a container tab, or simply a second machine \u2014 so the app greets an established user as brand new. Only fires in files that are already auth-aware, because a purely anonymous banner dismissal is the correct use of local storage.",
|
|
8242
|
+
check(content, filePath) {
|
|
8243
|
+
if (!/\.(jsx?|tsx?|vue|svelte)$/.test(filePath)) return [];
|
|
8244
|
+
if (isTestFile(filePath)) return [];
|
|
8245
|
+
if (!/isSignedIn|useAuth|useUser|useSession|currentUser|getServerSession|session\?\.|auth\(\)|clerk/i.test(content)) return [];
|
|
8246
|
+
const hits = webStorageReads(content, LIFECYCLE_KEY_RE);
|
|
8247
|
+
if (hits.length === 0) return [];
|
|
8248
|
+
const first = hits[0];
|
|
8249
|
+
const line = lineNumberAt(content, first.index);
|
|
8250
|
+
return filterSilenced([{
|
|
8251
|
+
rule: "VC214",
|
|
8252
|
+
title: accountStateFromWebStorage.title,
|
|
8253
|
+
severity: "info",
|
|
8254
|
+
category: "Logic",
|
|
8255
|
+
file: filePath,
|
|
8256
|
+
line,
|
|
8257
|
+
snippet: getSnippet(content, line),
|
|
8258
|
+
fix: `"${first.key}" describes the ACCOUNT but is stored per-browser, so it resets on a new login, a cleared cookie, a private window, or another machine \u2014 and the user is treated as new again. Derive it from server state (has this user ever completed the action?) and keep browser storage for the per-device half, like "I closed this box". If this really is per-device by design, add an inline \`// VC214-OK: <reason>\` comment.`
|
|
8259
|
+
}], content, "VC214");
|
|
8260
|
+
}
|
|
8261
|
+
};
|
|
8116
8262
|
var middlewareMatcherExcludesApi = {
|
|
8117
8263
|
id: "VC210",
|
|
8118
8264
|
title: "Auth middleware matcher excludes API routes",
|
|
@@ -8669,15 +8815,22 @@ var insecureDirectObjectReference = {
|
|
|
8669
8815
|
if (!filePath.match(/\.(js|ts|jsx|tsx)$/)) return [];
|
|
8670
8816
|
if (isTestFile(filePath)) return [];
|
|
8671
8817
|
if (/admin/i.test(filePath)) return [];
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8818
|
+
const scan = maskComments(content);
|
|
8819
|
+
const LOOKUP_RE = /findUnique|findFirst|findById|\.findOne\b|\.find\s*\(\s*\{|WHERE[\s\S]{0,120}?(?:params|req\.(?:body|query))|\.get\([^)]*(?:params|req\.(?:body|query))/i;
|
|
8820
|
+
const lookup = scan.match(LOOKUP_RE);
|
|
8821
|
+
if (!lookup || lookup.index === void 0) return [];
|
|
8822
|
+
const handlerScope = enclosingHandler(scan, lookup.index) ?? scan;
|
|
8823
|
+
const qScope = queryScope(scan, lookup.index) ?? handlerScope;
|
|
8824
|
+
if (/userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i.test(qScope)) return [];
|
|
8825
|
+
if (/requireUser|requireUserForApi|requireAuth|withAuth|getServerSession|auth\(\)|passport|isAuthenticated/i.test(handlerScope)) return [];
|
|
8675
8826
|
const isNextApiIdor = /\/api\//i.test(filePath) && /export\s+(?:async\s+)?function\s+(?:GET|PUT|PATCH|DELETE)/i.test(content) && /params\.id|params\.(?:slug|uuid)|req\.params\./i.test(content);
|
|
8676
8827
|
const hasExpressHandler = /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]*["'`]\s*,/i.test(content);
|
|
8677
8828
|
const readsObjectRef = /req\.params\b|req\.(?:body|query)\.\w*id\b/i.test(content);
|
|
8678
8829
|
const isExpressIdor = hasExpressHandler && readsObjectRef;
|
|
8679
|
-
|
|
8680
|
-
const
|
|
8830
|
+
const hasExportedHandler = /(?:module\.)?exports\.\w+\s*=\s*(?:async\s+)?(?:function\s*)?\(\s*req\b[^)]*\)/i.test(content) || /(?:module\.)?exports\.\w+\s*=\s*(?:async\s*)?\(\s*req\b[^)]*\)\s*=>/i.test(content);
|
|
8831
|
+
const isControllerIdor = hasExportedHandler && readsObjectRef;
|
|
8832
|
+
if (!isNextApiIdor && !isExpressIdor && !isControllerIdor) return [];
|
|
8833
|
+
const m = scan.match(/params\.id|params\.(?:slug|uuid)|req\.params\.\w+|req\.params\b|req\.(?:body|query)\.\w*id/i);
|
|
8681
8834
|
if (!m || m.index === void 0) return [];
|
|
8682
8835
|
const lineNum = lineNumberAt(content, m.index);
|
|
8683
8836
|
return [{
|
|
@@ -8980,7 +9133,10 @@ var allCustomRules = [
|
|
|
8980
9133
|
graphqlCSRFDisabled,
|
|
8981
9134
|
// VC211–VC212: hardcoded sensitive personal data (PII)
|
|
8982
9135
|
hardcodedCreditCard,
|
|
8983
|
-
hardcodedSSN
|
|
9136
|
+
hardcodedSSN,
|
|
9137
|
+
// VC213–VC214: state that belongs to the account, kept in the browser
|
|
9138
|
+
entitlementFromWebStorage,
|
|
9139
|
+
accountStateFromWebStorage
|
|
8984
9140
|
];
|
|
8985
9141
|
function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
|
|
8986
9142
|
const findings = [];
|
|
@@ -8999,7 +9155,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
8999
9155
|
}
|
|
9000
9156
|
}
|
|
9001
9157
|
if (maxLineLen > 5e4) return findings;
|
|
9002
|
-
if (/
|
|
9158
|
+
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
9003
9159
|
const vendoredFile = isVendoredPath(filePath);
|
|
9004
9160
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
9005
9161
|
for (const rule of ruleset) {
|
|
@@ -9032,8 +9188,8 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
9032
9188
|
|
|
9033
9189
|
// src/rule-counts.ts
|
|
9034
9190
|
var FREE_RULE_COUNT = 30;
|
|
9035
|
-
var PRO_RULE_COUNT =
|
|
9036
|
-
var TOTAL_RULE_COUNT =
|
|
9191
|
+
var PRO_RULE_COUNT = 184;
|
|
9192
|
+
var TOTAL_RULE_COUNT = 214;
|
|
9037
9193
|
|
|
9038
9194
|
// src/ai-fp-filter.ts
|
|
9039
9195
|
var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
|
|
@@ -9415,6 +9571,112 @@ function scanEntropy(files) {
|
|
|
9415
9571
|
return findings;
|
|
9416
9572
|
}
|
|
9417
9573
|
|
|
9574
|
+
// src/routes.ts
|
|
9575
|
+
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
9576
|
+
var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
|
|
9577
|
+
function hasDep(files, name) {
|
|
9578
|
+
const pkg = files.find(
|
|
9579
|
+
(f) => f.path === "package.json" || f.path.endsWith("/package.json")
|
|
9580
|
+
);
|
|
9581
|
+
if (!pkg) return false;
|
|
9582
|
+
try {
|
|
9583
|
+
const json = JSON.parse(pkg.content);
|
|
9584
|
+
return Boolean({ ...json.dependencies ?? {}, ...json.devDependencies ?? {} }[name]);
|
|
9585
|
+
} catch {
|
|
9586
|
+
return false;
|
|
9587
|
+
}
|
|
9588
|
+
}
|
|
9589
|
+
function normalize(p) {
|
|
9590
|
+
if (!p.startsWith("/")) return "";
|
|
9591
|
+
if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
|
|
9592
|
+
return p;
|
|
9593
|
+
}
|
|
9594
|
+
function extractRoutes(files) {
|
|
9595
|
+
const routes = /* @__PURE__ */ new Map();
|
|
9596
|
+
const frameworks = /* @__PURE__ */ new Set();
|
|
9597
|
+
const add = (raw, framework, source, kindOverride) => {
|
|
9598
|
+
const path = normalize(raw);
|
|
9599
|
+
if (!path || routes.has(path)) return;
|
|
9600
|
+
routes.set(path, {
|
|
9601
|
+
path,
|
|
9602
|
+
// The URL prefix is a fallback, not the authority. A Next `route.ts` is a
|
|
9603
|
+
// handler wherever it lives: /free-trust-page/claim/start/route.ts is an
|
|
9604
|
+
// endpoint, not a page, and calling it a page mislabels what an attacker
|
|
9605
|
+
// would actually hit.
|
|
9606
|
+
kind: kindOverride ?? (API_RE.test(path) ? "api" : "page"),
|
|
9607
|
+
dynamic: DYNAMIC_RE.test(path),
|
|
9608
|
+
framework,
|
|
9609
|
+
source
|
|
9610
|
+
});
|
|
9611
|
+
frameworks.add(framework);
|
|
9612
|
+
};
|
|
9613
|
+
const isNext = hasDep(files, "next");
|
|
9614
|
+
const isExpress = hasDep(files, "express") || hasDep(files, "hono") || hasDep(files, "koa");
|
|
9615
|
+
const isTanstack = hasDep(files, "@tanstack/react-router") || hasDep(files, "@tanstack/react-start");
|
|
9616
|
+
if (isTanstack) {
|
|
9617
|
+
const gen = files.find((f) => f.path.endsWith("routeTree.gen.ts"));
|
|
9618
|
+
if (gen) {
|
|
9619
|
+
for (const m of gen.content.matchAll(/'(\/[A-Za-z0-9_\-/$.]*)'/g)) {
|
|
9620
|
+
if (m[1].split("/").some((seg) => seg.startsWith("_"))) continue;
|
|
9621
|
+
add(m[1], "tanstack-router", gen.path);
|
|
9622
|
+
}
|
|
9623
|
+
}
|
|
9624
|
+
}
|
|
9625
|
+
for (const file of files) {
|
|
9626
|
+
const rel = file.path;
|
|
9627
|
+
if (isNext) {
|
|
9628
|
+
const page = rel.match(/(?:^|\/)app\/(?:(.*)\/)?page\.(tsx?|jsx?)$/);
|
|
9629
|
+
if (page) {
|
|
9630
|
+
const segs = (page[1] ?? "").split("/").filter(Boolean).filter((s) => !/^\(.*\)$/.test(s));
|
|
9631
|
+
add("/" + segs.join("/"), "next-app", rel);
|
|
9632
|
+
}
|
|
9633
|
+
const handler = rel.match(/(?:^|\/)app\/(?:(.*)\/)?route\.(tsx?|jsx?)$/);
|
|
9634
|
+
if (handler) {
|
|
9635
|
+
const segs = (handler[1] ?? "").split("/").filter(Boolean).filter((s) => !/^\(.*\)$/.test(s));
|
|
9636
|
+
add("/" + segs.join("/"), "next-app", rel, "api");
|
|
9637
|
+
}
|
|
9638
|
+
const pages = rel.match(/(?:^|\/)pages\/(.+)\.(tsx?|jsx?)$/);
|
|
9639
|
+
if (pages && !/^_/.test(pages[1].split("/").pop() ?? "")) {
|
|
9640
|
+
const p = "/" + pages[1].replace(/\/index$/, "").replace(/^index$/, "");
|
|
9641
|
+
add(p === "/" ? "/" : p, "next-pages", rel);
|
|
9642
|
+
}
|
|
9643
|
+
}
|
|
9644
|
+
if (!/\.(tsx?|jsx?|mjs|cjs|py)$/.test(rel)) continue;
|
|
9645
|
+
const src = file.content;
|
|
9646
|
+
for (const m of src.matchAll(/<Route\s[^>]*path\s*=\s*["'`]([^"'`]+)["'`]/g)) {
|
|
9647
|
+
add(m[1].startsWith("/") ? m[1] : "/" + m[1], "react-router", rel);
|
|
9648
|
+
}
|
|
9649
|
+
if (/createBrowserRouter|createHashRouter|useRoutes/.test(src)) {
|
|
9650
|
+
for (const m of src.matchAll(/path\s*:\s*["'`]([^"'`]+)["'`]/g)) {
|
|
9651
|
+
add(m[1].startsWith("/") ? m[1] : "/" + m[1], "react-router", rel);
|
|
9652
|
+
}
|
|
9653
|
+
}
|
|
9654
|
+
for (const m of src.matchAll(
|
|
9655
|
+
/@\w+\.(?:route|get|post|put|patch|delete)\(\s*["']([^"']+)["']/g
|
|
9656
|
+
)) {
|
|
9657
|
+
add(m[1], "flask-fastapi", rel);
|
|
9658
|
+
}
|
|
9659
|
+
for (const m of src.matchAll(/add_url_rule\(\s*["']([^"']+)["']/g)) {
|
|
9660
|
+
add(m[1], "flask-fastapi", rel);
|
|
9661
|
+
}
|
|
9662
|
+
if (isExpress) {
|
|
9663
|
+
for (const m of src.matchAll(
|
|
9664
|
+
/\b(?:app|router)\.(?:get|post|put|patch|delete|all)\(\s*["'`]([^"'`]+)["'`]/g
|
|
9665
|
+
)) {
|
|
9666
|
+
add(m[1], "express", rel);
|
|
9667
|
+
}
|
|
9668
|
+
}
|
|
9669
|
+
}
|
|
9670
|
+
return {
|
|
9671
|
+
frameworks: [...frameworks],
|
|
9672
|
+
routes: [...routes.values()].sort((a, b) => a.path.localeCompare(b.path))
|
|
9673
|
+
};
|
|
9674
|
+
}
|
|
9675
|
+
function routeForFile(table, filePath) {
|
|
9676
|
+
const norm = filePath.replace(/^\.\//, "");
|
|
9677
|
+
return table.routes.find((r) => r.source === norm || r.source.endsWith("/" + norm));
|
|
9678
|
+
}
|
|
9679
|
+
|
|
9418
9680
|
// src/url-recon.ts
|
|
9419
9681
|
var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
|
|
9420
9682
|
"localhost",
|
|
@@ -9594,6 +9856,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9594
9856
|
PRO_RULE_COUNT,
|
|
9595
9857
|
RULE_IMPACTS,
|
|
9596
9858
|
TOTAL_RULE_COUNT,
|
|
9859
|
+
accountStateFromWebStorage,
|
|
9597
9860
|
allCustomRules,
|
|
9598
9861
|
allRules,
|
|
9599
9862
|
androidDebuggable,
|
|
@@ -9631,6 +9894,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9631
9894
|
ecbModeEncryption,
|
|
9632
9895
|
electronNavigationUnrestricted,
|
|
9633
9896
|
emptyCatchBlock,
|
|
9897
|
+
entitlementFromWebStorage,
|
|
9634
9898
|
envNotGitignored,
|
|
9635
9899
|
evalUsage,
|
|
9636
9900
|
eventListenerLeak,
|
|
@@ -9645,6 +9909,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9645
9909
|
exposedServerActions,
|
|
9646
9910
|
exposedSourceMaps,
|
|
9647
9911
|
exposedStackTraces,
|
|
9912
|
+
extractRoutes,
|
|
9648
9913
|
extractScriptUrls,
|
|
9649
9914
|
filterFalsePositives,
|
|
9650
9915
|
findSourceMapRefs,
|
|
@@ -9788,6 +10053,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9788
10053
|
rdsPubliclyAccessible,
|
|
9789
10054
|
reflectedCORSOrigin,
|
|
9790
10055
|
regexDos,
|
|
10056
|
+
routeForFile,
|
|
9791
10057
|
runCustomRules,
|
|
9792
10058
|
s3BucketNoEncryption,
|
|
9793
10059
|
scanEntropy,
|