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.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.
|
|
168
|
+
declare const SCANNER_VERSION = "2.4.17";
|
|
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.
|
|
168
|
+
declare const SCANNER_VERSION = "2.4.17";
|
|
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.
|
|
2
|
+
var SCANNER_VERSION = "2.4.17";
|
|
3
3
|
|
|
4
4
|
// src/snippet.ts
|
|
5
5
|
var cacheContent = null;
|
|
@@ -5054,6 +5054,41 @@ var KEY_VALUE_CONFIG_RE = /\.(?:ini|properties|cfg|conf)$/i;
|
|
|
5054
5054
|
var XML_CONFIG_RE = /\.xml$/i;
|
|
5055
5055
|
var JWT_RE = /^ey[A-Za-z0-9_-]+\.ey[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
5056
5056
|
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;
|
|
5057
|
+
var SAFE_VAR_NAMES_SCAN = new RegExp(SAFE_VAR_NAMES.source, "gi");
|
|
5058
|
+
var SAFE_VAR_NAMES_AT = new RegExp(SAFE_VAR_NAMES.source, "iy");
|
|
5059
|
+
function buildSafeWordIndex(line) {
|
|
5060
|
+
const starts = [];
|
|
5061
|
+
const ends = [];
|
|
5062
|
+
SAFE_VAR_NAMES_SCAN.lastIndex = 0;
|
|
5063
|
+
let m;
|
|
5064
|
+
while ((m = SAFE_VAR_NAMES_SCAN.exec(line)) !== null) {
|
|
5065
|
+
const s = m.index;
|
|
5066
|
+
let end = s + m[0].length;
|
|
5067
|
+
for (let len = 1; len < m[0].length; len++) {
|
|
5068
|
+
SAFE_VAR_NAMES_AT.lastIndex = 0;
|
|
5069
|
+
if (SAFE_VAR_NAMES_AT.test(line.substring(s, s + len))) {
|
|
5070
|
+
end = s + len;
|
|
5071
|
+
break;
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
5074
|
+
starts.push(s);
|
|
5075
|
+
ends.push(end);
|
|
5076
|
+
SAFE_VAR_NAMES_SCAN.lastIndex = s + 1;
|
|
5077
|
+
}
|
|
5078
|
+
const minEnd = ends.slice();
|
|
5079
|
+
for (let j = minEnd.length - 2; j >= 0; j--) minEnd[j] = Math.min(minEnd[j], minEnd[j + 1]);
|
|
5080
|
+
return { starts, minEnd };
|
|
5081
|
+
}
|
|
5082
|
+
function safeWordIn(index, from, to) {
|
|
5083
|
+
let lo = 0;
|
|
5084
|
+
let hi = index.starts.length;
|
|
5085
|
+
while (lo < hi) {
|
|
5086
|
+
const mid = lo + hi >>> 1;
|
|
5087
|
+
if (index.starts[mid] < from) lo = mid + 1;
|
|
5088
|
+
else hi = mid;
|
|
5089
|
+
}
|
|
5090
|
+
return lo < index.minEnd.length && index.minEnd[lo] <= to;
|
|
5091
|
+
}
|
|
5057
5092
|
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;
|
|
5058
5093
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
5059
5094
|
var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
|
|
@@ -5090,8 +5125,7 @@ function assignmentNameBefore(beforeAssign) {
|
|
|
5090
5125
|
return s.slice(i + 1, end);
|
|
5091
5126
|
}
|
|
5092
5127
|
var MAX_QUOTED_VALUE = 256;
|
|
5093
|
-
function getSnippet2(
|
|
5094
|
-
const lines = content.split("\n");
|
|
5128
|
+
function getSnippet2(lines, line) {
|
|
5095
5129
|
const start = Math.max(0, line - 2);
|
|
5096
5130
|
const end = Math.min(lines.length, line + 2);
|
|
5097
5131
|
return lines.slice(start, end).map((l, i) => {
|
|
@@ -5193,22 +5227,38 @@ function scanEntropyFiles(files, collect) {
|
|
|
5193
5227
|
if (adjacent && joined.length >= 20 && joined.length <= MAX_QUOTED_VALUE) {
|
|
5194
5228
|
candidates.push({
|
|
5195
5229
|
value: joined,
|
|
5196
|
-
beforeAssign: line.substring(0, assignmentMatch.index)
|
|
5230
|
+
beforeAssign: line.substring(0, assignmentMatch.index),
|
|
5231
|
+
contextFrom: 0,
|
|
5232
|
+
contextTo: assignmentMatch.index
|
|
5197
5233
|
});
|
|
5198
5234
|
}
|
|
5199
5235
|
}
|
|
5200
5236
|
}
|
|
5201
5237
|
const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,256})\1/g;
|
|
5202
5238
|
let match;
|
|
5239
|
+
let separatorScan = 0;
|
|
5240
|
+
let lastSeparator = -1;
|
|
5203
5241
|
while ((match = stringPattern.exec(line)) !== null) {
|
|
5204
5242
|
if (match[1] === "`" && /(?:^|[\s(]):[a-z][\w-]{0,20}:$/.test(line.slice(Math.max(0, match.index - 23), match.index + 1))) continue;
|
|
5205
5243
|
let beforeAssign = line.substring(0, match.index);
|
|
5206
|
-
|
|
5207
|
-
|
|
5244
|
+
let contextFrom = 0;
|
|
5245
|
+
if (structured) {
|
|
5246
|
+
for (; separatorScan < match.index; separatorScan++) {
|
|
5247
|
+
const c = line.charCodeAt(separatorScan);
|
|
5248
|
+
if (c === 44 || c === 123) lastSeparator = separatorScan;
|
|
5249
|
+
}
|
|
5250
|
+
contextFrom = lastSeparator + 1;
|
|
5251
|
+
beforeAssign = beforeAssign.slice(contextFrom);
|
|
5252
|
+
}
|
|
5253
|
+
candidates.push({ value: match[2], beforeAssign, contextFrom, contextTo: match.index });
|
|
5208
5254
|
}
|
|
5209
5255
|
}
|
|
5256
|
+
let safeWords;
|
|
5257
|
+
let verificationMeta;
|
|
5258
|
+
let silenced;
|
|
5259
|
+
let snippet;
|
|
5210
5260
|
const seenValues = /* @__PURE__ */ new Set();
|
|
5211
|
-
for (const { value, beforeAssign, dotenvName, variableName } of candidates) {
|
|
5261
|
+
for (const { value, beforeAssign, dotenvName, variableName, contextFrom, contextTo } of candidates) {
|
|
5212
5262
|
if (seenValues.has(value)) continue;
|
|
5213
5263
|
seenValues.add(value);
|
|
5214
5264
|
if (value.includes("${")) continue;
|
|
@@ -5219,7 +5269,10 @@ function scanEntropyFiles(files, collect) {
|
|
|
5219
5269
|
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);
|
|
5220
5270
|
if (!isUuidShape && SAFE_PATTERNS.some((p) => p.test(value))) continue;
|
|
5221
5271
|
if (HASH_PREFIX_RE.test(value)) continue;
|
|
5222
|
-
if (
|
|
5272
|
+
if (contextTo !== void 0) {
|
|
5273
|
+
if (safeWords === void 0) safeWords = buildSafeWordIndex(line);
|
|
5274
|
+
if (safeWordIn(safeWords, contextFrom ?? 0, contextTo)) continue;
|
|
5275
|
+
} else if (SAFE_VAR_NAMES.test(beforeAssign)) continue;
|
|
5223
5276
|
if (/^https?:\/\/[^:@]*$/.test(value)) continue;
|
|
5224
5277
|
if ((value.match(/\s/g) || []).length > 2) continue;
|
|
5225
5278
|
const isHex = /^[0-9a-fA-F]+$/.test(value);
|
|
@@ -5236,7 +5289,8 @@ function scanEntropyFiles(files, collect) {
|
|
|
5236
5289
|
continue;
|
|
5237
5290
|
}
|
|
5238
5291
|
if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
|
|
5239
|
-
if (VERIFICATION_META_RE.test(line)
|
|
5292
|
+
if (verificationMeta === void 0) verificationMeta = VERIFICATION_META_RE.test(line);
|
|
5293
|
+
if (verificationMeta) continue;
|
|
5240
5294
|
if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
|
|
5241
5295
|
if (JWT_RE.test(value) && !isSecretVariableName(varName)) continue;
|
|
5242
5296
|
if (/^DOTENV_PUBLIC_KEY(?:_\w{1,60})?$/.test(varName) && /^0[23][0-9a-fA-F]{64}$/.test(value)) continue;
|
|
@@ -5245,9 +5299,11 @@ function scanEntropyFiles(files, collect) {
|
|
|
5245
5299
|
if (dotenvName && /(?:^|_)IDS?$/i.test(dotenvName) && !isSecretVariableName(dotenvName)) continue;
|
|
5246
5300
|
const isLikelySecret = isSecretVariableName(varName) || publicEnv?.secret === true;
|
|
5247
5301
|
if (entropy < 4.5 && !isLikelySecret) continue;
|
|
5248
|
-
if (isLineSilenced(lines, i, "ENTROPY")
|
|
5302
|
+
if (silenced === void 0) silenced = isLineSilenced(lines, i, "ENTROPY");
|
|
5303
|
+
if (silenced) continue;
|
|
5249
5304
|
collect?.push(value);
|
|
5250
5305
|
const masked = maskSecretValue(value);
|
|
5306
|
+
if (snippet === void 0) snippet = getSnippet2(lines, i + 1);
|
|
5251
5307
|
findings.push({
|
|
5252
5308
|
...vendored ? { vendored: true } : {},
|
|
5253
5309
|
id: `ENTROPY-${filePath}:${i + 1}`,
|
|
@@ -5257,7 +5313,7 @@ function scanEntropyFiles(files, collect) {
|
|
|
5257
5313
|
description: `Found a high-entropy string (${entropy.toFixed(1)} bits) that may be a hardcoded secret or API key: "${masked}"`,
|
|
5258
5314
|
file: filePath,
|
|
5259
5315
|
line: i + 1,
|
|
5260
|
-
snippet
|
|
5316
|
+
snippet,
|
|
5261
5317
|
// The generic advice ("move it to an environment variable") is
|
|
5262
5318
|
// wrong for a value that is already in one, so dotenv findings get
|
|
5263
5319
|
// advice about the file, and public-prefixed ones about the prefix.
|