xploitscan-shared-rules 1.13.1 → 1.14.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/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Shared XploitScan rule definitions, helpers, compliance mappings, the AI false-positive filter, and the entropy-based secret scanner.
4
4
 
5
- This package is the source of truth for XploitScan's detection logic. It's consumed by the [XploitScan CLI](https://www.npmjs.com/package/xploitscan), the [XploitScan MCP server](https://www.npmjs.com/package/xploitscan-mcp), the web scan API at [xploitscan.com](https://xploitscan.com), and the [XploitScan GitHub Action](https://github.com/marketplace/actions/xploitscan-security-scanner) — so detection behavior can't drift between surfaces.
5
+ This package is the source of truth for XploitScan's detection logic. It's consumed by the [XploitScan CLI](https://www.npmjs.com/package/xploitscan), the [XploitScan MCP server](https://www.npmjs.com/package/xploitscan-mcp), the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=XploitScan.xploitscan-vscode), the web scan API at [xploitscan.com](https://xploitscan.com), and the [XploitScan GitHub Action](https://github.com/marketplace/actions/xploitscan-security-scanner) — so detection behavior can't drift between surfaces.
6
6
 
7
7
  ## What's in here
8
8
 
9
- - **210 security rules** — pattern + AST-based detection for hardcoded secrets, SQL injection, XSS, SSRF, prototype pollution, crypto misuse, deserialization, JWT alg confusion, and more.
9
+ - **210+ security rules** — pattern + AST-based detection for hardcoded secrets, SQL injection, XSS, SSRF, prototype pollution, crypto misuse, deserialization, JWT alg confusion, and more.
10
10
  - **Compliance mappings** — each rule tagged with the SOC2, ISO 27001, and OWASP Top 10 controls it covers.
11
11
  - **AI false-positive filter** — optional Claude Haiku integration that re-evaluates findings to suppress benign matches before reporting.
12
12
  - **Entropy-based secret scanner** — detects high-entropy strings that look like credentials but don't match a known service-key pattern.
package/dist/index.cjs CHANGED
@@ -52,6 +52,7 @@ __export(index_exports, {
52
52
  dangerousInnerHTML: () => dangerousInnerHTML,
53
53
  deprecatedTLS: () => deprecatedTLS,
54
54
  detectFramework: () => detectFramework,
55
+ detectPlatform: () => detectPlatform,
55
56
  disabledTLSVerification: () => disabledTLSVerification,
56
57
  djangoDebug: () => djangoDebug,
57
58
  dockerCopySensitive: () => dockerCopySensitive,
@@ -97,6 +98,7 @@ __export(index_exports, {
97
98
  hardcodedAnthropicKey: () => hardcodedAnthropicKey,
98
99
  hardcodedCloudflareToken: () => hardcodedCloudflareToken,
99
100
  hardcodedCohereKey: () => hardcodedCohereKey,
101
+ hardcodedCreditCard: () => hardcodedCreditCard,
100
102
  hardcodedDatadogKey: () => hardcodedDatadogKey,
101
103
  hardcodedDiscordToken: () => hardcodedDiscordToken,
102
104
  hardcodedEncryptionKey: () => hardcodedEncryptionKey,
@@ -126,6 +128,7 @@ __export(index_exports, {
126
128
  hardcodedRailwayToken: () => hardcodedRailwayToken,
127
129
  hardcodedReplicateKey: () => hardcodedReplicateKey,
128
130
  hardcodedResendKey: () => hardcodedResendKey,
131
+ hardcodedSSN: () => hardcodedSSN,
129
132
  hardcodedSecrets: () => hardcodedSecrets,
130
133
  hardcodedSendGridKey: () => hardcodedSendGridKey,
131
134
  hardcodedSentryAuthToken: () => hardcodedSentryAuthToken,
@@ -521,7 +524,9 @@ var RULE_IMPACTS = {
521
524
  VC207: "Model output is attacker-influenceable via prompt injection. Feeding it into eval, new Function, a shell command, a raw SQL string, or a filesystem path turns a crafted or hallucinated response into remote code execution, command injection, SQL injection, or path traversal \u2014 your most dangerous sinks, driven by untrusted text.",
522
525
  VC208: "Interpolating a secret into a prompt ships your API key, token, or password to a third-party model provider, where it persists in their request logs and training-eligible data. A credential that leaves your infrastructure in prompt text should be considered compromised and rotated.",
523
526
  VC209: "Webhooks are delivered at-least-once. Without de-duplicating on the event id, a retried or replayed delivery re-runs the side effect \u2014 a customer is charged twice, a record is duplicated, or an entitlement is granted again. Stripe and Svix both retry on any non-2xx, so this fires in normal operation, not just under attack.",
524
- VC210: "If your auth middleware skips /api, those routes run with no gate unless each one re-checks auth itself. It is the most common way a Next.js app ends up with publicly callable API routes that everyone assumed the middleware was protecting."
527
+ VC210: "If your auth middleware skips /api, those routes run with no gate unless each one re-checks auth itself. It is the most common way a Next.js app ends up with publicly callable API routes that everyone assumed the middleware was protecting.",
528
+ VC211: "A real credit card number in source is cardholder data sitting in git history, CI logs, and every backup \u2014 a direct PCI-DSS violation. Anyone with repo access can read it, and it cannot be un-leaked once committed; the card must be treated as compromised.",
529
+ VC212: "A hardcoded Social Security Number is regulated PII permanently embedded in your git history and backups. It exposes a real person to identity theft, and its presence in source can trigger breach-notification and privacy-law obligations the moment the repo is accessed."
525
530
  };
526
531
 
527
532
  // src/exposure.ts
@@ -4130,6 +4135,31 @@ function detectFramework(files) {
4130
4135
  if (frameworks.size === 0) frameworks.add("unknown");
4131
4136
  return [...frameworks];
4132
4137
  }
4138
+ function detectPlatform(files) {
4139
+ const platforms = /* @__PURE__ */ new Set();
4140
+ for (const { path, content } of files) {
4141
+ const p = path.toLowerCase();
4142
+ if (/(^|\/)lovable\.config\./.test(p) || /lovable-tagger/i.test(content) || /lovable\.dev/i.test(content)) {
4143
+ platforms.add("lovable");
4144
+ }
4145
+ if (/(^|\/)\.bolt\//.test(p) || /(^|\/)\.stackblitzrc$/.test(p) || /bolt\.new/i.test(content)) {
4146
+ platforms.add("bolt");
4147
+ }
4148
+ if (/(^|\/)\.replit$/.test(p) || /(^|\/)replit\.nix$/.test(p)) {
4149
+ platforms.add("replit");
4150
+ }
4151
+ if (/(^|\/)\.cursorrules$/.test(p) || /(^|\/)\.cursor\//.test(p)) {
4152
+ platforms.add("cursor");
4153
+ }
4154
+ if (/(^|\/)claude\.md$/.test(p) || /(^|\/)\.claude\//.test(p)) {
4155
+ platforms.add("claude-code");
4156
+ }
4157
+ if (/v0\.dev/i.test(content) || /generated by v0\b/i.test(content)) {
4158
+ platforms.add("v0");
4159
+ }
4160
+ }
4161
+ return [...platforms];
4162
+ }
4133
4163
  function calculateGrade(findings, _totalFiles) {
4134
4164
  if (findings.length === 0) {
4135
4165
  return { grade: "A+", score: 100, summary: "No security issues detected. Excellent." };
@@ -5062,8 +5092,13 @@ var complianceMap = {
5062
5092
  // VC209–VC210: advisory heuristics
5063
5093
  VC209: { owasp: "A04:2021", cwe: "CWE-799" },
5064
5094
  // webhook missing idempotency
5065
- VC210: { owasp: "A01:2021", cwe: "CWE-862" }
5095
+ VC210: { owasp: "A01:2021", cwe: "CWE-862" },
5066
5096
  // middleware matcher excludes /api
5097
+ // VC211–VC212: hardcoded sensitive personal data (PII) in source
5098
+ VC211: { owasp: "A02:2021", cwe: "CWE-540" },
5099
+ // hardcoded credit card number
5100
+ VC212: { owasp: "A02:2021", cwe: "CWE-540" }
5101
+ // hardcoded US SSN
5067
5102
  };
5068
5103
  var consoleLogProduction = {
5069
5104
  id: "VC097",
@@ -7888,6 +7923,113 @@ var middlewareMatcherExcludesApi = {
7888
7923
  }], content, "VC210");
7889
7924
  }
7890
7925
  };
7926
+ function passesLuhn(digits) {
7927
+ let sum = 0;
7928
+ let alt = false;
7929
+ for (let i = digits.length - 1; i >= 0; i--) {
7930
+ let d = digits.charCodeAt(i) - 48;
7931
+ if (d < 0 || d > 9) return false;
7932
+ if (alt) {
7933
+ d *= 2;
7934
+ if (d > 9) d -= 9;
7935
+ }
7936
+ sum += d;
7937
+ alt = !alt;
7938
+ }
7939
+ return sum % 10 === 0;
7940
+ }
7941
+ function looksLikeIssuerCard(d) {
7942
+ if (/^4/.test(d) && (d.length === 13 || d.length === 16 || d.length === 19)) return true;
7943
+ if (/^5[1-5]/.test(d) && d.length === 16) return true;
7944
+ if (/^2(2[2-9]|[3-6]\d|7[01]|720)/.test(d) && d.length === 16) return true;
7945
+ if (/^3[47]/.test(d) && d.length === 15) return true;
7946
+ if (/^(6011|65|64[4-9])/.test(d) && d.length === 16) return true;
7947
+ return false;
7948
+ }
7949
+ var TEST_CARD_NUMBERS = /* @__PURE__ */ new Set([
7950
+ "4242424242424242",
7951
+ "4111111111111111",
7952
+ "4012888888881881",
7953
+ "4000056655665556",
7954
+ "4000000000000002",
7955
+ "4000000000009995",
7956
+ "5555555555554444",
7957
+ "5200828282828210",
7958
+ "5105105105105100",
7959
+ "2223003122003222",
7960
+ "378282246310005",
7961
+ "371449635398431",
7962
+ "6011111111111117",
7963
+ "6011000990139424",
7964
+ "3056930009020004",
7965
+ "38520000023237"
7966
+ ]);
7967
+ var hardcodedCreditCard = {
7968
+ id: "VC211",
7969
+ title: "Hardcoded credit card number",
7970
+ severity: "high",
7971
+ category: "Information Leakage",
7972
+ description: "A literal credit card number (Luhn-valid, with a real issuer prefix, and not a known network test card) appears in source. Cardholder data does not belong in code \u2014 it lands in git history, logs, and backups, and is a PCI-DSS violation. Use your processor's published test cards for tests, and tokenize real cards.",
7973
+ check(content, filePath) {
7974
+ if (isTestFile(filePath)) return [];
7975
+ const findings = [];
7976
+ const pattern = /(?<![\d.])\d[\d -]{11,21}\d(?![\d.])/g;
7977
+ let m;
7978
+ while ((m = pattern.exec(content)) !== null) {
7979
+ const digits = m[0].replace(/[ -]/g, "");
7980
+ if (digits.length < 13 || digits.length > 19) continue;
7981
+ if (TEST_CARD_NUMBERS.has(digits)) continue;
7982
+ if (!looksLikeIssuerCard(digits)) continue;
7983
+ if (!passesLuhn(digits)) continue;
7984
+ if (isCommentLine(content, m.index)) continue;
7985
+ const lineNum = lineNumberAt(content, m.index);
7986
+ findings.push({
7987
+ rule: "VC211",
7988
+ title: hardcodedCreditCard.title,
7989
+ severity: "high",
7990
+ category: "Information Leakage",
7991
+ file: filePath,
7992
+ line: lineNum,
7993
+ snippet: getSnippet(content, lineNum),
7994
+ fix: "Never store a real card number in source. Tokenize through your payment processor (Stripe, Braintree) and keep only the returned token. For tests, use the processor's published test cards (e.g. Stripe's 4242 4242 4242 4242)."
7995
+ });
7996
+ }
7997
+ return findings;
7998
+ }
7999
+ };
8000
+ var hardcodedSSN = {
8001
+ id: "VC212",
8002
+ title: "Hardcoded US Social Security Number",
8003
+ severity: "high",
8004
+ category: "Information Leakage",
8005
+ description: "A value in SSN format (NNN-NN-NNNN) is assigned to an SSN-named field in source. Social Security Numbers are regulated PII; a literal one leaks into git history, logs, and backups. Store SSNs encrypted at rest and load test data from generated fakes, never a code literal.",
8006
+ check(content, filePath) {
8007
+ if (isTestFile(filePath)) return [];
8008
+ const findings = [];
8009
+ const pattern = /(?:ssn|social[_-]?sec(?:urity)?(?:[_-]?(?:no|num|number))?|taxpayer[_-]?id)\b["']?\s*[:=]\s*["']?(\d{3}-\d{2}-\d{4})/gi;
8010
+ let m;
8011
+ while ((m = pattern.exec(content)) !== null) {
8012
+ const ssn = m[1];
8013
+ const [area, group, serial] = ssn.split("-");
8014
+ if (area === "000" || area === "666" || Number(area) >= 900) continue;
8015
+ if (group === "00" || serial === "0000") continue;
8016
+ if (ssn === "123-45-6789") continue;
8017
+ if (isCommentLine(content, m.index)) continue;
8018
+ const lineNum = lineNumberAt(content, m.index);
8019
+ findings.push({
8020
+ rule: "VC212",
8021
+ title: hardcodedSSN.title,
8022
+ severity: "high",
8023
+ category: "Information Leakage",
8024
+ file: filePath,
8025
+ line: lineNum,
8026
+ snippet: getSnippet(content, lineNum),
8027
+ fix: "Don't hardcode SSNs. Generate fake values for tests (a faker/factory), and store real SSNs with application-level encryption or in a secrets vault \u2014 never as a code literal."
8028
+ });
8029
+ }
8030
+ return findings;
8031
+ }
8032
+ };
7891
8033
  var secretInURLParam = {
7892
8034
  id: "VC146",
7893
8035
  title: "Secret Passed in URL Query Parameter",
@@ -8309,14 +8451,16 @@ var insecureDirectObjectReference = {
8309
8451
  check(content, filePath) {
8310
8452
  if (!filePath.match(/\.(js|ts|jsx|tsx)$/)) return [];
8311
8453
  if (isTestFile(filePath)) return [];
8312
- if (!/\/api\//i.test(filePath)) return [];
8313
- if (!/export\s+(?:async\s+)?function\s+(?:GET|PUT|PATCH|DELETE)/i.test(content)) return [];
8314
- if (!/params\.id|params\.(?:slug|uuid)|req\.params\./i.test(content)) return [];
8315
- if (!/findUnique|findFirst|findById|\.findOne|WHERE.*=.*params|\.get\(.*params/i.test(content)) return [];
8316
- if (/userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i.test(content)) return [];
8317
8454
  if (/admin/i.test(filePath)) return [];
8318
- if (/requireUser|requireUserForApi|getServerSession|auth\(\)/i.test(content)) return [];
8319
- const m = content.match(/params\.id|params\.(?:slug|uuid)|req\.params\./);
8455
+ if (/userId|ownerId|createdBy|user_id|owner_id|AND.*user|where.*user|authorize|canAccess|checkPermission|isOwner|belongsTo/i.test(content)) return [];
8456
+ if (/requireUser|requireUserForApi|requireAuth|withAuth|getServerSession|auth\(\)|req\.user\b|passport|session\.user|isAuthenticated/i.test(content)) return [];
8457
+ if (!/findUnique|findFirst|findById|\.findOne|WHERE.*=.*(?:params|req\.(?:body|query))|\.get\(.*(?:params|req\.(?:body|query))/i.test(content)) return [];
8458
+ const isNextApiIdor = /\/api\//i.test(filePath) && /export\s+(?:async\s+)?function\s+(?:GET|PUT|PATCH|DELETE)/i.test(content) && /params\.id|params\.(?:slug|uuid)|req\.params\./i.test(content);
8459
+ const hasExpressHandler = /\.(get|post|put|patch|delete)\s*\(\s*["'`][^"'`]*["'`]\s*,/i.test(content);
8460
+ const readsObjectRef = /req\.params\b|req\.(?:body|query)\.\w*id\b/i.test(content);
8461
+ const isExpressIdor = hasExpressHandler && readsObjectRef;
8462
+ if (!isNextApiIdor && !isExpressIdor) return [];
8463
+ const m = content.match(/params\.id|params\.(?:slug|uuid)|req\.params\.\w+|req\.params\b|req\.(?:body|query)\.\w*id/i);
8320
8464
  if (!m || m.index === void 0) return [];
8321
8465
  const lineNum = lineNumberAt(content, m.index);
8322
8466
  return [{
@@ -8327,7 +8471,7 @@ var insecureDirectObjectReference = {
8327
8471
  file: filePath,
8328
8472
  line: lineNum,
8329
8473
  snippet: getSnippet(content, lineNum),
8330
- fix: "Add an ownership check: verify the requesting user owns the record before returning it. Example: WHERE id = params.id AND userId = session.userId"
8474
+ fix: "Add an ownership check: verify the requesting user owns the record before returning it. Example: WHERE id = req.params.id AND userId = req.user.id"
8331
8475
  }];
8332
8476
  }
8333
8477
  };
@@ -8616,7 +8760,10 @@ var allCustomRules = [
8616
8760
  // VC204–VC206: GraphQL server hardening
8617
8761
  graphqlNoDepthLimit,
8618
8762
  graphqlNoComplexityLimit,
8619
- graphqlCSRFDisabled
8763
+ graphqlCSRFDisabled,
8764
+ // VC211–VC212: hardcoded sensitive personal data (PII)
8765
+ hardcodedCreditCard,
8766
+ hardcodedSSN
8620
8767
  ];
8621
8768
  function runCustomRules(content, filePath, disabledRules = [], tier = "free", extraRules = []) {
8622
8769
  const findings = [];
@@ -9000,6 +9147,7 @@ function scanEntropy(files) {
9000
9147
  dangerousInnerHTML,
9001
9148
  deprecatedTLS,
9002
9149
  detectFramework,
9150
+ detectPlatform,
9003
9151
  disabledTLSVerification,
9004
9152
  djangoDebug,
9005
9153
  dockerCopySensitive,
@@ -9045,6 +9193,7 @@ function scanEntropy(files) {
9045
9193
  hardcodedAnthropicKey,
9046
9194
  hardcodedCloudflareToken,
9047
9195
  hardcodedCohereKey,
9196
+ hardcodedCreditCard,
9048
9197
  hardcodedDatadogKey,
9049
9198
  hardcodedDiscordToken,
9050
9199
  hardcodedEncryptionKey,
@@ -9074,6 +9223,7 @@ function scanEntropy(files) {
9074
9223
  hardcodedRailwayToken,
9075
9224
  hardcodedReplicateKey,
9076
9225
  hardcodedResendKey,
9226
+ hardcodedSSN,
9077
9227
  hardcodedSecrets,
9078
9228
  hardcodedSendGridKey,
9079
9229
  hardcodedSentryAuthToken,