xploitscan-shared-rules 1.14.3 → 1.15.0

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
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ NON_APP_PATH_PATTERNS: () => NON_APP_PATH_PATTERNS,
33
34
  RULE_IMPACTS: () => RULE_IMPACTS,
34
35
  allCustomRules: () => allCustomRules,
35
36
  allRules: () => allRules,
@@ -156,6 +157,8 @@ __export(index_exports, {
156
157
  ipcPathTraversal: () => ipcPathTraversal,
157
158
  isCalleeNamed: () => isCalleeNamed,
158
159
  isMethodCall: () => isMethodCall,
160
+ isVendoredFinding: () => isVendoredFinding,
161
+ isVendoredPath: () => isVendoredPath,
159
162
  javaDeserialization: () => javaDeserialization,
160
163
  jwtAlgConfusion: () => jwtAlgConfusion,
161
164
  k8sNoResourceLimits: () => k8sNoResourceLimits,
@@ -196,6 +199,7 @@ __export(index_exports, {
196
199
  nPlusOneQuery: () => nPlusOneQuery,
197
200
  nextPublicSecret: () => nextPublicSecret,
198
201
  noRateLimiting: () => noRateLimiting,
202
+ normalizeScanPath: () => normalizeScanPath,
199
203
  nosqlInjection: () => nosqlInjection,
200
204
  openRedirectParams: () => openRedirectParams,
201
205
  overlyPermissiveIAM: () => overlyPermissiveIAM,
@@ -253,6 +257,7 @@ __export(index_exports, {
253
257
  unvalidatedRedirect: () => unvalidatedRedirect,
254
258
  vectorStoreQueryNoUserFilter: () => vectorStoreQueryNoUserFilter,
255
259
  vectorStoreUpsertNoMetadata: () => vectorStoreUpsertNoMetadata,
260
+ vendoredReason: () => vendoredReason,
256
261
  visitBinary: () => visitBinary,
257
262
  visitCalls: () => visitCalls,
258
263
  vulnerableDependencies: () => vulnerableDependencies,
@@ -550,6 +555,97 @@ function classifyExposure(filePath) {
550
555
  return "unknown";
551
556
  }
552
557
 
558
+ // src/vendored.ts
559
+ var NON_APP_PATH_PATTERNS = [
560
+ // 1. vendored UI component libraries
561
+ "**/components/ui/**",
562
+ "**/ui/shadcn/**",
563
+ "**/shadcn/ui/**",
564
+ "**/shadcn/**",
565
+ // 2. documentation prose
566
+ "**/*.md",
567
+ "**/*.mdx",
568
+ // 3. AI-agent and editor tooling artifacts. Each gets a `**/`-prefixed form
569
+ // as well as the root-anchored one: these directories turn up per-package
570
+ // in a monorepo, and a finding's `file` is occasionally an absolute path,
571
+ // which makes even a repo-root `.claude/` a nested segment.
572
+ ".claude/**",
573
+ ".agent/**",
574
+ ".cursor/**",
575
+ ".superpowers/**",
576
+ ".windsurf/**",
577
+ "**/.claude/**",
578
+ "**/.agent/**",
579
+ "**/.cursor/**",
580
+ "**/.superpowers/**",
581
+ "**/.windsurf/**",
582
+ // 4. explicitly third-party or machine-generated trees
583
+ "**/vendor/**",
584
+ "**/vendored/**",
585
+ "**/third_party/**",
586
+ "**/generated/**",
587
+ "**/__generated__/**"
588
+ ];
589
+ function globToRegExp(pattern) {
590
+ const segments = pattern.split("/");
591
+ let src = "^";
592
+ for (let i = 0; i < segments.length; i++) {
593
+ const seg = segments[i];
594
+ const isLast = i === segments.length - 1;
595
+ if (seg === "**") {
596
+ src += isLast ? ".+" : "(?:[^/]+/)*";
597
+ continue;
598
+ }
599
+ src += seg.replace(/[.*+?^${}()|[\]\\]/g, (ch) => ch === "*" ? "[^/]*" : "\\" + ch);
600
+ if (!isLast) src += "/";
601
+ }
602
+ return new RegExp(src + "$", "i");
603
+ }
604
+ var NON_APP_MATCHERS = NON_APP_PATH_PATTERNS.map(globToRegExp);
605
+ function normalizeScanPath(filePath) {
606
+ const raw = typeof filePath === "string" ? filePath : "";
607
+ const trimmed = raw.trim();
608
+ const looksWindows = !trimmed.includes("/") && trimmed.includes("\\");
609
+ const withForwardSlashes = (looksWindows ? trimmed.replace(/\\/g, "/") : trimmed).replace(/^[A-Za-z]:\//, "/");
610
+ const out = [];
611
+ for (const segment of withForwardSlashes.split("/")) {
612
+ if (segment === "" || segment === ".") continue;
613
+ if (segment === "..") {
614
+ if (out.length > 0 && out[out.length - 1] !== "..") out.pop();
615
+ else out.push("..");
616
+ continue;
617
+ }
618
+ out.push(segment);
619
+ }
620
+ return out.join("/");
621
+ }
622
+ function isVendoredPath(filePath) {
623
+ const normalized = normalizeScanPath(filePath);
624
+ if (!normalized) return false;
625
+ return NON_APP_MATCHERS.some((re) => re.test(normalized));
626
+ }
627
+ var HEURISTIC_SECRET_RULES = /* @__PURE__ */ new Set(["ENTROPY"]);
628
+ var ALWAYS_GRADED_RULES = /* @__PURE__ */ new Set(["VC115", "VC062"]);
629
+ function isAlwaysGraded(finding) {
630
+ const rule = finding?.rule ?? "";
631
+ if (ALWAYS_GRADED_RULES.has(rule)) return true;
632
+ if (finding?.category !== "Secrets") return false;
633
+ return !HEURISTIC_SECRET_RULES.has(rule);
634
+ }
635
+ function isVendoredFinding(finding) {
636
+ if (isAlwaysGraded(finding)) return false;
637
+ return isVendoredPath(finding?.file ?? "");
638
+ }
639
+ function vendoredReason(filePath) {
640
+ const normalized = normalizeScanPath(filePath);
641
+ if (!normalized) return null;
642
+ if (/\.mdx?$/.test(normalized)) return "documentation";
643
+ if (/(^|\/)(components\/ui|shadcn)(\/|$)/.test(normalized)) return "vendored UI component library";
644
+ if (/(^|\/)\.(claude|agent|cursor|superpowers|windsurf)(\/|$)/.test(normalized)) return "AI-agent tooling artifact";
645
+ if (isVendoredPath(normalized)) return "third-party or generated code";
646
+ return null;
647
+ }
648
+
553
649
  // src/ast/parse.ts
554
650
  var import_parser = require("@babel/parser");
555
651
  var MAX_CACHE = 256;
@@ -4160,12 +4256,20 @@ function detectPlatform(files) {
4160
4256
  }
4161
4257
  return [...platforms];
4162
4258
  }
4163
- function calculateGrade(findings, _totalFiles) {
4164
- if (findings.length === 0) {
4165
- return { grade: "A+", score: 100, summary: "No security issues detected. Excellent." };
4259
+ function calculateGrade(findings, _totalFiles, options = {}) {
4260
+ const scored = options.gradeVendored ? findings : findings.filter((f) => !isVendoredFinding(f));
4261
+ const ungraded = findings.length - scored.length;
4262
+ const holdout = ungraded > 0 ? ` ${ungraded} finding${ungraded === 1 ? "" : "s"} in vendored, generated, or documentation files ${ungraded === 1 ? "is" : "are"} reported but not graded.` : "";
4263
+ if (scored.length === 0) {
4264
+ return {
4265
+ grade: "A+",
4266
+ score: 100,
4267
+ summary: (ungraded > 0 ? "No security issues detected in your own code." : "No security issues detected. Excellent.") + holdout,
4268
+ ungraded
4269
+ };
4166
4270
  }
4167
4271
  let critical = 0, high = 0, medium = 0, low = 0;
4168
- for (const f of findings) {
4272
+ for (const f of scored) {
4169
4273
  if (f.severity === "critical") critical++;
4170
4274
  else if (f.severity === "high") high++;
4171
4275
  else if (f.severity === "medium") medium++;
@@ -4205,7 +4309,7 @@ function calculateGrade(findings, _totalFiles) {
4205
4309
  } else {
4206
4310
  summary = "No security issues detected.";
4207
4311
  }
4208
- return { grade, score: rawScore, summary };
4312
+ return { grade, score: rawScore, summary: summary + holdout, ungraded };
4209
4313
  }
4210
4314
  var jwtAlgConfusion = {
4211
4315
  id: "VC079",
@@ -8783,13 +8887,16 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
8783
8887
  }
8784
8888
  if (maxLineLen > 5e4) return findings;
8785
8889
  if (/onboarding|demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
8890
+ const vendoredFile = isVendoredPath(filePath);
8786
8891
  const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
8787
8892
  for (const rule of ruleset) {
8788
8893
  if (disabledRules.includes(rule.id)) continue;
8789
8894
  const matches = rule.check(content, filePath);
8790
8895
  const compliance = complianceMap[rule.id];
8896
+ const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
8791
8897
  for (const match of matches) {
8792
8898
  findings.push({
8899
+ ...vendored ? { vendored: true } : {},
8793
8900
  id: `${match.rule}-${match.file}:${match.line}`,
8794
8901
  rule: match.rule,
8795
8902
  severity: match.severity,
@@ -8900,7 +9007,7 @@ function parseReviewResponse(text) {
8900
9007
  }
8901
9008
  }
8902
9009
  async function filterFalsePositives(findings, fileContents) {
8903
- const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length };
9010
+ const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length, unreviewedCount: 0 };
8904
9011
  if (!process.env.ANTHROPIC_API_KEY) return empty;
8905
9012
  if (findings.length === 0) return empty;
8906
9013
  const prioritized = [...findings].sort((a, b) => {
@@ -8927,6 +9034,7 @@ async function filterFalsePositives(findings, fileContents) {
8927
9034
  let reviewedAny = false;
8928
9035
  let firstError = null;
8929
9036
  let failedBatches = 0;
9037
+ let unreviewedCount = 0;
8930
9038
  const tasks = [];
8931
9039
  for (const [file, fileFindings] of byFile) {
8932
9040
  const content = fileContents.get(file);
@@ -8936,8 +9044,8 @@ async function filterFalsePositives(findings, fileContents) {
8936
9044
  }
8937
9045
  }
8938
9046
  const reviewBatch = async (task) => {
9047
+ const { batch, content } = task;
8939
9048
  try {
8940
- const { batch, content } = task;
8941
9049
  const prompt = buildReviewPrompt(batch, content);
8942
9050
  const response = await client.messages.create(
8943
9051
  {
@@ -8966,6 +9074,7 @@ async function filterFalsePositives(findings, fileContents) {
8966
9074
  }
8967
9075
  } catch (err) {
8968
9076
  failedBatches++;
9077
+ unreviewedCount += batch.length;
8969
9078
  if (!firstError) firstError = err;
8970
9079
  }
8971
9080
  };
@@ -9002,7 +9111,8 @@ async function filterFalsePositives(findings, fileContents) {
9002
9111
  filteredFindings,
9003
9112
  aiReviewed: reviewedAny,
9004
9113
  removedCount: fpMap.size,
9005
- totalBefore
9114
+ totalBefore,
9115
+ unreviewedCount
9006
9116
  };
9007
9117
  }
9008
9118
 
@@ -9123,6 +9233,7 @@ function scanEntropy(files) {
9123
9233
  if (filePath.includes(".min.")) continue;
9124
9234
  if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
9125
9235
  if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(filePath)) continue;
9236
+ const vendored = isVendoredPath(filePath);
9126
9237
  const lines = content.split("\n");
9127
9238
  for (let i = 0; i < lines.length; i++) {
9128
9239
  const line = lines[i];
@@ -9153,6 +9264,7 @@ function scanEntropy(files) {
9153
9264
  if (entropy < 4.5 && !isLikelySecret) continue;
9154
9265
  const masked = value.substring(0, 6) + "..." + value.substring(value.length - 4);
9155
9266
  findings.push({
9267
+ ...vendored ? { vendored: true } : {},
9156
9268
  id: `ENTROPY-${filePath}:${i + 1}`,
9157
9269
  rule: "ENTROPY",
9158
9270
  severity: isLikelySecret ? "critical" : "high",
@@ -9174,6 +9286,7 @@ function scanEntropy(files) {
9174
9286
  }
9175
9287
  // Annotate the CommonJS export names for ESM import in node:
9176
9288
  0 && (module.exports = {
9289
+ NON_APP_PATH_PATTERNS,
9177
9290
  RULE_IMPACTS,
9178
9291
  allCustomRules,
9179
9292
  allRules,
@@ -9300,6 +9413,8 @@ function scanEntropy(files) {
9300
9413
  ipcPathTraversal,
9301
9414
  isCalleeNamed,
9302
9415
  isMethodCall,
9416
+ isVendoredFinding,
9417
+ isVendoredPath,
9303
9418
  javaDeserialization,
9304
9419
  jwtAlgConfusion,
9305
9420
  k8sNoResourceLimits,
@@ -9340,6 +9455,7 @@ function scanEntropy(files) {
9340
9455
  nPlusOneQuery,
9341
9456
  nextPublicSecret,
9342
9457
  noRateLimiting,
9458
+ normalizeScanPath,
9343
9459
  nosqlInjection,
9344
9460
  openRedirectParams,
9345
9461
  overlyPermissiveIAM,
@@ -9397,6 +9513,7 @@ function scanEntropy(files) {
9397
9513
  unvalidatedRedirect,
9398
9514
  vectorStoreQueryNoUserFilter,
9399
9515
  vectorStoreUpsertNoMetadata,
9516
+ vendoredReason,
9400
9517
  visitBinary,
9401
9518
  visitCalls,
9402
9519
  vulnerableDependencies,