xploitscan-shared-rules 1.18.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
@@ -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
@@ -4344,10 +4350,14 @@ function detectFramework(files) {
4344
4350
  if (frameworks.size === 0) frameworks.add("unknown");
4345
4351
  return [...frameworks];
4346
4352
  }
4353
+ function describesRatherThanUses(lowerPath) {
4354
+ return /(^|\/)(public|static|assets|fixtures|__fixtures__|testdata|test-fixtures)\//.test(lowerPath) || /\.(md|mdx|txt|rst)$/.test(lowerPath);
4355
+ }
4347
4356
  function detectPlatform(files) {
4348
4357
  const platforms = /* @__PURE__ */ new Set();
4349
- for (const { path, content } of files) {
4358
+ for (const { path, content: rawContent } of files) {
4350
4359
  const p = path.toLowerCase();
4360
+ const content = describesRatherThanUses(p) ? "" : rawContent;
4351
4361
  if (/(^|\/)lovable\.config\./.test(p) || /lovable-tagger/i.test(content) || /lovable\.dev/i.test(content)) {
4352
4362
  platforms.add("lovable");
4353
4363
  }
@@ -5314,8 +5324,13 @@ var complianceMap = {
5314
5324
  // VC211–VC212: hardcoded sensitive personal data (PII) in source
5315
5325
  VC211: { owasp: "A02:2021", cwe: "CWE-540" },
5316
5326
  // hardcoded credit card number
5317
- VC212: { owasp: "A02:2021", cwe: "CWE-540" }
5327
+ VC212: { owasp: "A02:2021", cwe: "CWE-540" },
5318
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)
5319
5334
  };
5320
5335
  var consoleLogProduction = {
5321
5336
  id: "VC097",
@@ -8113,6 +8128,74 @@ var webhookMissingIdempotency = {
8113
8128
  }], content, "VC209");
8114
8129
  }
8115
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
+ };
8116
8199
  var middlewareMatcherExcludesApi = {
8117
8200
  id: "VC210",
8118
8201
  title: "Auth middleware matcher excludes API routes",
@@ -8980,7 +9063,10 @@ var allCustomRules = [
8980
9063
  graphqlCSRFDisabled,
8981
9064
  // VC211–VC212: hardcoded sensitive personal data (PII)
8982
9065
  hardcodedCreditCard,
8983
- hardcodedSSN
9066
+ hardcodedSSN,
9067
+ // VC213–VC214: state that belongs to the account, kept in the browser
9068
+ entitlementFromWebStorage,
9069
+ accountStateFromWebStorage
8984
9070
  ];
8985
9071
  function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
8986
9072
  const findings = [];
@@ -8999,7 +9085,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
8999
9085
  }
9000
9086
  }
9001
9087
  if (maxLineLen > 5e4) return findings;
9002
- 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;
9003
9089
  const vendoredFile = isVendoredPath(filePath);
9004
9090
  const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
9005
9091
  for (const rule of ruleset) {
@@ -9032,8 +9118,8 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
9032
9118
 
9033
9119
  // src/rule-counts.ts
9034
9120
  var FREE_RULE_COUNT = 30;
9035
- var PRO_RULE_COUNT = 182;
9036
- var TOTAL_RULE_COUNT = 212;
9121
+ var PRO_RULE_COUNT = 184;
9122
+ var TOTAL_RULE_COUNT = 214;
9037
9123
 
9038
9124
  // src/ai-fp-filter.ts
9039
9125
  var import_sdk = __toESM(require("@anthropic-ai/sdk"), 1);
@@ -9415,6 +9501,112 @@ function scanEntropy(files) {
9415
9501
  return findings;
9416
9502
  }
9417
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
+
9418
9610
  // src/url-recon.ts
9419
9611
  var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
9420
9612
  "localhost",
@@ -9594,6 +9786,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9594
9786
  PRO_RULE_COUNT,
9595
9787
  RULE_IMPACTS,
9596
9788
  TOTAL_RULE_COUNT,
9789
+ accountStateFromWebStorage,
9597
9790
  allCustomRules,
9598
9791
  allRules,
9599
9792
  androidDebuggable,
@@ -9631,6 +9824,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9631
9824
  ecbModeEncryption,
9632
9825
  electronNavigationUnrestricted,
9633
9826
  emptyCatchBlock,
9827
+ entitlementFromWebStorage,
9634
9828
  envNotGitignored,
9635
9829
  evalUsage,
9636
9830
  eventListenerLeak,
@@ -9645,6 +9839,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9645
9839
  exposedServerActions,
9646
9840
  exposedSourceMaps,
9647
9841
  exposedStackTraces,
9842
+ extractRoutes,
9648
9843
  extractScriptUrls,
9649
9844
  filterFalsePositives,
9650
9845
  findSourceMapRefs,
@@ -9788,6 +9983,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
9788
9983
  rdsPubliclyAccessible,
9789
9984
  reflectedCORSOrigin,
9790
9985
  regexDos,
9986
+ routeForFile,
9791
9987
  runCustomRules,
9792
9988
  s3BucketNoEncryption,
9793
9989
  scanEntropy,