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.js CHANGED
@@ -1589,6 +1589,12 @@ function tryParse(content, filePath) {
1589
1589
  parseCacheValid = true;
1590
1590
  return result;
1591
1591
  }
1592
+ function isNamespacedSlotKey(value) {
1593
+ const words = value.split(/[.:/_-]/);
1594
+ if (words[words.length - 1] === "") words.pop();
1595
+ if (words.length < 2) return false;
1596
+ return words.every((w) => /^[a-z]+[0-9]*(?:[A-Z][a-z]+[0-9]*)*$/.test(w));
1597
+ }
1592
1598
  var hardcodedSecrets = {
1593
1599
  id: "VC001",
1594
1600
  title: "Hardcoded API Key or Secret",
@@ -1635,7 +1641,7 @@ var hardcodedSecrets = {
1635
1641
  "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.",
1636
1642
  "OpenAI API key detected \u2014 grants full API access and can incur charges. Rotate at platform.openai.com \u2192 API Keys.",
1637
1643
  "Hardcoded token or password detected. Move to an environment variable and rotate the credential if it has been committed to version control.",
1638
- "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.",
1644
+ "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.",
1639
1645
  "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.",
1640
1646
  "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.",
1641
1647
  "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.",
@@ -1684,7 +1690,7 @@ var hardcodedSecrets = {
1684
1690
  if (valMatch && nameMatch) {
1685
1691
  const value = valMatch[1];
1686
1692
  const isKeySuffix = nameMatch[1].endsWith("_KEY");
1687
- const isSlotIdentifier = value.length < 40 && /^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value);
1693
+ const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(value));
1688
1694
  if (isKeySuffix && isSlotIdentifier) continue;
1689
1695
  }
1690
1696
  }
@@ -2172,7 +2178,7 @@ var xssVulnerability = {
2172
2178
  pattern,
2173
2179
  xssVulnerability,
2174
2180
  filePath,
2175
- () => "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."
2181
+ () => "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."
2176
2182
  );
2177
2183
  for (const m of raw) {
2178
2184
  const lineText = (allLines[m.line - 1] || "").slice(0, 4e3);
@@ -2230,7 +2236,7 @@ var noRateLimiting = {
2230
2236
  check(content, filePath) {
2231
2237
  const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
2232
2238
  if (!isEntryFile) return [];
2233
- const isServer = /(?:express|hono|fastify|koa|next|createServer|listen\()/i.test(content);
2239
+ 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);
2234
2240
  if (!isServer) return [];
2235
2241
  const hasRateLimit = /rate.?limit|throttle|express-rate-limit|@elysiajs\/rate-limit|hono.*limiter/i.test(content);
2236
2242
  if (hasRateLimit) return [];
@@ -2508,6 +2514,20 @@ var exposedAuthSecret = {
2508
2514
  return matches;
2509
2515
  }
2510
2516
  };
2517
+ function cspFixFor(content) {
2518
+ const origins = [
2519
+ ...new Set(
2520
+ [...content.slice(0, 2e5).matchAll(/<script\b[^>]{0,500}?\bsrc\s*=\s*["'](https?:\/\/[^/"'\s>]+)/gi)].map((m) => m[1])
2521
+ )
2522
+ ].slice(0, 10);
2523
+ const inlineScripts = (content.slice(0, 2e5).match(/<script\b(?![^>]{0,500}\bsrc\s*=)[^>]{0,500}>\s*[^<\s]/gi) ?? []).length;
2524
+ const scriptSrc = ["'self'", ...origins].join(" ");
2525
+ return [
2526
+ `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.`,
2527
+ 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.` : "",
2528
+ "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."
2529
+ ].filter(Boolean).join(" ");
2530
+ }
2511
2531
  var missingCSP = {
2512
2532
  id: "VC020",
2513
2533
  title: "Missing Content Security Policy (CSP)",
@@ -2525,7 +2545,7 @@ var missingCSP = {
2525
2545
  file: filePath,
2526
2546
  line: 1,
2527
2547
  snippet: getSnippet(content, 1),
2528
- fix: `Add a CSP meta tag: <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">`
2548
+ fix: cspFixFor(content)
2529
2549
  }];
2530
2550
  }
2531
2551
  }