xploitscan-shared-rules 2.0.0 → 2.0.2
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/README.md +1 -1
- package/dist/index.cjs +50 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1589,6 +1589,16 @@ function tryParse(content, filePath) {
|
|
|
1589
1589
|
parseCacheValid = true;
|
|
1590
1590
|
return result;
|
|
1591
1591
|
}
|
|
1592
|
+
function isNamespacedSlotKey(name, value) {
|
|
1593
|
+
if (CREDENTIAL_NAME.test(name)) return false;
|
|
1594
|
+
const words = value.split(/[.:/_-]/);
|
|
1595
|
+
if (words[words.length - 1] === "") words.pop();
|
|
1596
|
+
if (words.length < 2) return false;
|
|
1597
|
+
if (words.some((w) => CREDENTIAL_WORD.test(w))) return false;
|
|
1598
|
+
return words.every((w) => /^[a-z]+[0-9]*(?:[A-Z][a-z]+[0-9]*)*$/.test(w));
|
|
1599
|
+
}
|
|
1600
|
+
var CREDENTIAL_NAME = /SECRET|SIGN|ENCRYPT|CRYPT|CIPHER|HMAC|JWT|PRIVATE|API|ACCESS|AUTH|MASTER|ADMIN|SESSION|PASS|TOKEN|CLIENT|SALT|PEPPER|LICEN[CS]E|WEBHOOK|STRIPE|AWS|SERVICE/;
|
|
1601
|
+
var CREDENTIAL_WORD = /secret|passw|token|private|signing|apikey|credential/i;
|
|
1592
1602
|
var hardcodedSecrets = {
|
|
1593
1603
|
id: "VC001",
|
|
1594
1604
|
title: "Hardcoded API Key or Secret",
|
|
@@ -1635,7 +1645,7 @@ var hardcodedSecrets = {
|
|
|
1635
1645
|
"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
1646
|
"OpenAI API key detected \u2014 grants full API access and can incur charges. Rotate at platform.openai.com \u2192 API Keys.",
|
|
1637
1647
|
"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).
|
|
1648
|
+
"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
1649
|
"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
1650
|
"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
1651
|
"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 +1694,7 @@ var hardcodedSecrets = {
|
|
|
1684
1694
|
if (valMatch && nameMatch) {
|
|
1685
1695
|
const value = valMatch[1];
|
|
1686
1696
|
const isKeySuffix = nameMatch[1].endsWith("_KEY");
|
|
1687
|
-
const isSlotIdentifier = value.length < 40 && /^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value);
|
|
1697
|
+
const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[1], value));
|
|
1688
1698
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
1689
1699
|
}
|
|
1690
1700
|
}
|
|
@@ -2172,7 +2182,7 @@ var xssVulnerability = {
|
|
|
2172
2182
|
pattern,
|
|
2173
2183
|
xssVulnerability,
|
|
2174
2184
|
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."
|
|
2185
|
+
() => "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
2186
|
);
|
|
2177
2187
|
for (const m of raw) {
|
|
2178
2188
|
const lineText = (allLines[m.line - 1] || "").slice(0, 4e3);
|
|
@@ -2230,7 +2240,8 @@ var noRateLimiting = {
|
|
|
2230
2240
|
check(content, filePath) {
|
|
2231
2241
|
const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
|
|
2232
2242
|
if (!isEntryFile) return [];
|
|
2233
|
-
const isServer = /(?:express|hono|fastify|koa|next
|
|
2243
|
+
const isServer = /(?:from\s+|require\s*\(\s*)["'`](?:express|hono|fastify|koa|koa-router|@koa\/[\w-]+|@hono\/[\w-]+|next(?:\/server)?|next-auth(?:\/[\w-]+)?|@clerk\/nextjs(?:\/server)?)["'`]/.test(content) || // Case-sensitive framework types — `adNext` and `nextLap` can't match.
|
|
2244
|
+
/\b(?:NextApiRequest|NextApiResponse|NextRequest|NextResponse)\b/.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
2245
|
if (!isServer) return [];
|
|
2235
2246
|
const hasRateLimit = /rate.?limit|throttle|express-rate-limit|@elysiajs\/rate-limit|hono.*limiter/i.test(content);
|
|
2236
2247
|
if (hasRateLimit) return [];
|
|
@@ -2508,6 +2519,40 @@ var exposedAuthSecret = {
|
|
|
2508
2519
|
return matches;
|
|
2509
2520
|
}
|
|
2510
2521
|
};
|
|
2522
|
+
function cspFixFor(content) {
|
|
2523
|
+
const html = content.slice(0, 2e5);
|
|
2524
|
+
const origins = /* @__PURE__ */ new Set();
|
|
2525
|
+
const addOrigin = (url) => {
|
|
2526
|
+
const m2 = url.match(/^(https?:)?\/\/([^/"'`\s>?#]+)/i);
|
|
2527
|
+
if (m2 && origins.size < 10) origins.add(`${(m2[1] ?? "https:").toLowerCase()}//${m2[2].toLowerCase()}`);
|
|
2528
|
+
};
|
|
2529
|
+
let inlineScripts = 0;
|
|
2530
|
+
const openTag = /<script\b([^>]{0,500})>/gi;
|
|
2531
|
+
let m;
|
|
2532
|
+
for (let seen = 0; (m = openTag.exec(html)) && seen < 100; seen++) {
|
|
2533
|
+
const attrs = m[1];
|
|
2534
|
+
const src = attrs.match(/\bsrc\s*=\s*["']?((?:https?:)?\/\/[^"'\s>]+)/i);
|
|
2535
|
+
if (src) {
|
|
2536
|
+
addOrigin(src[1]);
|
|
2537
|
+
continue;
|
|
2538
|
+
}
|
|
2539
|
+
if (/\bsrc\s*=/i.test(attrs)) continue;
|
|
2540
|
+
const close = html.indexOf("</script", openTag.lastIndex);
|
|
2541
|
+
const body = html.slice(openTag.lastIndex, close < 0 ? openTag.lastIndex + 5e4 : close);
|
|
2542
|
+
const type = (attrs.match(/\btype\s*=\s*["']?([^"'\s>]+)/i)?.[1] ?? "").toLowerCase();
|
|
2543
|
+
const runs = type === "" || type === "module" || type === "importmap" || /^(?:text|application)\/(?:x-)?(?:java|ecma)script$/.test(type);
|
|
2544
|
+
if (!runs || !body.trim()) continue;
|
|
2545
|
+
inlineScripts++;
|
|
2546
|
+
const urls = type === "importmap" ? body.matchAll(/["']((?:https?:)?\/\/[^"'\s]+)["']/g) : type === "module" ? body.matchAll(/(?:\bfrom|\bimport\s*\(?)\s*["'`]((?:https?:)?\/\/[^"'`\s]+)["'`]/g) : [];
|
|
2547
|
+
for (const u of urls) addOrigin(u[1]);
|
|
2548
|
+
}
|
|
2549
|
+
const scriptSrc = ["'self'", ...origins].join(" ");
|
|
2550
|
+
return [
|
|
2551
|
+
`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.`,
|
|
2552
|
+
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.` : "",
|
|
2553
|
+
"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."
|
|
2554
|
+
].filter(Boolean).join(" ");
|
|
2555
|
+
}
|
|
2511
2556
|
var missingCSP = {
|
|
2512
2557
|
id: "VC020",
|
|
2513
2558
|
title: "Missing Content Security Policy (CSP)",
|
|
@@ -2525,7 +2570,7 @@ var missingCSP = {
|
|
|
2525
2570
|
file: filePath,
|
|
2526
2571
|
line: 1,
|
|
2527
2572
|
snippet: getSnippet(content, 1),
|
|
2528
|
-
fix:
|
|
2573
|
+
fix: cspFixFor(content)
|
|
2529
2574
|
}];
|
|
2530
2575
|
}
|
|
2531
2576
|
}
|