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.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.16";
165
+ var SCANNER_VERSION = "2.4.18";
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(content, line) {
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
- if (structured) beforeAssign = beforeAssign.slice(Math.max(beforeAssign.lastIndexOf(","), beforeAssign.lastIndexOf("{")) + 1);
5370
- candidates.push({ value: match[2], beforeAssign });
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 (SAFE_VAR_NAMES.test(beforeAssign)) continue;
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)) continue;
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")) continue;
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: getSnippet2(content, i + 1),
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.
@@ -6423,8 +6479,183 @@ var CONFIG_CHECKS = [
6423
6479
  }
6424
6480
  return null;
6425
6481
  }
6482
+ },
6483
+ {
6484
+ id: "CFG013",
6485
+ title: "PHP base image affected by CVE-2026-109618 and CVE-2026-109619",
6486
+ severity: "critical",
6487
+ category: "Dependencies",
6488
+ 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",
6489
+ 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.",
6490
+ owasp: "A06:2021",
6491
+ cwe: "CWE-1395",
6492
+ filePattern: /Dockerfile$/i,
6493
+ check(content) {
6494
+ const line = php2shellLines(content).cfg013Line;
6495
+ if (line === null) return null;
6496
+ return { line, snippet: getSnippet4(content, line) };
6497
+ }
6498
+ },
6499
+ {
6500
+ id: "CFG014",
6501
+ title: "PHP base image (non-web variant) at a version affected by CVE-2026-109618 and CVE-2026-109619",
6502
+ severity: "info",
6503
+ category: "Dependencies",
6504
+ 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",
6505
+ 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.",
6506
+ owasp: "A06:2021",
6507
+ cwe: "CWE-1395",
6508
+ filePattern: /Dockerfile$/i,
6509
+ check(content) {
6510
+ const line = php2shellLines(content).cfg014Line;
6511
+ if (line === null) return null;
6512
+ return { line, snippet: getSnippet4(content, line) };
6513
+ }
6426
6514
  }
6427
6515
  ];
