xploitscan-shared-rules 2.4.16 → 2.4.18

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.16";
168
+ declare const SCANNER_VERSION = "2.4.18";
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.16";
168
+ declare const SCANNER_VERSION = "2.4.18";
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.16";
2
+ var SCANNER_VERSION = "2.4.18";
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(content, line) {
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
- if (structured) beforeAssign = beforeAssign.slice(Math.max(beforeAssign.lastIndexOf(","), beforeAssign.lastIndexOf("{")) + 1);
5207
- candidates.push({ value: match[2], beforeAssign });
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 (SAFE_VAR_NAMES.test(beforeAssign)) continue;
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)) continue;
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")) continue;
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: getSnippet2(content, i + 1),
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.
@@ -6260,8 +6316,183 @@ var CONFIG_CHECKS = [
6260
6316
  }
6261
6317
  return null;
6262
6318
  }
6319
+ },
6320
+ {
6321
+ id: "CFG013",
6322
+ title: "PHP base image affected by CVE-2026-109618 and CVE-2026-109619",
6323
+ severity: "critical",
6324
+ category: "Dependencies",
6325
+ description: "This Dockerfile builds on an official php image whose PHP version is affected by CVE-2026-109618 and CVE-2026-109619 (publicly known as PHP2Shell), memory-safety flaws reachable from unauthenticated HTTP requests to mod_php (-apache) and PHP-FPM (-fpm). Affected: 8.2.0-8.2.34, 8.3.0-8.3.35, 8.4.0-8.4.26, 8.5.0-8.5.11, and all end-of-life releases (8.1 and older), which have no fixed official release. Advisories: https://github.com/php/php-src/security/advisories/GHSA-w8hw-w9fx-j79w and https://github.com/php/php-src/security/advisories/GHSA-6wmf-4rv5-p3rp",
6326
+ fix: "Rebuild on php 8.2.35, 8.3.36, 8.4.27 or 8.5.12 or later, keeping the same variant (for example php:8.3.36-apache). End-of-life branches (8.1 and older) have no fixed release: move to a supported branch. Until you can rebuild, setting session.upload_progress.enabled=0, a low post_max_size and, on 8.5, fatal_error_backtraces=0 reduces but does not remove exposure.",
6327
+ owasp: "A06:2021",
6328
+ cwe: "CWE-1395",
6329
+ filePattern: /Dockerfile$/i,
6330
+ check(content) {
6331
+ const line = php2shellLines(content).cfg013Line;
6332
+ if (line === null) return null;
6333
+ return { line, snippet: getSnippet4(content, line) };
6334
+ }
6335
+ },
6336
+ {
6337
+ id: "CFG014",
6338
+ title: "PHP base image (non-web variant) at a version affected by CVE-2026-109618 and CVE-2026-109619",
6339
+ severity: "info",
6340
+ category: "Dependencies",
6341
+ description: "The final stage uses an official php image without the -apache or -fpm variant at an affected PHP version (8.2.0-8.2.34, 8.3.0-8.3.35, 8.4.0-8.4.26, 8.5.0-8.5.11, or 8.1 and older). The PHP advisories scope the risk to PHP serving web requests (mod_php, PHP-FPM, php-cgi, FrankenPHP, LiteSpeed); the official cli and zts images include php-cgi. Advisories: https://github.com/php/php-src/security/advisories/GHSA-w8hw-w9fx-j79w and https://github.com/php/php-src/security/advisories/GHSA-6wmf-4rv5-p3rp",
6342
+ fix: "Pin a fixed version (8.2.35, 8.3.36, 8.4.27, 8.5.12 or later). If this image never serves web requests, upgrade on your normal schedule.",
6343
+ owasp: "A06:2021",
6344
+ cwe: "CWE-1395",
6345
+ filePattern: /Dockerfile$/i,
6346
+ check(content) {
6347
+ const line = php2shellLines(content).cfg014Line;
6348
+ if (line === null) return null;
6349
+ return { line, snippet: getSnippet4(content, line) };
6350
+ }
6263
6351
  }
6264
6352
  ];
