xploitscan-shared-rules 2.0.1 → 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 +34 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ For the full API surface, see the TypeScript definitions in `dist/index.d.ts` (s
|
|
|
38
38
|
If you're scanning code, install the CLI instead:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npx xploitscan scan .
|
|
41
|
+
npx xploitscan@latest scan .
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
This package is published as a building block for the official XploitScan surfaces and for advanced users who want to call the detection engine directly from their own tooling.
|
package/dist/index.cjs
CHANGED
|
@@ -1726,12 +1726,16 @@ function tryParse(content, filePath) {
|
|
|
1726
1726
|
parseCacheValid = true;
|
|
1727
1727
|
return result;
|
|
1728
1728
|
}
|
|
1729
|
-
function isNamespacedSlotKey(value) {
|
|
1729
|
+
function isNamespacedSlotKey(name, value) {
|
|
1730
|
+
if (CREDENTIAL_NAME.test(name)) return false;
|
|
1730
1731
|
const words = value.split(/[.:/_-]/);
|
|
1731
1732
|
if (words[words.length - 1] === "") words.pop();
|
|
1732
1733
|
if (words.length < 2) return false;
|
|
1734
|
+
if (words.some((w) => CREDENTIAL_WORD.test(w))) return false;
|
|
1733
1735
|
return words.every((w) => /^[a-z]+[0-9]*(?:[A-Z][a-z]+[0-9]*)*$/.test(w));
|
|
1734
1736
|
}
|
|
1737
|
+
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/;
|
|
1738
|
+
var CREDENTIAL_WORD = /secret|passw|token|private|signing|apikey|credential/i;
|
|
1735
1739
|
var hardcodedSecrets = {
|
|
1736
1740
|
id: "VC001",
|
|
1737
1741
|
title: "Hardcoded API Key or Secret",
|
|
@@ -1827,7 +1831,7 @@ var hardcodedSecrets = {
|
|
|
1827
1831
|
if (valMatch && nameMatch) {
|
|
1828
1832
|
const value = valMatch[1];
|
|
1829
1833
|
const isKeySuffix = nameMatch[1].endsWith("_KEY");
|
|
1830
|
-
const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(value));
|
|
1834
|
+
const isSlotIdentifier = value.length < 40 && (/^[a-z0-9]+([_-][a-z0-9]+)+$/.test(value) || isNamespacedSlotKey(nameMatch[1], value));
|
|
1831
1835
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
1832
1836
|
}
|
|
1833
1837
|
}
|
|
@@ -2373,7 +2377,8 @@ var noRateLimiting = {
|
|
|
2373
2377
|
check(content, filePath) {
|
|
2374
2378
|
const isEntryFile = /(?:server|app|index|main)\.[jt]sx?$/.test(filePath) || filePath.includes("middleware");
|
|
2375
2379
|
if (!isEntryFile) return [];
|
|
2376
|
-
const isServer = /(?:from\s+|require\s*\(\s*)["'`](?:express|hono|fastify|koa|@hono\/[\w-]+|next
|
|
2380
|
+
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.
|
|
2381
|
+
/\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);
|
|
2377
2382
|
if (!isServer) return [];
|
|
2378
2383
|
const hasRateLimit = /rate.?limit|throttle|express-rate-limit|@elysiajs\/rate-limit|hono.*limiter/i.test(content);
|
|
2379
2384
|
if (hasRateLimit) return [];
|
|
@@ -2652,12 +2657,32 @@ var exposedAuthSecret = {
|
|
|
2652
2657
|
}
|
|
2653
2658
|
};
|
|
2654
2659
|
function cspFixFor(content) {
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
)
|
|
2659
|
-
|
|
2660
|
-
|
|
2660
|
+
const html = content.slice(0, 2e5);
|
|
2661
|
+
const origins = /* @__PURE__ */ new Set();
|
|
2662
|
+
const addOrigin = (url) => {
|
|
2663
|
+
const m2 = url.match(/^(https?:)?\/\/([^/"'`\s>?#]+)/i);
|
|
2664
|
+
if (m2 && origins.size < 10) origins.add(`${(m2[1] ?? "https:").toLowerCase()}//${m2[2].toLowerCase()}`);
|
|
2665
|
+
};
|
|
2666
|
+
let inlineScripts = 0;
|
|
2667
|
+
const openTag = /<script\b([^>]{0,500})>/gi;
|
|
2668
|
+
let m;
|
|
2669
|
+
for (let seen = 0; (m = openTag.exec(html)) && seen < 100; seen++) {
|
|
2670
|
+
const attrs = m[1];
|
|
2671
|
+
const src = attrs.match(/\bsrc\s*=\s*["']?((?:https?:)?\/\/[^"'\s>]+)/i);
|
|
2672
|
+
if (src) {
|
|
2673
|
+
addOrigin(src[1]);
|
|
2674
|
+
continue;
|
|
2675
|
+
}
|
|
2676
|
+
if (/\bsrc\s*=/i.test(attrs)) continue;
|
|
2677
|
+
const close = html.indexOf("</script", openTag.lastIndex);
|
|
2678
|
+
const body = html.slice(openTag.lastIndex, close < 0 ? openTag.lastIndex + 5e4 : close);
|
|
2679
|
+
const type = (attrs.match(/\btype\s*=\s*["']?([^"'\s>]+)/i)?.[1] ?? "").toLowerCase();
|
|
2680
|
+
const runs = type === "" || type === "module" || type === "importmap" || /^(?:text|application)\/(?:x-)?(?:java|ecma)script$/.test(type);
|
|
2681
|
+
if (!runs || !body.trim()) continue;
|
|
2682
|
+
inlineScripts++;
|
|
2683
|
+
const urls = type === "importmap" ? body.matchAll(/["']((?:https?:)?\/\/[^"'\s]+)["']/g) : type === "module" ? body.matchAll(/(?:\bfrom|\bimport\s*\(?)\s*["'`]((?:https?:)?\/\/[^"'`\s]+)["'`]/g) : [];
|
|
2684
|
+
for (const u of urls) addOrigin(u[1]);
|
|
2685
|
+
}
|
|
2661
2686
|
const scriptSrc = ["'self'", ...origins].join(" ");
|
|
2662
2687
|
return [
|
|
2663
2688
|
`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.`,
|