xploitscan-shared-rules 1.17.0 → 1.20.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 +212 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -12
- package/dist/index.d.ts +130 -12
- package/dist/index.js +205 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -258,7 +258,9 @@ var RULE_IMPACTS = {
|
|
|
258
258
|
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.",
|
|
259
259
|
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.",
|
|
260
260
|
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.",
|
|
261
|
-
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."
|
|
261
|
+
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.",
|
|
262
|
+
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.",
|
|
263
|
+
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."
|
|
262
264
|
};
|
|
263
265
|
|
|
264
266
|
// src/exposure.ts
|
|
@@ -4061,10 +4063,14 @@ function detectFramework(files) {
|
|
|
4061
4063
|
if (frameworks.size === 0) frameworks.add("unknown");
|
|
4062
4064
|
return [...frameworks];
|
|
4063
4065
|
}
|
|
4066
|
+
function describesRatherThanUses(lowerPath) {
|
|
4067
|
+
return /(^|\/)(public|static|assets|fixtures|__fixtures__|testdata|test-fixtures)\//.test(lowerPath) || /\.(md|mdx|txt|rst)$/.test(lowerPath);
|
|
4068
|
+
}
|
|
4064
4069
|
function detectPlatform(files) {
|
|
4065
4070
|
const platforms = /* @__PURE__ */ new Set();
|
|
4066
|
-
for (const { path, content } of files) {
|
|
4071
|
+
for (const { path, content: rawContent } of files) {
|
|
4067
4072
|
const p = path.toLowerCase();
|
|
4073
|
+
const content = describesRatherThanUses(p) ? "" : rawContent;
|
|
4068
4074
|
if (/(^|\/)lovable\.config\./.test(p) || /lovable-tagger/i.test(content) || /lovable\.dev/i.test(content)) {
|
|
4069
4075
|
platforms.add("lovable");
|
|
4070
4076
|
}
|
|
@@ -5031,8 +5037,13 @@ var complianceMap = {
|
|
|
5031
5037
|
// VC211–VC212: hardcoded sensitive personal data (PII) in source
|
|
5032
5038
|
VC211: { owasp: "A02:2021", cwe: "CWE-540" },
|
|
5033
5039
|
// hardcoded credit card number
|
|
5034
|
-
VC212: { owasp: "A02:2021", cwe: "CWE-540" }
|
|
5040
|
+
VC212: { owasp: "A02:2021", cwe: "CWE-540" },
|
|
5035
5041
|
// hardcoded US SSN
|
|
5042
|
+
// VC213–VC214: account state held in browser storage
|
|
5043
|
+
VC213: { owasp: "A01:2021", cwe: "CWE-602" },
|
|
5044
|
+
// entitlement from web storage (client-side enforcement)
|
|
5045
|
+
VC214: { owasp: "A04:2021", cwe: "CWE-1188" }
|
|
5046
|
+
// per-account state from web storage (insecure default state)
|
|
5036
5047
|
};
|
|
5037
5048
|
var consoleLogProduction = {
|
|
5038
5049
|
id: "VC097",
|
|
@@ -7830,6 +7841,74 @@ var webhookMissingIdempotency = {
|
|
|
7830
7841
|
}], content, "VC209");
|
|
7831
7842
|
}
|
|
7832
7843
|
};
|
|
7844
|
+
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;
|
|
7845
|
+
var LIFECYCLE_KEY_RE = /(onboard|first[_-]?time|has[_-]?seen|seen[_-]?|dismiss|welcome|tour|intro|visited|new[_-]?user|completed[_-]?setup)/i;
|
|
7846
|
+
var USED_AS_CONDITION_RE = /===|!==|==|!=|\?|&&|\|\||if\s*\(|return\s/;
|
|
7847
|
+
function webStorageReads(content, keyRe) {
|
|
7848
|
+
const out = [];
|
|
7849
|
+
const re = /(?:localStorage|sessionStorage)\s*\.\s*getItem\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g;
|
|
7850
|
+
for (const m of content.matchAll(re)) {
|
|
7851
|
+
if (m.index === void 0) continue;
|
|
7852
|
+
if (!keyRe.test(m[1])) continue;
|
|
7853
|
+
const lineStart = content.lastIndexOf("\n", m.index) + 1;
|
|
7854
|
+
let lineEnd = content.indexOf("\n", m.index);
|
|
7855
|
+
if (lineEnd === -1) lineEnd = content.length;
|
|
7856
|
+
if (!USED_AS_CONDITION_RE.test(content.slice(lineStart, lineEnd))) continue;
|
|
7857
|
+
out.push({ key: m[1], index: m.index });
|
|
7858
|
+
}
|
|
7859
|
+
return out;
|
|
7860
|
+
}
|
|
7861
|
+
var entitlementFromWebStorage = {
|
|
7862
|
+
id: "VC213",
|
|
7863
|
+
title: "Entitlement or role read from browser storage",
|
|
7864
|
+
severity: "high",
|
|
7865
|
+
category: "Authorization",
|
|
7866
|
+
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.",
|
|
7867
|
+
check(content, filePath) {
|
|
7868
|
+
if (!/\.(jsx?|tsx?|vue|svelte)$/.test(filePath)) return [];
|
|
7869
|
+
if (isTestFile(filePath)) return [];
|
|
7870
|
+
const hits = webStorageReads(content, ENTITLEMENT_KEY_RE);
|
|
7871
|
+
if (hits.length === 0) return [];
|
|
7872
|
+
const first = hits[0];
|
|
7873
|
+
const line = lineNumberAt(content, first.index);
|
|
7874
|
+
return filterSilenced([{
|
|
7875
|
+
rule: "VC213",
|
|
7876
|
+
title: entitlementFromWebStorage.title,
|
|
7877
|
+
severity: "high",
|
|
7878
|
+
category: "Authorization",
|
|
7879
|
+
file: filePath,
|
|
7880
|
+
line,
|
|
7881
|
+
snippet: getSnippet(content, line),
|
|
7882
|
+
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.`
|
|
7883
|
+
}], content, "VC213");
|
|
7884
|
+
}
|
|
7885
|
+
};
|
|
7886
|
+
var accountStateFromWebStorage = {
|
|
7887
|
+
id: "VC214",
|
|
7888
|
+
title: "Per-account state decided by browser storage alone",
|
|
7889
|
+
severity: "info",
|
|
7890
|
+
category: "Logic",
|
|
7891
|
+
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.",
|
|
7892
|
+
check(content, filePath) {
|
|
7893
|
+
if (!/\.(jsx?|tsx?|vue|svelte)$/.test(filePath)) return [];
|
|
7894
|
+
if (isTestFile(filePath)) return [];
|
|
7895
|
+
if (!/isSignedIn|useAuth|useUser|useSession|currentUser|getServerSession|session\?\.|auth\(\)|clerk/i.test(content)) return [];
|
|
7896
|
+
const hits = webStorageReads(content, LIFECYCLE_KEY_RE);
|
|
7897
|
+
if (hits.length === 0) return [];
|
|
7898
|
+
const first = hits[0];
|
|
7899
|
+
const line = lineNumberAt(content, first.index);
|
|
7900
|
+
return filterSilenced([{
|
|
7901
|
+
rule: "VC214",
|
|
7902
|
+
title: accountStateFromWebStorage.title,
|
|
7903
|
+
severity: "info",
|
|
7904
|
+
category: "Logic",
|
|
7905
|
+
file: filePath,
|
|
7906
|
+
line,
|
|
7907
|
+
snippet: getSnippet(content, line),
|
|
7908
|
+
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.`
|
|
7909
|
+
}], content, "VC214");
|
|
7910
|
+
}
|
|
7911
|
+
};
|
|
7833
7912
|
var middlewareMatcherExcludesApi = {
|
|
7834
7913
|
id: "VC210",
|
|
7835
7914
|
title: "Auth middleware matcher excludes API routes",
|
|
@@ -8697,7 +8776,10 @@ var allCustomRules = [
|
|
|
8697
8776
|
graphqlCSRFDisabled,
|
|
8698
8777
|
// VC211–VC212: hardcoded sensitive personal data (PII)
|
|
8699
8778
|
hardcodedCreditCard,
|
|
8700
|
-
hardcodedSSN
|
|
8779
|
+
hardcodedSSN,
|
|
8780
|
+
// VC213–VC214: state that belongs to the account, kept in the browser
|
|
8781
|
+
entitlementFromWebStorage,
|
|
8782
|
+
accountStateFromWebStorage
|
|
8701
8783
|
];
|
|
8702
8784
|
function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
|
|
8703
8785
|
const findings = [];
|
|
@@ -8716,7 +8798,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
8716
8798
|
}
|
|
8717
8799
|
}
|
|
8718
8800
|
if (maxLineLen > 5e4) return findings;
|
|
8719
|
-
if (/
|
|
8801
|
+
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
8720
8802
|
const vendoredFile = isVendoredPath(filePath);
|
|
8721
8803
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
8722
8804
|
for (const rule of ruleset) {
|
|
@@ -8747,6 +8829,11 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
8747
8829
|
return findings;
|
|
8748
8830
|
}
|
|
8749
8831
|
|
|
8832
|
+
// src/rule-counts.ts
|
|
8833
|
+
var FREE_RULE_COUNT = 30;
|
|
8834
|
+
var PRO_RULE_COUNT = 184;
|
|
8835
|
+
var TOTAL_RULE_COUNT = 214;
|
|
8836
|
+
|
|
8750
8837
|
// src/ai-fp-filter.ts
|
|
8751
8838
|
import Anthropic from "@anthropic-ai/sdk";
|
|
8752
8839
|
var REVIEW_SYSTEM_PROMPT = `You are reviewing security scan findings for false positives. Your job is to look at each finding and the surrounding code to determine if it's a REAL security vulnerability or a FALSE POSITIVE.
|
|
@@ -9127,6 +9214,112 @@ function scanEntropy(files) {
|
|
|
9127
9214
|
return findings;
|
|
9128
9215
|
}
|
|
9129
9216
|
|
|
9217
|
+
// src/routes.ts
|
|
9218
|
+
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
9219
|
+
var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
|
|
9220
|
+
function hasDep(files, name) {
|
|
9221
|
+
const pkg = files.find(
|
|
9222
|
+
(f) => f.path === "package.json" || f.path.endsWith("/package.json")
|
|
9223
|
+
);
|
|
9224
|
+
if (!pkg) return false;
|
|
9225
|
+
try {
|
|
9226
|
+
const json = JSON.parse(pkg.content);
|
|
9227
|
+
return Boolean({ ...json.dependencies ?? {}, ...json.devDependencies ?? {} }[name]);
|
|
9228
|
+
} catch {
|
|
9229
|
+
return false;
|
|
9230
|
+
}
|
|
9231
|
+
}
|
|
9232
|
+
function normalize(p) {
|
|
9233
|
+
if (!p.startsWith("/")) return "";
|
|
9234
|
+
if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
|
|
9235
|
+
return p;
|
|
9236
|
+
}
|
|
9237
|
+
function extractRoutes(files) {
|
|
9238
|
+
const routes = /* @__PURE__ */ new Map();
|
|
9239
|
+
const frameworks = /* @__PURE__ */ new Set();
|
|
9240
|
+
const add = (raw, framework, source, kindOverride) => {
|
|
9241
|
+
const path = normalize(raw);
|
|
9242
|
+
if (!path || routes.has(path)) return;
|
|
9243
|
+
routes.set(path, {
|
|
9244
|
+
path,
|
|
9245
|
+
// The URL prefix is a fallback, not the authority. A Next `route.ts` is a
|
|
9246
|
+
// handler wherever it lives: /free-trust-page/claim/start/route.ts is an
|
|
9247
|
+
// endpoint, not a page, and calling it a page mislabels what an attacker
|
|
9248
|
+
// would actually hit.
|
|
9249
|
+
kind: kindOverride ?? (API_RE.test(path) ? "api" : "page"),
|
|
9250
|
+
dynamic: DYNAMIC_RE.test(path),
|
|
9251
|
+
framework,
|
|
9252
|
+
source
|
|
9253
|
+
});
|
|
9254
|
+
frameworks.add(framework);
|
|
9255
|
+
};
|
|
9256
|
+
const isNext = hasDep(files, "next");
|
|
9257
|
+
const isExpress = hasDep(files, "express") || hasDep(files, "hono") || hasDep(files, "koa");
|
|
9258
|
+
const isTanstack = hasDep(files, "@tanstack/react-router") || hasDep(files, "@tanstack/react-start");
|
|
9259
|
+
if (isTanstack) {
|
|
9260
|
+
const gen = files.find((f) => f.path.endsWith("routeTree.gen.ts"));
|
|
9261
|
+
if (gen) {
|
|
9262
|
+
for (const m of gen.content.matchAll(/'(\/[A-Za-z0-9_\-/$.]*)'/g)) {
|
|
9263
|
+
if (m[1].split("/").some((seg) => seg.startsWith("_"))) continue;
|
|
9264
|
+
add(m[1], "tanstack-router", gen.path);
|
|
9265
|
+
}
|
|
9266
|
+
}
|
|
9267
|
+
}
|
|
9268
|
+
for (const file of files) {
|
|
9269
|
+
const rel = file.path;
|
|
9270
|
+
if (isNext) {
|
|
9271
|
+
const page = rel.match(/(?:^|\/)app\/(?:(.*)\/)?page\.(tsx?|jsx?)$/);
|
|
9272
|
+
if (page) {
|
|
9273
|
+
const segs = (page[1] ?? "").split("/").filter(Boolean).filter((s) => !/^\(.*\)$/.test(s));
|
|
9274
|
+
add("/" + segs.join("/"), "next-app", rel);
|
|
9275
|
+
}
|
|
9276
|
+
const handler = rel.match(/(?:^|\/)app\/(?:(.*)\/)?route\.(tsx?|jsx?)$/);
|
|
9277
|
+
if (handler) {
|
|
9278
|
+
const segs = (handler[1] ?? "").split("/").filter(Boolean).filter((s) => !/^\(.*\)$/.test(s));
|
|
9279
|
+
add("/" + segs.join("/"), "next-app", rel, "api");
|
|
9280
|
+
}
|
|
9281
|
+
const pages = rel.match(/(?:^|\/)pages\/(.+)\.(tsx?|jsx?)$/);
|
|
9282
|
+
if (pages && !/^_/.test(pages[1].split("/").pop() ?? "")) {
|
|
9283
|
+
const p = "/" + pages[1].replace(/\/index$/, "").replace(/^index$/, "");
|
|
9284
|
+
add(p === "/" ? "/" : p, "next-pages", rel);
|
|
9285
|
+
}
|
|
9286
|
+
}
|
|
9287
|
+
if (!/\.(tsx?|jsx?|mjs|cjs|py)$/.test(rel)) continue;
|
|
9288
|
+
const src = file.content;
|
|
9289
|
+
for (const m of src.matchAll(/<Route\s[^>]*path\s*=\s*["'`]([^"'`]+)["'`]/g)) {
|
|
9290
|
+
add(m[1].startsWith("/") ? m[1] : "/" + m[1], "react-router", rel);
|
|
9291
|
+
}
|
|
9292
|
+
if (/createBrowserRouter|createHashRouter|useRoutes/.test(src)) {
|
|
9293
|
+
for (const m of src.matchAll(/path\s*:\s*["'`]([^"'`]+)["'`]/g)) {
|
|
9294
|
+
add(m[1].startsWith("/") ? m[1] : "/" + m[1], "react-router", rel);
|
|
9295
|
+
}
|
|
9296
|
+
}
|
|
9297
|
+
for (const m of src.matchAll(
|
|
9298
|
+
/@\w+\.(?:route|get|post|put|patch|delete)\(\s*["']([^"']+)["']/g
|
|
9299
|
+
)) {
|
|
9300
|
+
add(m[1], "flask-fastapi", rel);
|
|
9301
|
+
}
|
|
9302
|
+
for (const m of src.matchAll(/add_url_rule\(\s*["']([^"']+)["']/g)) {
|
|
9303
|
+
add(m[1], "flask-fastapi", rel);
|
|
9304
|
+
}
|
|
9305
|
+
if (isExpress) {
|
|
9306
|
+
for (const m of src.matchAll(
|
|
9307
|
+
/\b(?:app|router)\.(?:get|post|put|patch|delete|all)\(\s*["'`]([^"'`]+)["'`]/g
|
|
9308
|
+
)) {
|
|
9309
|
+
add(m[1], "express", rel);
|
|
9310
|
+
}
|
|
9311
|
+
}
|
|
9312
|
+
}
|
|
9313
|
+
return {
|
|
9314
|
+
frameworks: [...frameworks],
|
|
9315
|
+
routes: [...routes.values()].sort((a, b) => a.path.localeCompare(b.path))
|
|
9316
|
+
};
|
|
9317
|
+
}
|
|
9318
|
+
function routeForFile(table, filePath) {
|
|
9319
|
+
const norm = filePath.replace(/^\.\//, "");
|
|
9320
|
+
return table.routes.find((r) => r.source === norm || r.source.endsWith("/" + norm));
|
|
9321
|
+
}
|
|
9322
|
+
|
|
9130
9323
|
// src/url-recon.ts
|
|
9131
9324
|
var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
|
|
9132
9325
|
"localhost",
|
|
@@ -9300,8 +9493,12 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
9300
9493
|
return [...new Set(out)];
|
|
9301
9494
|
}
|
|
9302
9495
|
export {
|
|
9496
|
+
FREE_RULE_COUNT,
|
|
9303
9497
|
NON_APP_PATH_PATTERNS,
|
|
9498
|
+
PRO_RULE_COUNT,
|
|
9304
9499
|
RULE_IMPACTS,
|
|
9500
|
+
TOTAL_RULE_COUNT,
|
|
9501
|
+
accountStateFromWebStorage,
|
|
9305
9502
|
allCustomRules,
|
|
9306
9503
|
allRules,
|
|
9307
9504
|
androidDebuggable,
|
|
@@ -9339,6 +9536,7 @@ export {
|
|
|
9339
9536
|
ecbModeEncryption,
|
|
9340
9537
|
electronNavigationUnrestricted,
|
|
9341
9538
|
emptyCatchBlock,
|
|
9539
|
+
entitlementFromWebStorage,
|
|
9342
9540
|
envNotGitignored,
|
|
9343
9541
|
evalUsage,
|
|
9344
9542
|
eventListenerLeak,
|
|
@@ -9353,6 +9551,7 @@ export {
|
|
|
9353
9551
|
exposedServerActions,
|
|
9354
9552
|
exposedSourceMaps,
|
|
9355
9553
|
exposedStackTraces,
|
|
9554
|
+
extractRoutes,
|
|
9356
9555
|
extractScriptUrls,
|
|
9357
9556
|
filterFalsePositives,
|
|
9358
9557
|
findSourceMapRefs,
|
|
@@ -9496,6 +9695,7 @@ export {
|
|
|
9496
9695
|
rdsPubliclyAccessible,
|
|
9497
9696
|
reflectedCORSOrigin,
|
|
9498
9697
|
regexDos,
|
|
9698
|
+
routeForFile,
|
|
9499
9699
|
runCustomRules,
|
|
9500
9700
|
s3BucketNoEncryption,
|
|
9501
9701
|
scanEntropy,
|