xploitscan-shared-rules 2.4.16 → 2.4.17
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 +67 -11
- 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 +67 -11
- 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.17";
|
|
166
166
|
|
|
167
167
|
// src/snippet.ts
|
|
168
168
|
var cacheContent = null;
|
|
@@ -5217,6 +5217,41 @@ var KEY_VALUE_CONFIG_RE = /\.(?:ini|properties|cfg|conf)$/i;
|
|
|
5217
5217
|
var XML_CONFIG_RE = /\.xml$/i;
|
|
5218
5218
|
var JWT_RE = /^ey[A-Za-z0-9_-]+\.ey[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
5219
5219
|
var SAFE_VAR_NAMES = /(?:description|message|text|label|title|content|template|html|svg|css|style|class(?:Name)?|query|mutation|schema|regex|pattern|format|placeholder|comment|url|path|route|endpoint|href|src|alt|name|type|version|encoding|charset|chars|alphabet|locale|translation|copy|prose|markdown|slug|handle)/i;
|
|
5220
|
+
var SAFE_VAR_NAMES_SCAN = new RegExp(SAFE_VAR_NAMES.source, "gi");
|
|
5221
|
+
var SAFE_VAR_NAMES_AT = new RegExp(SAFE_VAR_NAMES.source, "iy");
|
|
5222
|
+
function buildSafeWordIndex(line) {
|
|
5223
|
+
const starts = [];
|
|
5224
|
+
const ends = [];
|
|
5225
|
+
SAFE_VAR_NAMES_SCAN.lastIndex = 0;
|
|
5226
|
+
let m;
|
|
5227
|
+
while ((m = SAFE_VAR_NAMES_SCAN.exec(line)) !== null) {
|
|
5228
|
+
const s = m.index;
|
|
5229
|
+
let end = s + m[0].length;
|
|
5230
|
+
for (let len = 1; len < m[0].length; len++) {
|
|
5231
|
+
SAFE_VAR_NAMES_AT.lastIndex = 0;
|
|
5232
|
+
if (SAFE_VAR_NAMES_AT.test(line.substring(s, s + len))) {
|
|
5233
|
+
end = s + len;
|
|
5234
|
+
break;
|
|
5235
|
+
}
|
|
5236
|
+
}
|
|
5237
|
+
starts.push(s);
|
|
5238
|
+
ends.push(end);
|
|
5239
|
+
SAFE_VAR_NAMES_SCAN.lastIndex = s + 1;
|
|
5240
|
+
}
|
|
5241
|
+
const minEnd = ends.slice();
|
|
5242
|
+
for (let j = minEnd.length - 2; j >= 0; j--) minEnd[j] = Math.min(minEnd[j], minEnd[j + 1]);
|
|
5243
|
+
return { starts, minEnd };
|
|
5244
|
+
}
|
|
5245
|
+
function safeWordIn(index, from, to) {
|
|
5246
|
+
let lo = 0;
|
|
5247
|
+
let hi = index.starts.length;
|
|
5248
|
+
while (lo < hi) {
|
|
5249
|
+
const mid = lo + hi >>> 1;
|
|
5250
|
+
if (index.starts[mid] < from) lo = mid + 1;
|
|
5251
|
+
else hi = mid;
|
|
5252
|
+
}
|
|
5253
|
+
return lo < index.minEnd.length && index.minEnd[lo] <= to;
|
|
5254
|
+
}
|
|
5220
5255
|
var HASH_LIKE_VAR_NAMES = /(?:^|[^a-z])(?:hash|digest|checksum|fingerprint|etag|crc|md5|sha1|sha256|sha512|contenthash|buildid|revision|commit|sri|integrity|cacheKey|fileHash|assetId|versionId)(?:$|[^a-z])/i;
|
|
5221
5256
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
5222
5257
|
var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
|
|
@@ -5253,8 +5288,7 @@ function assignmentNameBefore(beforeAssign) {
|
|
|
5253
5288
|
return s.slice(i + 1, end);
|
|
5254
5289
|
}
|
|
5255
5290
|
var MAX_QUOTED_VALUE = 256;
|
|
5256
|
-
function getSnippet2(
|
|
5257
|
-
const lines = content.split("\n");
|
|
5291
|
+
function getSnippet2(lines, line) {
|
|
5258
5292
|
const start = Math.max(0, line - 2);
|
|
5259
5293
|
const end = Math.min(lines.length, line + 2);
|
|
5260
5294
|
return lines.slice(start, end).map((l, i) => {
|
|
@@ -5356,22 +5390,38 @@ function scanEntropyFiles(files, collect) {
|
|
|
5356
5390
|
if (adjacent && joined.length >= 20 && joined.length <= MAX_QUOTED_VALUE) {
|
|
5357
5391
|
candidates.push({
|
|
5358
5392
|
value: joined,
|
|
5359
|
-
beforeAssign: line.substring(0, assignmentMatch.index)
|
|
5393
|
+
beforeAssign: line.substring(0, assignmentMatch.index),
|
|
5394
|
+
contextFrom: 0,
|
|
5395
|
+
contextTo: assignmentMatch.index
|
|
5360
5396
|
});
|
|
5361
5397
|
}
|
|
5362
5398
|
}
|
|
5363
5399
|
}
|
|
5364
5400
|
const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,256})\1/g;
|
|
5365
5401
|
let match;
|
|
5402
|
+
let separatorScan = 0;
|
|
5403
|
+
let lastSeparator = -1;
|
|
5366
5404
|
while ((match = stringPattern.exec(line)) !== null) {
|
|
5367
5405
|
if (match[1] === "`" && /(?:^|[\s(]):[a-z][\w-]{0,20}:$/.test(line.slice(Math.max(0, match.index - 23), match.index + 1))) continue;
|
|
5368
5406
|
let beforeAssign = line.substring(0, match.index);
|
|
5369
|
-
|
|
5370
|
-
|
|
5407
|
+
let contextFrom = 0;
|
|
5408
|
+
if (structured) {
|
|
5409
|
+
for (; separatorScan < match.index; separatorScan++) {
|
|
5410
|
+
const c = line.charCodeAt(separatorScan);
|
|
5411
|
+
if (c === 44 || c === 123) lastSeparator = separatorScan;
|
|
5412
|
+
}
|
|
5413
|
+
contextFrom = lastSeparator + 1;
|
|
5414
|
+
beforeAssign = beforeAssign.slice(contextFrom);
|
|
5415
|
+
}
|
|
5416
|
+
candidates.push({ value: match[2], beforeAssign, contextFrom, contextTo: match.index });
|
|
5371
5417
|
}
|
|
5372
5418
|
}
|
|
5419
|
+
let safeWords;
|
|
5420
|
+
let verificationMeta;
|
|
5421
|
+
let silenced;
|
|
5422
|
+
let snippet;
|
|
5373
5423
|
const seenValues = /* @__PURE__ */ new Set();
|
|
5374
|
-
for (const { value, beforeAssign, dotenvName, variableName } of candidates) {
|
|
5424
|
+
for (const { value, beforeAssign, dotenvName, variableName, contextFrom, contextTo } of candidates) {
|
|
5375
5425
|
if (seenValues.has(value)) continue;
|
|
5376
5426
|
seenValues.add(value);
|
|
5377
5427
|
if (value.includes("${")) continue;
|
|
@@ -5382,7 +5432,10 @@ function scanEntropyFiles(files, collect) {
|
|
|
5382
5432
|
const isUuidShape = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
5383
5433
|
if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
|
|
5384
5434
|
if (HASH_PREFIX_RE.test(value)) continue;
|
|
5385
|
-
if (
|
|
5435
|
+
if (contextTo !== void 0) {
|
|
5436
|
+
if (safeWords === void 0) safeWords = buildSafeWordIndex(line);
|
|
5437
|
+
if (safeWordIn(safeWords, contextFrom ?? 0, contextTo)) continue;
|
|
5438
|
+
} else if (SAFE_VAR_NAMES.test(beforeAssign)) continue;
|
|
5386
5439
|
if (/^https?:\/\/[^:@]*$/.test(value)) continue;
|
|
5387
5440
|
if ((value.match(/\s/g) || []).length > 2) continue;
|
|
5388
5441
|
const isHex = /^[0-9a-fA-F]+$/.test(value);
|
|
@@ -5399,7 +5452,8 @@ function scanEntropyFiles(files, collect) {
|
|
|
5399
5452
|
continue;
|
|
5400
5453
|
}
|
|
5401
5454
|
if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
|
|
5402
|
-
if (VERIFICATION_META_RE.test(line)
|
|
5455
|
+
if (verificationMeta === void 0) verificationMeta = VERIFICATION_META_RE.test(line);
|
|
5456
|
+
if (verificationMeta) continue;
|
|
5403
5457
|
if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
|
|
5404
5458
|
if (JWT_RE.test(value) && !isSecretVariableName(varName)) continue;
|
|
5405
5459
|
if (/^DOTENV_PUBLIC_KEY(?:_\w{1,60})?$/.test(varName) && /^0[23][0-9a-fA-F]{64}$/.test(value)) continue;
|
|
@@ -5408,9 +5462,11 @@ function scanEntropyFiles(files, collect) {
|
|
|
5408
5462
|
if (dotenvName && /(?:^|_)IDS?$/i.test(dotenvName) && !isSecretVariableName(dotenvName)) continue;
|
|
5409
5463
|
const isLikelySecret = isSecretVariableName(varName) || publicEnv?.secret === true;
|
|
5410
5464
|
if (entropy < 4.5 && !isLikelySecret) continue;
|
|
5411
|
-
if (isLineSilenced(lines, i, "ENTROPY")
|
|
5465
|
+
if (silenced === void 0) silenced = isLineSilenced(lines, i, "ENTROPY");
|
|
5466
|
+
if (silenced) continue;
|
|
5412
5467
|
collect?.push(value);
|
|
5413
5468
|
const masked = maskSecretValue(value);
|
|
5469
|
+
if (snippet === void 0) snippet = getSnippet2(lines, i + 1);
|
|
5414
5470
|
findings.push({
|
|
5415
5471
|
...vendored ? { vendored: true } : {},
|
|
5416
5472
|
id: `ENTROPY-${filePath}:${i + 1}`,
|
|
@@ -5420,7 +5476,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5420
5476
|
description: `Found a high-entropy string (${entropy.toFixed(1)} bits) that may be a hardcoded secret or API key: "${masked}"`,
|
|
5421
5477
|
file: filePath,
|
|
5422
5478
|
line: i + 1,
|
|
5423
|
-
snippet
|
|
5479
|
+
snippet,
|
|
5424
5480
|
// The generic advice ("move it to an environment variable") is
|
|
5425
5481
|
// wrong for a value that is already in one, so dotenv findings get
|
|
5426
5482
|
// advice about the file, and public-prefixed ones about the prefix.
|