xploitscan-shared-rules 2.4.14 → 2.4.16
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 +54 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
165
|
+
var SCANNER_VERSION = "2.4.16";
|
|
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 ||
|
|
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
|
|
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 &&
|
|
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
|
-
|
|
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;
|
|
@@ -6793,15 +6827,17 @@ function isExcludedPath(path) {
|
|
|
6793
6827
|
if (/(?:^|\/)(?:migrations?|seeds?|scripts?)\//i.test(path)) return true;
|
|
6794
6828
|
return false;
|
|
6795
6829
|
}
|
|
6830
|
+
var USE_CLIENT_DIRECTIVE = /^[^\S\n\r\u2028\u2029]*["']use client["']/m;
|
|
6831
|
+
var USE_SERVER_DIRECTIVE = /^[^\S\n\r\u2028\u2029]*["']use server["']/m;
|
|
6796
6832
|
function looksClient(code) {
|
|
6797
|
-
if (
|
|
6833
|
+
if (USE_CLIENT_DIRECTIVE.test(code)) return true;
|
|
6798
6834
|
return /\b(?:useState|useEffect|useTransition|useReducer)\s*\(/.test(code);
|
|
6799
6835
|
}
|
|
6800
6836
|
function looksServer(path, code) {
|
|
6801
6837
|
if (/(?:^|\/)route\.(?:ts|js)$/.test(path)) return true;
|
|
6802
6838
|
if (/(?:^|\/)middleware\.(?:ts|js)$/.test(path)) return true;
|
|
6803
6839
|
if (/(?:^|\/)(?:api|server|functions|edge-functions)\//.test(path)) return true;
|
|
6804
|
-
if (
|
|
6840
|
+
if (USE_SERVER_DIRECTIVE.test(code)) return true;
|
|
6805
6841
|
if (/\bDeno\s*\.\s*serve\s*\(/.test(code)) return true;
|
|
6806
6842
|
if (/\bserve\s*\(\s*(?:async\s*)?\(/.test(code) && /deno\.land|@std\/http/i.test(code)) return true;
|
|
6807
6843
|
if (/\bexport\s+(?:async\s+)?function\s+(?:GET|POST|PUT|PATCH|DELETE|HEAD)\s*\(/.test(code)) return true;
|
|
@@ -7285,7 +7321,7 @@ var silentFailedWrite = {
|
|
|
7285
7321
|
if (!file.isClient) continue;
|
|
7286
7322
|
if (file.isServer) continue;
|
|
7287
7323
|
if (NEVER_CLIENT_PATH.test(file.path)) continue;
|
|
7288
|
-
if (
|
|
7324
|
+
if (USE_SERVER_DIRECTIVE.test(file.code)) continue;
|
|
7289
7325
|
const parsed = file.parsed;
|
|
7290
7326
|
if (!parsed) continue;
|
|
7291
7327
|
const { reachable } = collectFunctions(file);
|
|
@@ -9239,7 +9275,7 @@ var failedReadEmptyState = {
|
|
|
9239
9275
|
if (file.excluded) continue;
|
|
9240
9276
|
if (!file.isClient) continue;
|
|
9241
9277
|
if (file.isServer) continue;
|
|
9242
|
-
if (
|
|
9278
|
+
if (USE_SERVER_DIRECTIVE.test(file.code)) continue;
|
|
9243
9279
|
if (!file.code.includes("fetch")) continue;
|
|
9244
9280
|
const parsed = file.parsed;
|
|
9245
9281
|
if (!parsed) continue;
|