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.d.cts CHANGED
@@ -165,7 +165,7 @@ interface CustomRule {
165
165
  * before a scan can be saved without enough provenance to explain a changed
166
166
  * grade.
167
167
  */
168
- declare const SCANNER_VERSION = "2.4.14";
168
+ declare const SCANNER_VERSION = "2.4.15";
169
169
 
170
170
  /**
171
171
  * Line-oriented helpers shared by every rule. Pure string manipulation — no fs
package/dist/index.d.ts CHANGED
@@ -165,7 +165,7 @@ interface CustomRule {
165
165
  * before a scan can be saved without enough provenance to explain a changed
166
166
  * grade.
167
167
  */
168
- declare const SCANNER_VERSION = "2.4.14";
168
+ declare const SCANNER_VERSION = "2.4.15";
169
169
 
170
170
  /**
171
171
  * Line-oriented helpers shared by every rule. Pure string manipulation — no fs
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SCANNER_VERSION = "2.4.14";
2
+ var SCANNER_VERSION = "2.4.15";
3
3
 
4
4
  // src/snippet.ts
5
5
  var cacheContent = null;
@@ -5067,6 +5067,28 @@ function isSecretVariableName(name) {
5067
5067
  }
5068
5068
  var DOTENV_EXAMPLE_RE = /\.(?:example|sample|template|dist|defaults?)$/i;
5069
5069
  var MAX_DOTENV_VALUE = 256;
5070
+ function assignmentNameBefore(beforeAssign) {
5071
+ const s = beforeAssign.trimEnd();
5072
+ const end = s.length;
5073
+ if (end === 0) return "";
5074
+ const last = s.charCodeAt(end - 1);
5075
+ if (last === 34 || last === 39) {
5076
+ let i2 = end - 2;
5077
+ while (i2 >= 0) {
5078
+ const c = s.charCodeAt(i2);
5079
+ if (c === 34 || c === 39) break;
5080
+ i2--;
5081
+ }
5082
+ return i2 >= 0 && i2 < end - 2 ? s.slice(i2 + 1, end - 1) : "";
5083
+ }
5084
+ let i = end - 1;
5085
+ while (i >= 0) {
5086
+ const c = s.charCodeAt(i);
5087
+ if (!(c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 95 || c === 36 || c === 45)) break;
5088
+ i--;
5089
+ }
5090
+ return s.slice(i + 1, end);
5091
+ }
5070
5092
  var MAX_QUOTED_VALUE = 256;
5071
5093
  function getSnippet2(content, line) {
5072
5094
  const lines = content.split("\n");
@@ -5206,7 +5228,7 @@ function scanEntropyFiles(files, collect) {
5206
5228
  if (isHex) threshold = 3;
5207
5229
  else if (isBase64) threshold = 4.5;
5208
5230
  if (value.length < 20) continue;
5209
- const varName = variableName || dotenvName || beforeAssign.match(/["']([^"']+)["']\s*$/)?.[1] || beforeAssign.match(/([\w$-]+)\s*$/)?.[1] || "";
5231
+ const varName = variableName || dotenvName || assignmentNameBefore(beforeAssign);
5210
5232
  if (isUuidShape && !isSecretVariableName(varName)) continue;
5211
5233
  const entropy = shannonEntropy(value);
5212
5234
  if (entropy < threshold && !(isUuidShape && isSecretVariableName(varName))) continue;
@@ -5338,6 +5360,18 @@ function detectedSecretValues(text, filePath) {
5338
5360
  if (!text) return [];
5339
5361
  return [...entropySecretValues(filePath, text), ...hardcodedSecretValues(text, filePath)];
5340
5362
  }
5363
+ function findingSecrets(f, fileContent, detections) {
5364
+ const hit = detections?.get(f);
5365
+ if (hit) return hit;
5366
+ const { lines } = windowLines(fileContent, f.line);
5367
+ const secrets = [
5368
+ ...detectedSecretValues(lines.join("\n"), f.file),
5369
+ ...detectedSecretValues(f.description || "", f.file),
5370
+ ...detectedSecretValues(f.fix || "", f.file)
5371
+ ];
5372
+ detections?.set(f, secrets);
5373
+ return secrets;
5374
+ }
5341
5375
  function applySecretMasks(text, secrets) {
5342
5376
  if (!text || secrets.length === 0) return text;
5343
5377
  const unique = [...new Set(secrets)].filter((secret) => secret.length > 0);
@@ -5376,19 +5410,14 @@ function newDataFence() {
5376
5410
  function buildReviewPrompt(findings, fileContent, fence = newDataFence()) {
5377
5411
  return buildReviewPromptWithSecrets(findings, fileContent, fence).prompt;
5378
5412
  }
5379
- function buildReviewPromptWithSecrets(findings, fileContent, fence) {
5413
+ function buildReviewPromptWithSecrets(findings, fileContent, fence, detections) {
5380
5414
  const allSecrets = [];
5381
5415
  const parts = [];
5382
5416
  for (let i = 0; i < findings.length; i++) {
5383
5417
  const f = findings[i];
5384
5418
  const description = f.description || "";
5385
5419
  const fix = f.fix || "";
5386
- const { lines } = windowLines(fileContent, f.line);
5387
- const secrets = [
5388
- ...detectedSecretValues(lines.join("\n"), f.file),
5389
- ...detectedSecretValues(description, f.file),
5390
- ...detectedSecretValues(fix, f.file)
5391
- ];
5420
+ const secrets = findingSecrets(f, fileContent, detections);
5392
5421
  for (const secret of secrets) allSecrets.push(secret);
5393
5422
  const context = getExpandedContext(fileContent, f.line, secrets);
5394
5423
  const maskedFix = applySecretMasks(fix, secrets);
@@ -5419,12 +5448,15 @@ function maskProofCounts(prompt, secrets) {
5419
5448
  return { detected: unique.length, raw };
5420
5449
  }
5421
5450
  function packReviewBatches(fileFindings, content) {
5451
+ return packReviewBatchesWithCache(fileFindings, content, /* @__PURE__ */ new Map());
5452
+ }
5453
+ function packReviewBatchesWithCache(fileFindings, content, detections) {
5422
5454
  const batches = [];
5423
5455
  let current = [];
5424
5456
  for (const f of fileFindings) {
5425
5457
  const candidate = [...current, f];
5426
5458
  const overCount = candidate.length > MAX_FINDINGS_PER_BATCH;
5427
- const overChars = current.length > 0 && buildReviewPrompt(candidate, content).length > MAX_BATCH_PROMPT_CHARS;
5459
+ const overChars = current.length > 0 && buildReviewPromptWithSecrets(candidate, content, newDataFence(), detections).prompt.length > MAX_BATCH_PROMPT_CHARS;
5428
5460
  if (overCount || overChars) {
5429
5461
  if (current.length > 0) batches.push(current);
5430
5462
  current = [f];
@@ -5526,16 +5558,18 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
5526
5558
  continue;
5527
5559
  }
5528
5560
  let offset = 0;
5529
- for (const batch of packReviewBatches(fileTargets.map((target) => target.finding), content)) {
5561
+ const detections = /* @__PURE__ */ new Map();
5562
+ for (const batch of packReviewBatchesWithCache(fileTargets.map((target) => target.finding), content, detections)) {
5530
5563
  tasks.push({
5531
5564
  targets: fileTargets.slice(offset, offset + batch.length),
5532
- content
5565
+ content,
5566
+ detections
5533
5567
  });
5534
5568
  offset += batch.length;
5535
5569
  }
5536
5570
  }
5537
5571
  const reviewBatch = async (task) => {
5538
- const { targets, content } = task;
5572
+ const { targets, content, detections } = task;
5539
5573
  const batch = targets.map((target) => target.finding);
5540
5574
  if (abortController.signal.aborted || Date.now() >= deadlineMs) {
5541
5575
  budgetExpired = true;
@@ -5544,7 +5578,7 @@ async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER
5544
5578
  }
5545
5579
  try {
5546
5580
  const remaining = Math.max(1, deadlineMs - Date.now());
5547
- const { prompt, secrets } = buildReviewPromptWithSecrets(batch, content, newDataFence());
5581
+ const { prompt, secrets } = buildReviewPromptWithSecrets(batch, content, newDataFence(), detections);
5548
5582
  const proof = maskProofCounts(prompt, secrets);
5549
5583
  maskStats.prompt_batches++;
5550
5584
  maskStats.prompt_chars += prompt.length;