6353
+ var PHP2SHELL_LINE_LIMIT = 4096;
6354
+ var PHP2SHELL_FROM_CAP = 256;
6355
+ var PHP2SHELL_FROM_MARK = /^[ \t\uFEFF]{0,4096}FROM[ \t]/i;
6356
+ var PHP2SHELL_FROM = /^[ \t\uFEFF]{0,4096}FROM[ \t]{1,4096}(?:--[^ \t]{1,256}[ \t]{1,4096}){0,4}([^ \t]{1,512})(?:[ \t]{1,4096}AS[ \t]{1,4096}([^ \t]{1,128}))?[ \t]{0,4096}$/i;
6357
+ var PHP2SHELL_ARG = /^[ \t\uFEFF]{0,4096}ARG[ \t]{1,4096}([A-Za-z_][A-Za-z0-9_]{0,63})=(?:"([^"\s$]{1,64})"|'([^'\s$]{1,64})'|([^\s"'$]{1,64}))[ \t]{0,4096}$/i;
6358
+ var PHP2SHELL_VAR = /\$(?:\{([A-Za-z_][A-Za-z0-9_]{0,63})\}|([A-Za-z_][A-Za-z0-9_]{0,63}))/g;
6359
+ var PHP2SHELL_IMAGE = /^(?:(?:docker\.io|registry-1\.docker\.io|index\.docker\.io|mirror\.gcr\.io|public\.ecr\.aws\/docker)\/)?(?:library\/)?php(?::([A-Za-z0-9_][A-Za-z0-9_.-]{0,127}))?(?:@sha256:[a-f0-9]{64})?$/;
6360
+ var PHP2SHELL_TAG = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,3}))?(?:-([a-z0-9][a-z0-9.-]{0,63}))?$/;
6361
+ var PHP2SHELL_FIXED_PATCH = [
6362
+ [8, 2, 35],
6363
+ [8, 3, 36],
6364
+ [8, 4, 27],
6365
+ [8, 5, 12]
6366
+ ];
6367
+ function php2shellDigits(value) {
6368
+ let n = 0;
6369
+ for (let i = 0; i < value.length; i++) n = n * 10 + (value.charCodeAt(i) - 48);
6370
+ return n;
6371
+ }
6372
+ function php2shellFixedPatch(major, minor) {
6373
+ for (let i = 0; i < PHP2SHELL_FIXED_PATCH.length; i++) {
6374
+ const row = PHP2SHELL_FIXED_PATCH[i];
6375
+ if (row[0] === major && row[1] === minor) return row[2];
6376
+ }
6377
+ return null;
6378
+ }
6379
+ function php2shellAffected(major, minor, patch) {
6380
+ if (major < 8) return true;
6381
+ if (major === 8 && minor !== null && minor <= 1) return true;
6382
+ if (minor === null || patch === null) return false;
6383
+ const fixed = php2shellFixedPatch(major, minor);
6384
+ return fixed !== null && patch < fixed;
6385
+ }
6386
+ function php2shellWebSapi(suffix) {
6387
+ if (!suffix) return false;
6388
+ let start = 0;
6389
+ for (let i = 0; i <= suffix.length; i++) {
6390
+ if (i === suffix.length || suffix.charCodeAt(i) === 45) {
6391
+ const token = suffix.slice(start, i);
6392
+ if (token === "apache" || token === "fpm") return true;
6393
+ start = i + 1;
6394
+ }
6395
+ }
6396
+ return false;
6397
+ }
6398
+ function php2shellComment(line) {
6399
+ let i = 0;
6400
+ while (i < line.length) {
6401
+ const c = line.charCodeAt(i);
6402
+ if (c !== 32 && c !== 9) break;
6403
+ i += 1;
6404
+ }
6405
+ return i < line.length && line.charCodeAt(i) === 35;
6406
+ }
6407
+ function php2shellNormalize(raw, index) {
6408
+ let line = raw;
6409
+ if (index === 0 && line.charCodeAt(0) === 65279) line = line.slice(1);
6410
+ if (line.length > 0 && line.charCodeAt(line.length - 1) === 13) line = line.slice(0, -1);
6411
+ return line;
6412
+ }
6413
+ function php2shellSubstitute(ref, args) {
6414
+ PHP2SHELL_VAR.lastIndex = 0;
6415
+ let unknown = false;
6416
+ const out = ref.replace(PHP2SHELL_VAR, (match, braced, bare) => {
6417
+ const name = braced ?? bare;
6418
+ const value = name ? args.get(name) : void 0;
6419
+ if (value === void 0) {
6420
+ unknown = true;
6421
+ return match;
6422
+ }
6423
+ return value;
6424
+ });
6425
+ if (unknown || out.includes("$")) return null;
6426
+ return out;
6427
+ }
6428
+ function php2shellLines(content) {
6429
+ const args = /* @__PURE__ */ new Map();
6430
+ const stages = /* @__PURE__ */ new Set();
6431
+ let seenFrom = false;
6432
+ let fromCount = 0;
6433
+ let capped = false;
6434
+ let cfg013Line = null;
6435
+ let lastLine = 0;
6436
+ let lastAffectedNonWeb = false;
6437
+ const lines = content.split("\n");
6438
+ for (let i = 0; i < lines.length; i++) {
6439
+ const line = php2shellNormalize(lines[i] ?? "", i);
6440
+ if (line.length > PHP2SHELL_LINE_LIMIT) continue;
6441
+ if (php2shellComment(line)) continue;
6442
+ if (!seenFrom) {
6443
+ const arg = PHP2SHELL_ARG.exec(line);
6444
+ if (arg?.[1]) {
6445
+ const value = arg[2] ?? arg[3] ?? arg[4];
6446
+ if (value !== void 0) {
6447
+ args.set(arg[1], value);
6448
+ continue;
6449
+ }
6450
+ }
6451
+ }
6452
+ if (!PHP2SHELL_FROM_MARK.test(line)) continue;
6453
+ fromCount += 1;
6454
+ if (fromCount > PHP2SHELL_FROM_CAP) {
6455
+ capped = true;
6456
+ break;
6457
+ }
6458
+ seenFrom = true;
6459
+ const lineNo = i + 1;
6460
+ lastLine = lineNo;
6461
+ lastAffectedNonWeb = false;
6462
+ const from = PHP2SHELL_FROM.exec(line);
6463
+ const rawRef = from?.[1];
6464
+ if (!rawRef) continue;
6465
+ const ref = php2shellSubstitute(rawRef, args);
6466
+ if (ref === null) continue;
6467
+ const asName = from?.[2];
6468
+ const refLower = ref.toLowerCase();
6469
+ if (stages.has(refLower)) {
6470
+ if (asName) stages.add(asName.toLowerCase());
6471
+ continue;
6472
+ }
6473
+ if (asName) stages.add(asName.toLowerCase());
6474
+ if (ref === "scratch") continue;
6475
+ const image = PHP2SHELL_IMAGE.exec(ref);
6476
+ const tag = image?.[1];
6477
+ if (!image || tag === void 0 || tag === "latest") continue;
6478
+ const parsed = PHP2SHELL_TAG.exec(tag);
6479
+ const majorText = parsed?.[1];
6480
+ if (!parsed || majorText === void 0) continue;
6481
+ const major = php2shellDigits(majorText);
6482
+ const minor = parsed[2] !== void 0 ? php2shellDigits(parsed[2]) : null;
6483
+ const patch = parsed[3] !== void 0 ? php2shellDigits(parsed[3]) : null;
6484
+ if (!php2shellAffected(major, minor, patch)) continue;
6485
+ if (php2shellWebSapi(parsed[4])) {
6486
+ if (cfg013Line === null) cfg013Line = lineNo;
6487
+ } else {
6488
+ lastAffectedNonWeb = true;
6489
+ }
6490
+ }
6491
+ return {
6492
+ cfg013Line,
6493
+ cfg014Line: !capped && cfg013Line === null && lastAffectedNonWeb ? lastLine : null
6494
+ };
6495
+ }
6265
6496
  function scanConfigs(files) {
6266
6497
  const findings = [];
6267
6498
  for (const { path: filePath, content } of files) {