xploitscan-shared-rules 1.15.1 → 1.16.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
  allCustomRules: () => allCustomRules,
36
36
  allRules: () => allRules,
37
37
  androidDebuggable: () => androidDebuggable,
38
+ assessHeaders: () => assessHeaders,
38
39
  blockingMainThread: () => blockingMainThread,
39
40
  buildTaintMap: () => buildTaintMap,
40
41
  calculateGrade: () => calculateGrade,
@@ -52,6 +53,8 @@ __export(index_exports, {
52
53
  corsWildcard: () => corsWildcard,
53
54
  dangerousInnerHTML: () => dangerousInnerHTML,
54
55
  deprecatedTLS: () => deprecatedTLS,
56
+ detectBuilder: () => detectBuilder,
57
+ detectExposedConfig: () => detectExposedConfig,
55
58
  detectFramework: () => detectFramework,
56
59
  detectPlatform: () => detectPlatform,
57
60
  disabledTLSVerification: () => disabledTLSVerification,
@@ -80,7 +83,9 @@ __export(index_exports, {
80
83
  exposedServerActions: () => exposedServerActions,
81
84
  exposedSourceMaps: () => exposedSourceMaps,
82
85
  exposedStackTraces: () => exposedStackTraces,
86
+ extractScriptUrls: () => extractScriptUrls,
83
87
  filterFalsePositives: () => filterFalsePositives,
88
+ findSourceMapRefs: () => findSourceMapRefs,
84
89
  firebaseClientConfig: () => firebaseClientConfig,
85
90
  flaskSecretKey: () => flaskSecretKey,
86
91
  freeRules: () => freeRules,
@@ -157,6 +162,7 @@ __export(index_exports, {
157
162
  ipcPathTraversal: () => ipcPathTraversal,
158
163
  isCalleeNamed: () => isCalleeNamed,
159
164
  isMethodCall: () => isMethodCall,
165
+ isPrivateAddress: () => isPrivateAddress,
160
166
  isVendoredFinding: () => isVendoredFinding,
161
167
  isVendoredPath: () => isVendoredPath,
162
168
  javaDeserialization: () => javaDeserialization,
@@ -204,6 +210,7 @@ __export(index_exports, {
204
210
  openRedirectParams: () => openRedirectParams,
205
211
  overlyPermissiveIAM: () => overlyPermissiveIAM,
206
212
  parseFile: () => parseFile,
213
+ parseScanTarget: () => parseScanTarget,
207
214
  pathTraversal: () => pathTraversal,
208
215
  pickleDeserialization: () => pickleDeserialization,
209
216
  piiInLogs: () => piiInLogs,
@@ -646,6 +653,26 @@ function vendoredReason(filePath) {
646
653
  return null;
647
654
  }
648
655
 
656
+ // src/silencing.ts
657
+ function isInlineSilenced(content, matchIndex, ruleId) {
658
+ const lines = content.split("\n");
659
+ const matchLineNum = content.substring(0, matchIndex).split("\n").length - 1;
660
+ return isLineSilenced(lines, matchLineNum, ruleId);
661
+ }
662
+ function isLineSilenced(lines, lineIdx, ruleId) {
663
+ const matchLine = lines[lineIdx] ?? "";
664
+ const marker = new RegExp(`(?://|/\\*|#)\\s*(?:${ruleId}|scanner)-OK\\b`, "i");
665
+ if (marker.test(matchLine)) return true;
666
+ const COMMENT_LINE = /^\s*[{(]?\s*(?:\/\/|#|\/\*|\*)/;
667
+ const MAX_BLOCK_LINES = 20;
668
+ for (let i = lineIdx - 1, seen = 0; i >= 0 && seen < MAX_BLOCK_LINES; i--, seen++) {
669
+ const line = lines[i] ?? "";
670
+ if (marker.test(line)) return true;
671
+ if (!COMMENT_LINE.test(line)) break;
672
+ }
673
+ return false;
674
+ }
675
+
649
676
  // src/ast/parse.ts
650
677
  var import_parser = require("@babel/parser");
651
678
  var MAX_CACHE = 256;
@@ -1244,17 +1271,6 @@ function isInsideFixMessage(content, matchIndex) {
1244
1271
  const lineText = content.substring(lineStart, content.indexOf("\n", matchIndex));
1245
1272
  return /(?:fix|description|message|suggestion|hint|help|example|doc|comment)\s*[:=]\s*["'`]/i.test(lineText) || /return\s*["'`].*\b(?:Use|Replace|Add|Move|Set|Enable|Disable|Never|Don't|Do not|Instead)\b/i.test(lineText);
1246
1273
  }
1247
- function isInlineSilenced(content, matchIndex, ruleId) {
1248
- const lines = content.split("\n");
1249
- const matchLineNum = content.substring(0, matchIndex).split("\n").length - 1;
1250
- const matchLine = lines[matchLineNum] ?? "";
1251
- const prevLine = matchLineNum > 0 ? lines[matchLineNum - 1] ?? "" : "";
1252
- const marker = new RegExp(
1253
- `(?://|/\\*|#)\\s*(?:${ruleId}|scanner)-OK\\b`,
1254
- "i"
1255
- );
1256
- return marker.test(matchLine) || marker.test(prevLine);
1257
- }
1258
1274
  function filterSilenced(matches, content, ruleId) {
1259
1275
  if (matches.length === 0) return matches;
1260
1276
  const lines = content.split("\n");
@@ -1513,11 +1529,11 @@ var missingAuthMiddleware = {
1513
1529
  pattern,
1514
1530
  missingAuthMiddleware,
1515
1531
  filePath,
1516
- () => "Add authentication middleware to protect this route. Check the user's session/token before processing the request."
1532
+ () => "Add authentication middleware to protect this route. Check the user's session/token before processing the request. If the endpoint is public by design (an OG image, an embeddable badge, a health check), add an inline `// VC003-OK: <reason>` comment above the handler to silence."
1517
1533
  )
1518
1534
  );
1519
1535
  }
1520
- return matches;
1536
+ return filterSilenced(matches, content, "VC003");
1521
1537
  }
1522
1538
  };
1523
1539
  var supabaseNoRLS = {
@@ -9273,6 +9289,7 @@ function scanEntropy(files) {
9273
9289
  if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
9274
9290
  const isLikelySecret = SECRET_VAR_NAMES.test(varName);
9275
9291
  if (entropy < 4.5 && !isLikelySecret) continue;
9292
+ if (isLineSilenced(lines, i, "ENTROPY")) continue;
9276
9293
  const masked = value.substring(0, 6) + "..." + value.substring(value.length - 4);
9277
9294
  findings.push({
9278
9295
  ...vendored ? { vendored: true } : {},
@@ -9284,7 +9301,7 @@ function scanEntropy(files) {
9284
9301
  file: filePath,
9285
9302
  line: i + 1,
9286
9303
  snippet: getSnippet2(content, i + 1),
9287
- fix: "If this is a secret, move it to an environment variable. If it's not a secret (e.g., hash, encoded data), add it to .xploitscanignore.",
9304
+ fix: "If this is a secret, move it to an environment variable. If it's not a secret (e.g. a hash, encoded data, or a public verification token), add an inline `// ENTROPY-OK: <reason>` comment above the line, or add the file to .xploitscanignore.",
9288
9305
  category: "Secrets",
9289
9306
  source: "custom",
9290
9307
  owasp: "A02:2021",
@@ -9295,6 +9312,179 @@ function scanEntropy(files) {
9295
9312
  }
9296
9313
  return findings;
9297
9314
  }
9315
+
9316
+ // src/url-recon.ts
9317
+ var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
9318
+ "localhost",
9319
+ "127.0.0.1",
9320
+ "0.0.0.0",
9321
+ "::1",
9322
+ "[::1]",
9323
+ "metadata.google.internal",
9324
+ "metadata.goog",
9325
+ "instance-data"
9326
+ ]);
9327
+ var BLOCKED_SUFFIXES = [".local", ".localhost", ".internal", ".home.arpa", ".cluster.local"];
9328
+ function isPrivateAddress(address) {
9329
+ const addr = address.trim().toLowerCase().replace(/^\[|\]$/g, "");
9330
+ const mapped = addr.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
9331
+ if (mapped) return isPrivateAddress(mapped[1]);
9332
+ const v4 = addr.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
9333
+ if (v4) {
9334
+ const [a, b] = [Number(v4[1]), Number(v4[2])];
9335
+ if ([a, Number(v4[2]), Number(v4[3]), Number(v4[4])].some((o) => o > 255)) return true;
9336
+ if (a === 0) return true;
9337
+ if (a === 10) return true;
9338
+ if (a === 127) return true;
9339
+ if (a === 169 && b === 254) return true;
9340
+ if (a === 172 && b >= 16 && b <= 31) return true;
9341
+ if (a === 192 && b === 168) return true;
9342
+ if (a === 100 && b >= 64 && b <= 127) return true;
9343
+ if (a === 192 && b === 0) return true;
9344
+ if (a === 198 && (b === 18 || b === 19)) return true;
9345
+ if (a >= 224) return true;
9346
+ return false;
9347
+ }
9348
+ if (addr === "::" || addr === "::1") return true;
9349
+ if (/^f[cd][0-9a-f]{2}:/.test(addr)) return true;
9350
+ if (/^fe[89ab][0-9a-f]:/.test(addr)) return true;
9351
+ return false;
9352
+ }
9353
+ function parseScanTarget(input) {
9354
+ const raw = (input || "").trim();
9355
+ if (!raw) return { ok: false, reason: "Enter a URL to scan." };
9356
+ if (raw.length > 2048) return { ok: false, reason: "That URL is too long." };
9357
+ const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : `https://${raw}`;
9358
+ let url;
9359
+ try {
9360
+ url = new URL(withScheme);
9361
+ } catch {
9362
+ return { ok: false, reason: "That doesn't look like a valid URL." };
9363
+ }
9364
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
9365
+ return { ok: false, reason: "Only http and https URLs can be scanned." };
9366
+ }
9367
+ if (url.username || url.password) {
9368
+ return { ok: false, reason: "Remove the username and password from the URL." };
9369
+ }
9370
+ if (url.port && url.port !== "80" && url.port !== "443") {
9371
+ return { ok: false, reason: "Only the standard web ports (80 and 443) can be scanned." };
9372
+ }
9373
+ const host = url.hostname.toLowerCase();
9374
+ if (BLOCKED_HOSTNAMES.has(host)) {
9375
+ return { ok: false, reason: "That address is not publicly reachable." };
9376
+ }
9377
+ if (BLOCKED_SUFFIXES.some((s) => host.endsWith(s))) {
9378
+ return { ok: false, reason: "That address is not publicly reachable." };
9379
+ }
9380
+ if (isPrivateAddress(host)) {
9381
+ return { ok: false, reason: "That address is not publicly reachable." };
9382
+ }
9383
+ if (!host.includes(".")) {
9384
+ return { ok: false, reason: "Enter a full domain name." };
9385
+ }
9386
+ return { ok: true, url: url.toString(), hostname: host };
9387
+ }
9388
+ var BUILDER_SIGNATURES = [
9389
+ {
9390
+ id: "lovable",
9391
+ name: "Lovable",
9392
+ patterns: [/lovable-tagger/i, /lovable\.dev/i, /data-lov-id=/i, /gpteng\.co/i]
9393
+ },
9394
+ { id: "v0", name: "v0", patterns: [/v0-user-next/i, /v0\.dev/i, /_next\/static.*v0-/i] },
9395
+ { id: "bolt", name: "Bolt", patterns: [/bolt-vite-react/i, /stackblitz/i, /bolt\.new/i] },
9396
+ { id: "base44", name: "Base44", patterns: [/@base44\/sdk/i, /base44\.app/i, /base44\.com/i] }
9397
+ ];
9398
+ function detectBuilder(haystack) {
9399
+ for (const sig of BUILDER_SIGNATURES) {
9400
+ for (const p of sig.patterns) {
9401
+ const m = haystack.match(p);
9402
+ if (m) return { id: sig.id, name: sig.name, evidence: m[0].slice(0, 120) };
9403
+ }
9404
+ }
9405
+ return null;
9406
+ }
9407
+ function findSourceMapRefs(js, bundleUrl) {
9408
+ const out = [];
9409
+ const re = /[#@]\s*sourceMappingURL\s*=\s*([^\s*'"]+)/g;
9410
+ let m;
9411
+ while ((m = re.exec(js)) !== null) {
9412
+ const ref = m[1].trim();
9413
+ if (!ref || ref.startsWith("data:")) continue;
9414
+ try {
9415
+ out.push(new URL(ref, bundleUrl).toString());
9416
+ } catch {
9417
+ }
9418
+ }
9419
+ return [...new Set(out)];
9420
+ }
9421
+ function detectExposedConfig(js) {
9422
+ const out = [];
9423
+ const supabase = js.match(/https:\/\/([a-z0-9]{16,32})\.supabase\.co/i);
9424
+ if (supabase) {
9425
+ out.push({
9426
+ kind: "supabase",
9427
+ projectRef: supabase[1],
9428
+ detail: "A Supabase project URL is present in the client bundle. This is normal and expected \u2014 but it means row-level security is the only thing standing between a visitor and your data."
9429
+ });
9430
+ }
9431
+ const firebase = js.match(/["']?projectId["']?\s*:\s*["']([a-z0-9-]{4,60})["']/i);
9432
+ if (firebase && /firebase/i.test(js)) {
9433
+ out.push({
9434
+ kind: "firebase",
9435
+ projectRef: firebase[1],
9436
+ detail: "A Firebase project configuration is present in the client bundle. This is normal and expected \u2014 but it means your Firestore/Storage rules are the only access control."
9437
+ });
9438
+ }
9439
+ return out;
9440
+ }
9441
+ function assessHeaders(headers) {
9442
+ const h = {};
9443
+ for (const [k, v] of Object.entries(headers)) h[k.toLowerCase()] = v;
9444
+ const out = [];
9445
+ if (!h["content-security-policy"]) {
9446
+ out.push({
9447
+ header: "Content-Security-Policy",
9448
+ severity: "medium",
9449
+ message: "No CSP. A single injected script has nothing stopping it from loading or exfiltrating."
9450
+ });
9451
+ }
9452
+ if (!h["strict-transport-security"]) {
9453
+ out.push({
9454
+ header: "Strict-Transport-Security",
9455
+ severity: "medium",
9456
+ message: "No HSTS. A first visit over http can be intercepted before the redirect to https."
9457
+ });
9458
+ }
9459
+ if (!h["x-content-type-options"]) {
9460
+ out.push({
9461
+ header: "X-Content-Type-Options",
9462
+ severity: "low",
9463
+ message: "Missing nosniff. Browsers may re-interpret a response as a type you did not intend."
9464
+ });
9465
+ }
9466
+ if (!h["referrer-policy"]) {
9467
+ out.push({
9468
+ header: "Referrer-Policy",
9469
+ severity: "low",
9470
+ message: "No referrer policy. Full URLs \u2014 including any ids in the path \u2014 leak to third parties."
9471
+ });
9472
+ }
9473
+ return out;
9474
+ }
9475
+ function extractScriptUrls(html, pageUrl, limit = 12) {
9476
+ const out = [];
9477
+ const re = /<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["']/gi;
9478
+ let m;
9479
+ while ((m = re.exec(html)) !== null && out.length < limit) {
9480
+ try {
9481
+ const u = new URL(m[1], pageUrl);
9482
+ if (u.protocol === "http:" || u.protocol === "https:") out.push(u.toString());
9483
+ } catch {
9484
+ }
9485
+ }
9486
+ return [...new Set(out)];
9487
+ }
9298
9488
  // Annotate the CommonJS export names for ESM import in node:
9299
9489
  0 && (module.exports = {
9300
9490
  NON_APP_PATH_PATTERNS,
@@ -9302,6 +9492,7 @@ function scanEntropy(files) {
9302
9492
  allCustomRules,
9303
9493
  allRules,
9304
9494
  androidDebuggable,
9495
+ assessHeaders,
9305
9496
  blockingMainThread,
9306
9497
  buildTaintMap,
9307
9498
  calculateGrade,
@@ -9319,6 +9510,8 @@ function scanEntropy(files) {
9319
9510
  corsWildcard,
9320
9511
  dangerousInnerHTML,
9321
9512
  deprecatedTLS,
9513
+ detectBuilder,
9514
+ detectExposedConfig,
9322
9515
  detectFramework,
9323
9516
  detectPlatform,
9324
9517
  disabledTLSVerification,
@@ -9347,7 +9540,9 @@ function scanEntropy(files) {
9347
9540
  exposedServerActions,
9348
9541
  exposedSourceMaps,
9349
9542
  exposedStackTraces,
9543
+ extractScriptUrls,
9350
9544
  filterFalsePositives,
9545
+ findSourceMapRefs,
9351
9546
  firebaseClientConfig,
9352
9547
  flaskSecretKey,
9353
9548
  freeRules,
@@ -9424,6 +9619,7 @@ function scanEntropy(files) {
9424
9619
  ipcPathTraversal,
9425
9620
  isCalleeNamed,
9426
9621
  isMethodCall,
9622
+ isPrivateAddress,
9427
9623
  isVendoredFinding,
9428
9624
  isVendoredPath,
9429
9625
  javaDeserialization,
@@ -9471,6 +9667,7 @@ function scanEntropy(files) {
9471
9667
  openRedirectParams,
9472
9668
  overlyPermissiveIAM,
9473
9669
  parseFile,
9670
+ parseScanTarget,
9474
9671
  pathTraversal,
9475
9672
  pickleDeserialization,
9476
9673
  piiInLogs,