6516
+ var PHP2SHELL_LINE_LIMIT = 4096;
6517
+ var PHP2SHELL_FROM_CAP = 256;
6518
+ var PHP2SHELL_FROM_MARK = /^[ \t\uFEFF]{0,4096}FROM[ \t]/i;
6519
+ 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;
6520
+ 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;
6521
+ var PHP2SHELL_VAR = /\$(?:\{([A-Za-z_][A-Za-z0-9_]{0,63})\}|([A-Za-z_][A-Za-z0-9_]{0,63}))/g;
6522
+ 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})?$/;
6523
+ var PHP2SHELL_TAG = /^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,3}))?(?:-([a-z0-9][a-z0-9.-]{0,63}))?$/;
6524
+ var PHP2SHELL_FIXED_PATCH = [
6525
+ [8, 2, 35],
6526
+ [8, 3, 36],
6527
+ [8, 4, 27],
6528
+ [8, 5, 12]
6529
+ ];
6530
+ function php2shellDigits(value) {
6531
+ let n = 0;
6532
+ for (let i = 0; i < value.length; i++) n = n * 10 + (value.charCodeAt(i) - 48);
6533
+ return n;
6534
+ }
6535
+ function php2shellFixedPatch(major, minor) {
6536
+ for (let i = 0; i < PHP2SHELL_FIXED_PATCH.length; i++) {
6537
+ const row = PHP2SHELL_FIXED_PATCH[i];
6538
+ if (row[0] === major && row[1] === minor) return row[2];
6539
+ }
6540
+ return null;
6541
+ }
6542
+ function php2shellAffected(major, minor, patch) {
6543
+ if (major < 8) return true;
6544
+ if (major === 8 && minor !== null && minor <= 1) return true;
6545
+ if (minor === null || patch === null) return false;
6546
+ const fixed = php2shellFixedPatch(major, minor);
6547
+ return fixed !== null && patch < fixed;
6548
+ }
6549
+ function php2shellWebSapi(suffix) {
6550
+ if (!suffix) return false;
6551
+ let start = 0;
6552
+ for (let i = 0; i <= suffix.length; i++) {
6553
+ if (i === suffix.length || suffix.charCodeAt(i) === 45) {
6554
+ const token = suffix.slice(start, i);
6555
+ if (token === "apache" || token === "fpm") return true;
6556
+ start = i + 1;
6557
+ }
6558
+ }
6559
+ return false;
6560
+ }
6561
+ function php2shellComment(line) {
6562
+ let i = 0;
6563
+ while (i < line.length) {
6564
+ const c = line.charCodeAt(i);
6565
+ if (c !== 32 && c !== 9) break;
6566
+ i += 1;
6567
+ }
6568
+ return i < line.length && line.charCodeAt(i) === 35;
6569
+ }
6570
+ function php2shellNormalize(raw, index) {
6571
+ let line = raw;
6572
+ if (index === 0 && line.charCodeAt(0) === 65279) line = line.slice(1);
6573
+ if (line.length > 0 && line.charCodeAt(line.length - 1) === 13) line = line.slice(0, -1);
6574
+ return line;
6575
+ }
6576
+ function php2shellSubstitute(ref, args) {
6577
+ PHP2SHELL_VAR.lastIndex = 0;
6578
+ let unknown = false;
6579
+ const out = ref.replace(PHP2SHELL_VAR, (match, braced, bare) => {
6580
+ const name = braced ?? bare;
6581
+ const value = name ? args.get(name) : void 0;
6582
+ if (value === void 0) {
6583
+ unknown = true;
6584
+ return match;
6585
+ }
6586
+ return value;
6587
+ });
6588
+ if (unknown || out.includes("$")) return null;
6589
+ return out;
6590
+ }
6591
+ function php2shellLines(content) {
6592
+ const args = /* @__PURE__ */ new Map();
6593
+ const stages = /* @__PURE__ */ new Set();
6594
+ let seenFrom = false;
6595
+ let fromCount = 0;
6596
+ let capped = false;
6597
+ let cfg013Line = null;
6598
+ let lastLine = 0;
6599
+ let lastAffectedNonWeb = false;
6600
+ const lines = content.split("\n");
6601
+ for (let i = 0; i < lines.length; i++) {
6602
+ const line = php2shellNormalize(lines[i] ?? "", i);
6603
+ if (line.length > PHP2SHELL_LINE_LIMIT) continue;
6604
+ if (php2shellComment(line)) continue;
6605
+ if (!seenFrom) {
6606
+ const arg = PHP2SHELL_ARG.exec(line);
6607
+ if (arg?.[1]) {
6608
+ const value = arg[2] ?? arg[3] ?? arg[4];
6609
+ if (value !== void 0) {
6610
+ args.set(arg[1], value);
6611
+ continue;
6612
+ }
6613
+ }
6614
+ }
6615
+ if (!PHP2SHELL_FROM_MARK.test(line)) continue;
6616
+ fromCount += 1;
6617
+ if (fromCount > PHP2SHELL_FROM_CAP) {
6618
+ capped = true;
6619
+ break;
6620
+ }
6621
+ seenFrom = true;
6622
+ const lineNo = i + 1;
6623
+ lastLine = lineNo;
6624
+ lastAffectedNonWeb = false;
6625
+ const from = PHP2SHELL_FROM.exec(line);
6626
+ const rawRef = from?.[1];
6627
+ if (!rawRef) continue;
6628
+ const ref = php2shellSubstitute(rawRef, args);
6629
+ if (ref === null) continue;
6630
+ const asName = from?.[2];
6631
+ const refLower = ref.toLowerCase();
6632
+ if (stages.has(refLower)) {
6633
+ if (asName) stages.add(asName.toLowerCase());
6634
+ continue;
6635
+ }
6636
+ if (asName) stages.add(asName.toLowerCase());
6637
+ if (ref === "scratch") continue;
6638
+ const image = PHP2SHELL_IMAGE.exec(ref);
6639
+ const tag = image?.[1];
6640
+ if (!image || tag === void 0 || tag === "latest") continue;
6641
+ const parsed = PHP2SHELL_TAG.exec(tag);
6642
+ const majorText = parsed?.[1];
6643
+ if (!parsed || majorText === void 0) continue;
6644
+ const major = php2shellDigits(majorText);
6645
+ const minor = parsed[2] !== void 0 ? php2shellDigits(parsed[2]) : null;
6646
+ const patch = parsed[3] !== void 0 ? php2shellDigits(parsed[3]) : null;
6647
+ if (!php2shellAffected(major, minor, patch)) continue;
6648
+ if (php2shellWebSapi(parsed[4])) {
6649
+ if (cfg013Line === null) cfg013Line = lineNo;
6650
+ } else {
6651
+ lastAffectedNonWeb = true;
6652
+ }
6653
+ }
6654
+ return {
6655
+ cfg013Line,
6656
+ cfg014Line: !capped && cfg013Line === null && lastAffectedNonWeb ? lastLine : null
6657
+ };
6658
+ }
6428
6659
  function scanConfigs(files) {
6429
6660
  const findings = [];
6430
6661
  for (const { path: filePath, content } of files) {