xploitscan-shared-rules 2.0.0 → 2.0.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
@@ -1726,6 +1726,12 @@ function tryParse(content, filePath) {
1726
1726
  parseCacheValid = true;
1727
1727
  return result;
1728
1728
  }
1729
+ function isNamespacedSlotKey(value) {
1730
+ const words = value.split(/[.:/_-]/);
1731
+ if (words[words.length - 1] === "") words.pop();
1732
+ if (words.length < 2) return false;
1733
+ return words.every((w) => /^[a-z]+[0-9]*(?:[A-Z][a-z]+[0-9]*)*$/.test(w));
1734
+ }
1729
1735
  var hardcodedSecrets = {
1730
1736
  id: "VC001",
1731
1737
  title: "Hardcoded API Key or Secret",
@@ -1772,7 +1778,7 @@ var hardcodedSecrets = {
1772
1778
  "Supabase key detected. Service role keys bypass Row Level Security and grant full database read/write access. Move to a server-side environment variable immediately.",
1773
1779
  "OpenAI API key detected \u2014 grants full API access and can incur charges. Rotate at platform.openai.com \u2192 API Keys.",
1774
1780
  "Hardcoded token or password detected. Move to an environment variable and rotate the credential if it has been committed to version control.",
1775
- "Named secret constant detected (XXX_SECRET / XXX_TOKEN / XXX_KEY). Move to an environment variable: `const NAME = process.env.NAME;`. Rotate the credential if this file has been committed to version control.",
1781
+ "Named secret constant detected (XXX_SECRET / XXX_TOKEN / XXX_KEY). If it's a real credential, move it to server-side configuration \u2014 an environment variable read by server code (`process.env.NAME` in Node) \u2014 and rotate it if this file has been committed. Code that runs in the browser can't keep a secret: everything it loads is public, and `process` doesn't exist there without a bundler, so a browser-side credential has to move behind your own server. If the value is an identifier rather than a credential (a storage key, a cookie or cache name), there is nothing to rotate.",
1776
1782
  "Credential assigned to a config object property. Move to an environment variable \u2014 `apiKey: process.env.API_KEY` \u2014 and rotate the value if this file has been committed.",
1777
1783
  "Hardcoded password detected in a config object. Move to an environment variable (`password: process.env.DB_PASSWORD`) and rotate the password if this file has been committed.",
1778
1784
  "Private key found in source code. If this has been committed to version control, consider the key compromised \u2014 generate a new key pair and revoke the old one.",
@@ -1821,7 +1827,7 @@ var hardcodedSecrets = {
1821
1827
  if (valMatch && nameMatch) {
1822
1828
  const value = valMatch[1];
1823
1829
  const isKeySuffix = nameMatch[1].endsWith("_KEY");
1824
- const isSlotIdentifier = value.length < 40 && /^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value);
1830
+ const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(value));
1825
1831
  if (isKeySuffix && isSlotIdentifier) continue;
1826
1832
  }
1827
1833
  }
@@ -2309,7 +2315,7 @@ var xssVulnerability = {
2309
2315
  pattern,
2310
2316
  xssVulnerability,
2311
2317
  filePath,
2312
- () => "Sanitize user input before rendering as HTML. Use a library like DOMPurify: DOMPurify.sanitize(userInput). If this site is intentional (JSON-LD structured data, a const boot script, a sandboxed preview), add an inline `// VC007-OK: <reason>` comment above the line to silence."
2318
+ () => "Sanitize user input before rendering as HTML. Use a library like DOMPurify: DOMPurify.sanitize(userInput). If this site is intentional (JSON-LD structured data, a const boot script, a sandboxed preview, markup built only from constants and numbers), add an inline `// VC007-OK: <reason>` comment above the line to silence."
2313
2319
  );
2314
2320
  for (const m of raw) {
2315
2321
  const lineText = (allLines[m.line - 1] || "").slice(0, 4e3);
@@ -2367,7 +2373,7 @@ var noRateLimiting = {
2367
2373
  check(content, filePath) {
2368
2374
  const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
2369
2375
  if (!isEntryFile) return [];
2370
- const isServer = /(?:express|hono|fastify|koa|next|createServer|listen\()/i.test(content);
2376
+ const isServer = /(?:from\s+|require\s*\(\s*)["'`](?:express|hono|fastify|koa|@hono\/[\w-]+|next\/server|(?:node:)?https?)["'`]/.test(content) || /\b(?:express|fastify|createServer)\s*\(/.test(content) || /\bnew\s+(?:Hono|Koa)\s*\(/.test(content) || /\b(?:Deno|Bun)\.serve\s*\(/.test(content) || /\.listen\s*\(/.test(content);
2371
2377
  if (!isServer) return [];
2372
2378
  const hasRateLimit = /rate.?limit|throttle|express-rate-limit|@elysiajs\/rate-limit|hono.*limiter/i.test(content);
2373
2379
  if (hasRateLimit) return [];
@@ -2645,6 +2651,20 @@ var exposedAuthSecret = {
2645
2651
  return matches;
2646
2652
  }
2647
2653
  };
2654
+ function cspFixFor(content) {
2655
+ const origins = [
2656
+ ...new Set(
2657
+ [...content.slice(0, 2e5).matchAll(/<script\b[^>]{0,500}?\bsrc\s*=\s*["'](https?:\/\/[^/"'\s>]+)/gi)].map((m) => m[1])
2658
+ )
2659
+ ].slice(0, 10);
2660
+ const inlineScripts = (content.slice(0, 2e5).match(/<script\b(?![^>]{0,500}\bsrc\s*=)[^>]{0,500}>\s*[^<\s]/gi) ?? []).length;
2661
+ const scriptSrc = ["'self'", ...origins].join(" ");
2662
+ return [
2663
+ `Add a Content-Security-Policy. A starting point for this page: \`default-src 'self'; script-src ${scriptSrc}\`, plus any other origins it fetches from, frames or loads styles, fonts and images from.`,
2664
+ inlineScripts > 0 ? `This page has ${inlineScripts} inline <script> block${inlineScripts === 1 ? "" : "s"} (an import map counts), which that policy blocks: add each one's 'sha256-\u2026' hash to script-src, or move the code into a file.` : "",
2665
+ "Prefer sending it as an HTTP response header from your host; a <meta http-equiv> tag also works, but ignores frame-ancestors. Test it before shipping \u2014 a policy that's too strict stops the page from loading. As a header, Content-Security-Policy-Report-Only lets you see what it would block first."
2666
+ ].filter(Boolean).join(" ");
2667
+ }
2648
2668
  var missingCSP = {
2649
2669
  id: "VC020",
2650
2670
  title: "Missing Content Security Policy (CSP)",
@@ -2662,7 +2682,7 @@ var missingCSP = {
2662
2682
  file: filePath,
2663
2683
  line: 1,
2664
2684
  snippet: getSnippet(content, 1),
2665
- fix: `Add a CSP meta tag: <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">`
2685
+ fix: cspFixFor(content)
2666
2686
  }];
2667
2687
  }
2668
2688
  }