xploitscan-shared-rules 2.4.14 → 2.4.15

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
@@ -162,7 +162,7 @@ __export(index_exports, {
162
162
  module.exports = __toCommonJS(index_exports);
163
163
 
164
164
  // src/version.ts
165
- var SCANNER_VERSION = "2.4.14";
165
+ var SCANNER_VERSION = "2.4.15";
166
166
 
167
167
  // src/snippet.ts
168
168
  var cacheContent = null;
@@ -5230,6 +5230,28 @@ function isSecretVariableName(name) {
5230
5230
  }
5231
5231
  var DOTENV_EXAMPLE_RE = /\.(?:example|sample|template|dist|defaults?)$/i;
5232
5232
  var MAX_DOTENV_VALUE = 256;
5233
+ function assignmentNameBefore(beforeAssign) {
5234
+ const s = beforeAssign.trimEnd();
5235
+ const end = s.length;
5236
+ if (end === 0) return "";
5237
+ const last = s.charCodeAt(end - 1);
5238
+ if (last === 34 || last === 39) {
5239
+ let i2 = end - 2;
5240
+ while (i2 >= 0) {
5241
+ const c = s.charCodeAt(i2);
5242
+ if (c === 34 || c === 39) break;
5243
+ i2--;
5244
+ }
5245
+ return i2 >= 0 && i2 < end - 2 ? s.slice(i2 + 1, end - 1) : "";
5246
+ }
5247
+ let i = end - 1;
5248
+ while (i >= 0) {
5249
+ const c = s.charCodeAt(i);
5250
+ if (!(c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 95 || c === 36 || c === 45)) break;
5251
+ i--;
5252
+ }
5253
+ return s.slice(i + 1, end);
5254
+ }
5233
5255
  var MAX_QUOTED_VALUE = 256;
5234
5256
  function getSnippet2(content, line) {
5235
5257
  const lines = content.split("\n");
@@ -5369,7 +5391,7 @@ function scanEntropyFiles(files, collect) {
5369
5391
  if (isHex) threshold = 3;
5370
5392
  else if (isBase64) threshold = 4.5;
5371
5393
  if (value.length < 20) continue;
5372
- const varName = variableName || dotenvName || beforeAssign.match(/["']([^"']+)["']\s*$/)?.[1] || beforeAssign.match(/([\w$-]+)\s*$/)?.[1] || "";
5394
+ const varName = variableName || dotenvName || assignmentNameBefore(beforeAssign);
5373
5395
  if (isUuidShape && !isSecretVariableName(varName)) continue;
5374
5396
  const entropy = shannonEntropy(value);
5375
5397
  if (entropy < threshold && !(isUuidShape && isSecretVariableName(varName))) continue;
@@ -5501,6 +5523,18 @@ function detectedSecretValues(text, filePath) {
5501
5523
  if (!text) return [];
5502
5524
  return [...entropySecretValues(filePath, text), ...hardcodedSecretValues(text, filePath)];
5503
5525
  }
5526
+ function findingSecrets(f, fileContent, detections) {
5527
+ const hit = detections?.get(f);
5528
+ if (hit) return hit;
5529
+ const { lines } = windowLines(fileContent, f.line);
5530
+ const secrets = [
5531
+ ...detectedSecretValues(lines.join("\n"), f.file),
5532
+ ...detectedSecretValues(f.description || "", f.file),
5533
+ ...detectedSecretValues(f.fix || "", f.file)
5534
+ ];
5535
+ detections?.set(f, secrets);
5536
+ return secrets;
5537
+ }
5504
5538
  function applySecretMasks(text, secrets) {
5505
5539
  if (!text || secrets.length === 0) return text;
5506
5540
  const unique = [...new Set(secrets)].filter((secret) => secret.length > 0);
@@ -5539,19 +5573,14 @@ function newDataFence() {
5539
5573
  function buildReviewPrompt(findings, fileContent, fence = newDataFence()) {
5540
5574
  return buildReviewPromptWithSecrets(findings, fileContent, fence).prompt;
5541
5575
  }
5542
- function buildReviewPromptWithSecrets(findings, fileContent, fence) {
5576
+ function buildReviewPromptWithSecrets(findings, fileContent, fence, detections) {
5543
5577
  const allSecrets = [];
5544
5578
  const parts = [];
5545
5579
  for (let i = 0; i < findings.length; i++) {
5546
5580
  const f = findings[i];
5547
5581
  const description = f.description || "";
5548
5582
  const fix = f.fix || "";
5549
- const { lines } = windowLines(fileContent, f.line);
5550
- const secrets = [
5551
- ...detectedSecretValues(lines.join("\n"), f.file),
5552
- ...detectedSecretValues(description, f.file),
5553
- ...detectedSecretValues(fix, f.file)
5554
- ];
5583
+ const secrets = findingSecrets(f, fileContent, detections);
5555
5584
  for (const secret of secrets) allSecrets.push(secret);
5556
5585
  const context = getExpandedContext(fileContent, f.line, secrets);
5557
5586
  const maskedFix = applySecretMasks(fix, secrets);
@@ -5582,12 +5611,15 @@ function maskProofCounts(prompt, secrets) {
5582
5611
  return { detected: unique.length, raw };
5583
5612
  }
5584
5613
  function packReviewBatches(fileFindings, content) {
5614
+ return packReviewBatchesWithCache(fileFindings, content, /* @__PURE__ */ new Map());
5615
+ }
5616
+ function packReviewBatchesWithCache(fileFindings, content, detections) {
5585
5617
  const batches = [];
5586
5618
  let current = [];
5587
5619
  for (const f of fileFindings) {
5588
5620
  const candidate = [...current, f];
5589
5621
  const overCount = candidate.length > MAX_FINDINGS_PER_BATCH;
5590
- const overChars = current.length > 0 && buildReviewPrompt(candidate, content).length > MAX_BATCH_PROMPT_CHARS;
5622
+ const overChars = current.length > 0 && buildReviewPromptWithSecrets(candidate, content, newDataFence(), detections).prompt.length > MAX_BATCH_PROMPT_CHARS;
5591
5623
  if (overCount || overChars) {
5592
5624
  if (current.length > 0) batches.push(current);
5593
5625
  current = [f];
@@ -5689,16 +5721,18 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
5689
5721
  continue;
5690
5722
  }
5691
5723
  let offset = 0;
5692
- for (const batch of packReviewBatches(fileTargets.map((target) => target.finding), content)) {
5724
+ const detections = /* @__PURE__ */ new Map();
5725
+ for (const batch of packReviewBatchesWithCache(fileTargets.map((target) => target.finding), content, detections)) {
5693
5726
  tasks.push({
5694
5727
  targets: fileTargets.slice(offset, offset + batch.length),
5695
- content
5728
+ content,
5729
+ detections
5696
5730
  });
5697
5731
  offset += batch.length;
5698
5732
  }
5699
5733
  }
5700
5734
  const reviewBatch = async (task) => {
5701
- const { targets, content } = task;
5735
+ const { targets, content, detections } = task;
5702
5736
  const batch = targets.map((target) => target.finding);
5703
5737
  if (abortController.signal.aborted || Date.now() >= deadlineMs) {
5704
5738
  budgetExpired = true;
@@ -5707,7 +5741,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
5707
5741
  }
5708
5742
  try {
5709
5743
  const remaining = Math.max(1, deadlineMs - Date.now());
5710
- const { prompt, secrets } = buildReviewPromptWithSecrets(batch, content, newDataFence());
5744
+ const { prompt, secrets } = buildReviewPromptWithSecrets(batch, content, newDataFence(), detections);
5711
5745
  const proof = maskProofCounts(prompt, secrets);
5712
5746
  maskStats.prompt_batches++;
5713
5747
  maskStats.prompt_chars += prompt.length;