xploitscan-shared-rules 1.26.2 → 1.27.1

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,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ CHECKABLE_CLAIMS: () => CHECKABLE_CLAIMS,
33
34
  FREE_RULE_COUNT: () => FREE_RULE_COUNT,
34
35
  INTENT_EXPECTATIONS: () => INTENT_EXPECTATIONS,
35
36
  MODEL_ANALYSIS: () => MODEL_ANALYSIS,
@@ -54,6 +55,7 @@ __export(index_exports, {
54
55
  callbackHell: () => callbackHell,
55
56
  checkIntent: () => checkIntent,
56
57
  classifyExposure: () => classifyExposure,
58
+ classifyStatement: () => classifyStatement,
57
59
  clickjacking: () => clickjacking,
58
60
  clientComponentSecret: () => clientComponentSecret,
59
61
  clientSideAuth: () => clientSideAuth,
@@ -891,6 +893,15 @@ function harvestIntent(files) {
891
893
  }
892
894
  continue;
893
895
  }
896
+ if (match.origin === "declared") {
897
+ for (const line of file.content.split("\n")) {
898
+ const text = clean(line).trim();
899
+ if (text && !text.startsWith("#")) {
900
+ out.push({ text, source: file.path, line: 1, origin: match.origin });
901
+ }
902
+ }
903
+ continue;
904
+ }
894
905
  let inFence = false;
895
906
  const lines = file.content.split("\n");
896
907
  for (let i = 0; i < lines.length; i++) {
@@ -1048,12 +1059,26 @@ function pathTokens(p) {
1048
1059
  (p.toLowerCase().match(/[a-z][a-z-]{2,}/g) ?? []).filter((t) => !STOPWORDS.has(t))
1049
1060
  );
1050
1061
  }
1062
+ function classifyStatement(text) {
1063
+ if (describesAbsence(text)) return { checkable: false, matched: [] };
1064
+ const matched = INTENT_EXPECTATIONS.filter((e) => e.claims.test(text)).map((e) => e.id);
1065
+ return { checkable: matched.length > 0, matched };
1066
+ }
1067
+ var CHECKABLE_CLAIMS = [
1068
+ { id: "owner-scoped", label: "who can see whose data", example: "Customers can only see their own orders." },
1069
+ { id: "requires-auth", label: "what needs a login", example: "Every API route requires the user to be logged in." },
1070
+ { id: "admin-only", label: "what is admin-only", example: "Only admins can delete a workspace." },
1071
+ { id: "private-data", label: "what is private", example: "Uploaded files are never public." },
1072
+ { id: "verified-webhooks", label: "which webhooks are verified", example: "Stripe webhooks are signature verified." },
1073
+ { id: "rate-limited", label: "what is rate limited", example: "The public API is rate limited." }
1074
+ ];
1051
1075
  function checkIntent(files, findings) {
1052
1076
  const statements = harvestIntent(files);
1053
1077
  const sources = [...new Set(statements.map((s) => s.source))];
1054
1078
  const routes = extractRoutes(files).routes;
1055
1079
  const mismatches = [];
1056
1080
  const unchallenged = [];
1081
+ const uncheckable = [];
1057
1082
  const byRule = /* @__PURE__ */ new Map();
1058
1083
  for (const f of findings) {
1059
1084
  const list = byRule.get(f.rule);
@@ -1065,6 +1090,10 @@ function checkIntent(files, findings) {
1065
1090
  const global = isGlobalClaim(statement.text);
1066
1091
  const subject = topics(statement.text);
1067
1092
  if (describesAbsence(statement.text)) continue;
1093
+ if (!classifyStatement(statement.text).checkable) {
1094
+ uncheckable.push(statement);
1095
+ continue;
1096
+ }
1068
1097
  for (const exp of INTENT_EXPECTATIONS) {
1069
1098
  if (!exp.claims.test(statement.text)) continue;
1070
1099
  const candidates = exp.contradictedBy.flatMap((r) => byRule.get(r) ?? []);
@@ -1109,7 +1138,7 @@ function checkIntent(files, findings) {
1109
1138
  });
1110
1139
  }
1111
1140
  }
1112
- return { statements, mismatches, sources, unchallenged };
1141
+ return { statements, mismatches, sources, unchallenged, uncheckable };
1113
1142
  }
1114
1143
 
1115
1144
  // src/silencing.ts
@@ -2075,6 +2104,7 @@ var missingAuthMiddleware = {
2075
2104
  description: "API routes without authentication checks allow unauthorized access.",
2076
2105
  check(content, filePath, project) {
2077
2106
  if (!isServerSideFile(filePath, content)) return [];
2107
+ if (PUBLIC_BY_CONVENTION_ROUTE.test(routeSegmentName(filePath))) return [];
2078
2108
  const routePatterns = [
2079
2109
  // Express/Hono style
2080
2110
  /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]+["'`]\s*,\s*(?:async\s+)?\(?(?:req|c|ctx)/gi,
@@ -2140,7 +2170,22 @@ var missingAuthMiddleware = {
2140
2170
  /\bjwt\.verify\b/i,
2141
2171
  /\bbearer\s/i,
2142
2172
  /\b(?:protect|guard)\(/i,
2143
- /\.use\([^)]*(?:auth|session|protect|requireAuth)/i
2173
+ /\.use\([^)]*(?:auth|session|protect|requireAuth)/i,
2174
+ // A handler that can answer HTTP 401 is, by definition, deciding whether
2175
+ // the caller is allowed in. This catches the whole family of
2176
+ // capability-token flows the named patterns above miss — magic links,
2177
+ // share links, unsubscribe links, invite/claim URLs — where there is no
2178
+ // session and no account, and the unguessable token in the request IS
2179
+ // the credential, checked by a bespoke lookup like
2180
+ // `findShareByToken(slug, token)`.
2181
+ //
2182
+ // 401 only, deliberately not 403. 401 means "I could not authenticate
2183
+ // you"; 403 is routinely returned by things that never identified the
2184
+ // caller at all — an Origin allowlist on an anonymous analytics beacon,
2185
+ // a feature flag, a geo block. Accepting 403 would suppress genuinely
2186
+ // unauthenticated routes.
2187
+ /\bstatus(?:Code)?\s*[:(]\s*401\b/,
2188
+ /\bsendStatus\s*\(\s*401\b/
2144
2189
  ];
2145
2190
  const APP_LEVEL_AUTH = [
2146
2191
  /\.use\([^)]*(?:auth|session|protect|requireAuth)/i,
@@ -2200,6 +2245,15 @@ var missingAuthMiddleware = {
2200
2245
  return filterSilenced(unauthenticated, content, "VC003");
2201
2246
  }
2202
2247
  };
2248
+ var PUBLIC_BY_CONVENTION_ROUTE = /^(?:og|opengraph-image|twitter-image|icon|apple-icon|favicon|sitemap|robots|manifest|badge)(?:[.-]\w+)?$/i;
2249
+ function routeSegmentName(filePath) {
2250
+ const segments = filePath.split("/");
2251
+ const base = segments[segments.length - 1] ?? "";
2252
+ if (/^route\.(?:ts|tsx|js|jsx|mjs|cjs)$/i.test(base)) {
2253
+ return segments[segments.length - 2] ?? "";
2254
+ }
2255
+ return base.replace(/\.[^.]+$/, "");
2256
+ }
2203
2257
  var supabaseNoRLS = {
2204
2258
  id: "VC004",
2205
2259
  title: "Supabase Client Without Row Level Security",
@@ -2733,10 +2787,10 @@ var insecureCookies = {
2733
2787
  check(content, filePath) {
2734
2788
  if (isTestFile(filePath)) return [];
2735
2789
  if (!/cookie/i.test(content)) return [];
2736
- const setCookiePattern = /(?:set-cookie|setCookie|cookie\s*=|res\.cookie\s*\()/gi;
2790
+ const setCookiePattern = /(?:set-cookie|setCookie|\bcookie\s*=|res\.cookie\s*\()/gi;
2737
2791
  if (!setCookiePattern.test(content)) return [];
2738
2792
  const hasHttpOnly = /httpOnly\s*:\s*true|httponly/i.test(content);
2739
- const hasSecure = /secure\s*:\s*true|;\s*secure/i.test(content);
2793
+ const hasSecure = /secure\s*:\s*(?!false\b)\S/i.test(content) || /;\s*secure/i.test(content);
2740
2794
  const hasSameSite = /sameSite\s*:|samesite/i.test(content);
2741
2795
  const matches = [];
2742
2796
  if (!hasHttpOnly || !hasSecure || !hasSameSite) {
@@ -10253,6 +10307,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
10253
10307
  }
10254
10308
  // Annotate the CommonJS export names for ESM import in node:
10255
10309
  0 && (module.exports = {
10310
+ CHECKABLE_CLAIMS,
10256
10311
  FREE_RULE_COUNT,
10257
10312
  INTENT_EXPECTATIONS,
10258
10313
  MODEL_ANALYSIS,
@@ -10277,6 +10332,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
10277
10332
  callbackHell,
10278
10333
  checkIntent,
10279
10334
  classifyExposure,
10335
+ classifyStatement,
10280
10336
  clickjacking,
10281
10337
  clientComponentSecret,
10282
10338
  clientSideAuth,