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 CHANGED
@@ -30,8 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ FREE_RULE_COUNT: () => FREE_RULE_COUNT,
33
34
  NON_APP_PATH_PATTERNS: () => NON_APP_PATH_PATTERNS,
35
+ PRO_RULE_COUNT: () => PRO_RULE_COUNT,
34
36
  RULE_IMPACTS: () => RULE_IMPACTS,
37
+ TOTAL_RULE_COUNT: () => TOTAL_RULE_COUNT,
38
+ accountStateFromWebStorage: () => accountStateFromWebStorage,
35
39
  allCustomRules: () => allCustomRules,
36
40
  allRules: () => allRules,
37
41
  androidDebuggable: () => androidDebuggable,
@@ -69,6 +73,7 @@ __export(index_exports, {
69
73
  ecbModeEncryption: () => ecbModeEncryption,
70
74
  electronNavigationUnrestricted: () => electronNavigationUnrestricted,
71
75
  emptyCatchBlock: () => emptyCatchBlock,
76
+ entitlementFromWebStorage: () => entitlementFromWebStorage,
72
77
  envNotGitignored: () => envNotGitignored,
73
78
  evalUsage: () => evalUsage,
74
79
  eventListenerLeak: () => eventListenerLeak,
@@ -83,6 +88,7 @@ __export(index_exports, {
83
88
  exposedServerActions: () => exposedServerActions,
84
89
  exposedSourceMaps: () => exposedSourceMaps,
85
90
  exposedStackTraces: () => exposedStackTraces,
91
+ extractRoutes: () => extractRoutes,
86
92
  extractScriptUrls: () => extractScriptUrls,
87
93
  filterFalsePositives: () => filterFalsePositives,
88
94
  findSourceMapRefs: () => findSourceMapRefs,
@@ -226,6 +232,7 @@ __export(index_exports, {
226
232
  rdsPubliclyAccessible: () => rdsPubliclyAccessible,
227
233
  reflectedCORSOrigin: () => reflectedCORSOrigin,
228
234
  regexDos: () => regexDos,
235
+ routeForFile: () => routeForFile,
229
236
  runCustomRules: () => runCustomRules,
230
237
  s3BucketNoEncryption: () => s3BucketNoEncryption,
231
238
  scanEntropy: () => scanEntropy,
@@ -538,7 +545,9 @@ var RULE_IMPACTS = {
538
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.",
539
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.",
540
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.",
541
- 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."
542
551
  };
543
552
 
544
553
  // src/exposure.ts
@@ -4341,10 +4350,14 @@ function detectFramework(files) {
4341
4350
  if (frameworks.size === 0) frameworks.add("unknown");
4342
4351
  return [...frameworks];
4343
4352
  }
4353
+ function describesRatherThanUses(lowerPath) {
4354
+ return /(^|\/)(public|static|assets|fixtures|__fixtures__|testdata|test-fixtures)\//.test(lowerPath) || /\.(md|mdx|txt|rst)$/.test(lowerPath);
4355
+ }
4344
4356
  function detectPlatform(files) {
4345
4357
  const platforms = /* @__PURE__ */ new Set();
4346
- for (const { path, content } of files) {
4358
+ for (const { path, content: rawContent } of files) {
4347
4359
  const p = path.toLowerCase();
4360
+ const content = describesRatherThanUses(p) ? "" : rawContent;
4348
4361
  if (/(^|\/)lovable\.config\./.test(p) || /lovable-tagger/i.test(content) || /lovable\.dev/i.test(content)) {
4349
4362
  platforms.add("lovable");
4350
4363
  }
@@ -5311,8 +5324,13 @@ var complianceMap = {
5311
5324
  // VC211–VC212: hardcoded sensitive personal data (PII) in source
5312
5325
  VC211: { owasp: "A02:2021", cwe: "CWE-540" },
5313
5326
  // hardcoded credit card number
5314
- VC212: { owasp: "A02:2021", cwe: "CWE-540" }
5327
+ VC212: { owasp: "A02:2021", cwe: "CWE-540" },
5315
5328
  // hardcoded US SSN
5329
+ // VC213–VC214: account state held in browser storage
5330
+ VC213: { owasp: "A01:2021", cwe: "CWE-602" },
5331
+ // entitlement from web storage (client-side enforcement)
5332
+ VC214: { owasp: "A04:2021", cwe: "CWE-1188" }
5333
+ // per-account state from web storage (insecure default state)
5316
5334
  };
5317
5335
  var consoleLogProduction = {
5318
5336
  id: "VC097",
@@ -8110,6 +8128,74 @@ var webhookMissingIdempotency = {
8110
8128
  }], content, "VC209");
8111
8129
  }
8112
8130
  };
8131
+ 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;
8132
+ var LIFECYCLE_KEY_RE = /(onboard|first[_-]?time|has[_-]?seen|seen[_-]?|dismiss|welcome|tour|intro|visited|new[_-]?user|completed[_-]?setup)/i;
8133
+ var USED_AS_CONDITION_RE = /===|!==|==|!=|\?|&&|\|\||if\s*\(|return\s/;
8134
+ function webStorageReads(content, keyRe) {
8135
+ const out = [];
8136
+ const re = /(?:localStorage|sessionStorage)\s*\.\s*getItem\s*\(\s*["'`]([^"'`]+)["'`]\s*\)/g;
8137
+ for (const m of content.matchAll(re)) {
8138
+ if (m.index === void 0) continue;
8139
+ if (!keyRe.test(m[1])) continue;
8140
+ const lineStart = content.lastIndexOf("\n", m.index) + 1;
8141
+ let lineEnd = content.indexOf("\n", m.index);
8142
+ if (lineEnd === -1) lineEnd = content.length;
8143
+ if (!USED_AS_CONDITION_RE.test(content.slice(lineStart, lineEnd))) continue;
8144
+ out.push({ key: m[1], index: m.index });
8145
+ }
8146
+ return out;
8147
+ }
8148
+ var entitlementFromWebStorage = {
8149
+ id: "VC213",
8150
+ title: "Entitlement or role read from browser storage",
8151
+ severity: "high",
8152
+ category: "Authorization",
8153
+ 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.",
8154
+ check(content, filePath) {
8155
+ if (!/\.(jsx?|tsx?|vue|svelte)$/.test(filePath)) return [];
8156
+ if (isTestFile(filePath)) return [];
8157
+ const hits = webStorageReads(content, ENTITLEMENT_KEY_RE);
8158
+ if (hits.length === 0) return [];
8159
+ const first = hits[0];
8160
+ const line = lineNumberAt(content, first.index);
8161
+ return filterSilenced([{
8162
+ rule: "VC213",
8163
+ title: entitlementFromWebStorage.title,
8164
+ severity: "high",
8165
+ category: "Authorization",
8166
+ file: filePath,
8167
+ line,
8168
+ snippet: getSnippet(content, line),
8169
+ 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.`
8170
+ }], content, "VC213");
8171
+ }
8172
+ };
8173
+ var accountStateFromWebStorage = {
8174
+ id: "VC214",
8175
+ title: "Per-account state decided by browser storage alone",
8176
+ severity: "info",
8177
+ category: "Logic",
8178
+ 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.",
8179
+ check(content, filePath) {
8180
+ if (!/\.(jsx?|tsx?|vue|svelte)$/.test(filePath)) return [];
8181
+ if (isTestFile(filePath)) return [];
8182
+ if (!/isSignedIn|useAuth|useUser|useSession|currentUser|getServerSession|session\?\.|auth\(\)|clerk/i.test(content)) return [];
8183
+ const hits = webStorageReads(content, LIFECYCLE_KEY_RE);
8184
+ if (hits.length === 0) return [];
8185
+ const first = hits[0];
8186
+ const line = lineNumberAt(content, first.index);
8187
+ return filterSilenced([{
8188
+ rule: "VC214",
8189
+ title: accountStateFromWebStorage.title,
8190
+ severity: "info",
8191
+ category: "Logic",
8192
+ file: filePath,
8193
+ line,
8194
+ snippet: getSnippet(content, line),
8195
+ 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.`
8196
+ }], content, "VC214");
8197
+ }
8198
+ };
8113
8199
  var middlewareMatcherExcludesApi = {
8114
8200
  id: "VC210",
8115
8201
  title: "Auth middleware matcher excludes API routes",
@@ -8977,7 +9063,10 @@ var allCustomRules = [
8977
9063
  graphqlCSRFDisabled,
8978
9064
  // VC211–VC212: hardcoded sensitive personal data (PII)
8979
9065
  hardcodedCreditCard,
8980
- hardcodedSSN
9066
+ hardcodedSSN,
9067
+ // VC213–VC214: state that belongs to the account, kept in the browser
9068
+ entitlementFromWebStorage,
9069
+ accountStateFromWebStorage
8981
9070
  ];
8982
9071
  function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
8983
9072
  const findings = [];
@@ -8996,7 +9085,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
8996
9085
  }
8997
9086
  }
8998
9087
  if (maxLineLen > 5e4) return findings;
8999
- if (/onboarding|demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
9088
+ if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
9000
9089
  const vendoredFile = isVendoredPath(filePath);
9001
9090
  const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
9002
9091
  for (const rule of ruleset) {
@@ -9027,6 +9116,11 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
9027
9116
  return findings;
9028
9117
  }
9029
9118
 
9119
+ // src/rule-counts.ts
9120
+ var FREE_RULE_COUNT = 30;
9121
+ var PRO_RULE_COUNT = 184;
9122
+ var TOTAL_RULE_COUNT = 214;
9123
+
9030
9124
  // src/ai-fp-filter.ts
9031
9125
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
9032
9126
  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.
@@ -9407,6 +9501,112 @@ function scanEntropy(files) {
9407
9501
  return findings;
9408
9502
  }
9409
9503
 
9504
+ // src/routes.ts
9505
+ var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
9506
+ var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
9507
+ function hasDep(files, name) {
9508
+ const pkg = files.find(
9509
+ (f) => f.path === "package.json" || f.path.endsWith("/package.json")
9510
+ );
9511
+ if (!pkg) return false;
9512
+ try {
9513
+ const json = JSON.parse(pkg.content);
9514
+ return Boolean({ ...json.dependencies ?? {}, ...json.devDependencies ?? {} }[name]);
9515
+ } catch {
9516
+ return false;
9517
+ }
9518
+ }
9519
+ function normalize(p) {
9520
+ if (!p.startsWith("/")) return "";
9521
+ if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
9522
+ return p;
9523
+ }
9524
+ function extractRoutes(files) {
9525
+ const routes = /* @__PURE__ */ new Map();
9526
+ const frameworks = /* @__PURE__ */ new Set();
9527
+ const add = (raw, framework, source, kindOverride) => {
9528
+ const path = normalize(raw);
9529
+ if (!path || routes.has(path)) return;
9530
+ routes.set(path, {
9531
+ path,
9532
+ // The URL prefix is a fallback, not the authority. A Next `route.ts` is a
9533
+ // handler wherever it lives: /free-trust-page/claim/start/route.ts is an
9534
+ // endpoint, not a page, and calling it a page mislabels what an attacker
9535
+ // would actually hit.
9536
+ kind: kindOverride ?? (API_RE.test(path) ? "api" : "page"),
9537
+ dynamic: DYNAMIC_RE.test(path),
9538
+ framework,
9539
+ source
9540
+ });
9541
+ frameworks.add(framework);
9542
+ };
9543
+ const isNext = hasDep(files, "next");
9544
+ const isExpress = hasDep(files, "express") || hasDep(files, "hono") || hasDep(files, "koa");
9545
+ const isTanstack = hasDep(files, "@tanstack/react-router") || hasDep(files, "@tanstack/react-start");
9546
+ if (isTanstack) {
9547
+ const gen = files.find((f) => f.path.endsWith("routeTree.gen.ts"));
9548
+ if (gen) {
9549
+ for (const m of gen.content.matchAll(/'(\/[A-Za-z0-9_\-/$.]*)'/g)) {
9550
+ if (m[1].split("/").some((seg) => seg.startsWith("_"))) continue;
9551
+ add(m[1], "tanstack-router", gen.path);
9552
+ }
9553
+ }
9554
+ }
9555
+ for (const file of files) {
9556
+ const rel = file.path;
9557
+ if (isNext) {
9558
+ const page = rel.match(/(?:^|\/)app\/(?:(.*)\/)?page\.(tsx?|jsx?)$/);
9559
+ if (page) {
9560
+ const segs = (page[1] ?? "").split("/").filter(Boolean).filter((s) => !/^\(.*\)$/.test(s));
9561
+ add("/" + segs.join("/"), "next-app", rel);
9562
+ }
9563
+ const handler = rel.match(/(?:^|\/)app\/(?:(.*)\/)?route\.(tsx?|jsx?)$/);
9564
+ if (handler) {
9565
+ const segs = (handler[1] ?? "").split("/").filter(Boolean).filter((s) => !/^\(.*\)$/.test(s));
9566
+ add("/" + segs.join("/"), "next-app", rel, "api");
9567
+ }
9568
+ const pages = rel.match(/(?:^|\/)pages\/(.+)\.(tsx?|jsx?)$/);
9569
+ if (pages && !/^_/.test(pages[1].split("/").pop() ?? "")) {
9570
+ const p = "/" + pages[1].replace(/\/index$/, "").replace(/^index$/, "");
9571
+ add(p === "/" ? "/" : p, "next-pages", rel);
9572
+ }
9573
+ }
9574
+ if (!/\.(tsx?|jsx?|mjs|cjs|py)$/.test(rel)) continue;
9575
+ const src = file.content;
9576
+ for (const m of src.matchAll(/<Route\s[^>]*path\s*=\s*["'`]([^"'`]+)["'`]/g)) {
9577
+ add(m[1].startsWith("/") ? m[1] : "/" + m[1], "react-router", rel);
9578
+ }
9579
+ if (/createBrowserRouter|createHashRouter|useRoutes/.test(src)) {
9580
+ for (const m of src.matchAll(/path\s*:\s*["'`]([^"'`]+)["'`]/g)) {
9581
+ add(m[1].startsWith("/") ? m[1] : "/" + m[1], "react-router", rel);
9582
+ }
9583
+ }
9584
+ for (const m of src.matchAll(
9585
+ /@\w+\.(?:route|get|post|put|patch|delete)\(\s*["']([^"']+)["']/g
9586
+ )) {
9587
+ add(m[1], "flask-fastapi", rel);
9588
+ }
9589
+ for (const m of src.matchAll(/add_url_rule\(\s*["']([^"']+)["']/g)) {
9590
+ add(m[1], "flask-fastapi", rel);
9591
+ }
9592
+ if (isExpress) {
9593
+ for (const m of src.matchAll(
9594
+ /\b(?:app|router)\.(?:get|post|put|patch|delete|all)\(\s*["'`]([^"'`]+)["'`]/g
9595
+ )) {
9596
+ add(m[1], "express", rel);
9597
+ }
9598
+ }
9599
+ }
9600
+ return {
9601
+ frameworks: [...frameworks],
9602
+ routes: [...routes.values()].sort((a, b) => a.path.localeCompare(b.path))
9603
+ };
9604
+ }
9605
+ function routeForFile(table, filePath) {
9606
+ const norm = filePath.replace(/^\.\//, "");
9607
+ return table.routes.find((r) => r.source === norm || r.source.endsWith("/" + norm));
9608
+ }
9609
+
9410
9610
  // src/url-recon.ts
9411
9611
  var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
9412
9612
  "localhost",
@@ -9581,8 +9781,12 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9581
9781
  }
9582
9782
  // Annotate the CommonJS export names for ESM import in node:
9583
9783
  0 && (module.exports = {
9784
+ FREE_RULE_COUNT,
9584
9785
  NON_APP_PATH_PATTERNS,
9786
+ PRO_RULE_COUNT,
9585
9787
  RULE_IMPACTS,
9788
+ TOTAL_RULE_COUNT,
9789
+ accountStateFromWebStorage,
9586
9790
  allCustomRules,
9587
9791
  allRules,
9588
9792
  androidDebuggable,
@@ -9620,6 +9824,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9620
9824
  ecbModeEncryption,
9621
9825
  electronNavigationUnrestricted,
9622
9826
  emptyCatchBlock,
9827
+ entitlementFromWebStorage,
9623
9828
  envNotGitignored,
9624
9829
  evalUsage,
9625
9830
  eventListenerLeak,
@@ -9634,6 +9839,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9634
9839
  exposedServerActions,
9635
9840
  exposedSourceMaps,
9636
9841
  exposedStackTraces,
9842
+ extractRoutes,
9637
9843
  extractScriptUrls,
9638
9844
  filterFalsePositives,
9639
9845
  findSourceMapRefs,
@@ -9777,6 +9983,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9777
9983
  rdsPubliclyAccessible,
9778
9984
  reflectedCORSOrigin,
9779
9985
  regexDos,
9986
+ routeForFile,
9780
9987
  runCustomRules,
9781
9988
  s3BucketNoEncryption,
9782
9989
  scanEntropy,