xploitscan-shared-rules 2.4.18 → 2.4.19

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.18";
168
+ declare const SCANNER_VERSION = "2.4.19";
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.18";
168
+ declare const SCANNER_VERSION = "2.4.19";
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.18";
2
+ var SCANNER_VERSION = "2.4.19";
3
3
 
4
4
  // src/snippet.ts
5
5
  var cacheContent = null;
@@ -5093,7 +5093,219 @@ var HASH_LIKE_VAR_NAMES = /(?:^|[^a-z])(?:hash|digest|checksum|fingerprint|etag|
5093
5093
  var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
5094
5094
  var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
5095
5095
  var VERIFICATION_KEY_NAMES = /^(?:google|yandex|yahoo|bing|me|other|["']?(?:google-site-verification|facebook-domain-verification|msvalidate\.01|norton-safeweb-site-verification|ahrefs-site-verification|p:domain_verify|wot-verification)["']?)$/i;
5096
- var VERIFICATION_META_RE = /<meta[^>]+name\s*=\s*["'][^"']*(?:site-verification|domain-verification|msvalidate|domain_verify)[^"']*["']/i;
5096
+ function isWsCode(code) {
5097
+ if (code <= 32) return code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 32;
5098
+ if (code < 160) return false;
5099
+ if (code === 160 || code === 5760 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279) return true;
5100
+ return code >= 8192 && code <= 8202;
5101
+ }
5102
+ function isWordCode(code) {
5103
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 95;
5104
+ }
5105
+ function isWs(c) {
5106
+ return c !== void 0 && isWsCode(c.charCodeAt(0));
5107
+ }
5108
+ function isLineTerminator2(c) {
5109
+ return c === "\n" || c === "\r" || c === "\u2028" || c === "\u2029";
5110
+ }
5111
+ function isAsciiLetter(c) {
5112
+ if (c === void 0) return false;
5113
+ const a = c.charCodeAt(0);
5114
+ return a >= 65 && a <= 90 || a >= 97 && a <= 122;
5115
+ }
5116
+ function isKeyChar(c) {
5117
+ if (c === void 0) return false;
5118
+ const a = c.charCodeAt(0);
5119
+ return a >= 48 && a <= 57 || a >= 65 && a <= 90 || a >= 97 && a <= 122 || a === 95 || a === 46 || a === 45;
5120
+ }
5121
+ function ciAt(line, p, word) {
5122
+ if (p < 0 || p + word.length > line.length) return false;
5123
+ for (let k = 0; k < word.length; k++) {
5124
+ const a = line.charCodeAt(p + k);
5125
+ const b = word.charCodeAt(k);
5126
+ if (a !== b && !(a >= 65 && a <= 90 && a + 32 === b)) return false;
5127
+ }
5128
+ return true;
5129
+ }
5130
+ function matchConfigAssign(line) {
5131
+ const n = line.length;
5132
+ let i = 0;
5133
+ while (i < n && isWs(line[i])) i++;
5134
+ if (!isAsciiLetter(line[i])) return null;
5135
+ const keyStart = i;
5136
+ i++;
5137
+ let extra = 0;
5138
+ while (i < n && extra < 120 && isKeyChar(line[i])) {
5139
+ i++;
5140
+ extra++;
5141
+ }
5142
+ if (extra < 1) return null;
5143
+ if (isKeyChar(line[i])) return null;
5144
+ while (i < n && isWs(line[i])) i++;
5145
+ if (line[i] !== ":" && line[i] !== "=") return null;
5146
+ const valueFrom = i + 1;
5147
+ let j = valueFrom;
5148
+ while (j < n && isWs(line[j])) j++;
5149
+ let end = n;
5150
+ while (end > j && isWs(line[end - 1])) end--;
5151
+ let vs;
5152
+ let ve;
5153
+ if (end > j) {
5154
+ for (let k = j; k < end; k++) if (isLineTerminator2(line[k])) return null;
5155
+ vs = j;
5156
+ ve = end;
5157
+ } else {
5158
+ let k = n - 1;
5159
+ while (k >= valueFrom && isLineTerminator2(line[k])) k--;
5160
+ if (k < valueFrom) return null;
5161
+ vs = k;
5162
+ ve = k + 1;
5163
+ }
5164
+ const out = [line, line.slice(keyStart, keyStart + 1 + extra), line.slice(vs, ve)];
5165
+ out.index = 0;
5166
+ return out;
5167
+ }
5168
+ function isQuote(c) {
5169
+ return c === '"' || c === "'";
5170
+ }
5171
+ function eqQuote(line, p) {
5172
+ const n = line.length;
5173
+ while (p < n && isWs(line[p])) p++;
5174
+ if (line[p] !== "=") return -1;
5175
+ p++;
5176
+ while (p < n && isWs(line[p])) p++;
5177
+ if (!isQuote(line[p])) return -1;
5178
+ return p + 1;
5179
+ }
5180
+ function litAt(line, p, min, max) {
5181
+ let k = p;
5182
+ const lim = Math.min(line.length, p + max + 1);
5183
+ while (k < lim && !isQuote(line[k])) k++;
5184
+ if (k >= line.length || !isQuote(line[k])) return -1;
5185
+ const len = k - p;
5186
+ if (len < min || len > max) return -1;
5187
+ return k;
5188
+ }
5189
+ function rightmostIn(arr, lo, hi) {
5190
+ let a = 0;
5191
+ let b = arr.length - 1;
5192
+ let best = null;
5193
+ while (a <= b) {
5194
+ const mid = a + b >> 1;
5195
+ if (arr[mid][0] <= hi) {
5196
+ if (arr[mid][0] >= lo) best = arr[mid];
5197
+ a = mid + 1;
5198
+ } else b = mid - 1;
5199
+ }
5200
+ return best;
5201
+ }
5202
+ function gtOffsets(line) {
5203
+ const out = [];
5204
+ let from = 0;
5205
+ while (from < line.length) {
5206
+ const g = line.indexOf(">", from);
5207
+ if (g < 0) break;
5208
+ out.push(g);
5209
+ from = g + 1;
5210
+ }
5211
+ return out;
5212
+ }
5213
+ function firstGtAt(offsets, lineLength, from) {
5214
+ let lo = 0;
5215
+ let hi = offsets.length;
5216
+ while (lo < hi) {
5217
+ const mid = lo + hi >> 1;
5218
+ if (offsets[mid] < from) lo = mid + 1;
5219
+ else hi = mid;
5220
+ }
5221
+ return lo < offsets.length ? offsets[lo] : lineLength;
5222
+ }
5223
+ function attrStart(kind, code) {
5224
+ if (kind === "key") return code === 75 || code === 107 || code === 78 || code === 110;
5225
+ return code === 86 || code === 118;
5226
+ }
5227
+ function matchInto(line, p, kind, buf) {
5228
+ if (p > 0 && isWordCode(line.charCodeAt(p - 1))) return false;
5229
+ let w = 0;
5230
+ if (kind === "key") {
5231
+ w = ciAt(line, p, "key") ? 3 : ciAt(line, p, "name") ? 4 : 0;
5232
+ } else if (ciAt(line, p, "value")) {
5233
+ w = 5;
5234
+ }
5235
+ if (!w) return false;
5236
+ const q = eqQuote(line, p + w);
5237
+ if (q < 0) return false;
5238
+ const e = litAt(line, q, kind === "key" ? 1 : 20, kind === "key" ? Number.POSITIVE_INFINITY : 256);
5239
+ if (e < 0) return false;
5240
+ buf[0] = p;
5241
+ buf[1] = q;
5242
+ buf[2] = e;
5243
+ buf[3] = e + 1;
5244
+ return true;
5245
+ }
5246
+ function collectAttr(line, kind) {
5247
+ const buf = [0, 0, 0, 0];
5248
+ const out = [];
5249
+ for (let p = 0; p < line.length; p++) {
5250
+ if (!attrStart(kind, line.charCodeAt(p))) continue;
5251
+ if (!matchInto(line, p, kind, buf)) continue;
5252
+ out.push([buf[0], buf[1], buf[2], buf[3]]);
5253
+ }
5254
+ return out;
5255
+ }
5256
+ function pairScan(line, first, second) {
5257
+ const seconds = collectAttr(line, second);
5258
+ if (seconds.length === 0) return null;
5259
+ const gts = gtOffsets(line);
5260
+ const buf = [0, 0, 0, 0];
5261
+ const n = line.length;
5262
+ for (let p = 0; p < n; p++) {
5263
+ if (!attrStart(first, line.charCodeAt(p))) continue;
5264
+ if (!matchInto(line, p, first, buf)) continue;
5265
+ const s2 = rightmostIn(seconds, buf[3], firstGtAt(gts, n, buf[3]));
5266
+ if (!s2) continue;
5267
+ const out = [line.slice(buf[0], s2[3]), line.slice(buf[1], buf[2]), line.slice(s2[1], s2[2])];
5268
+ out.index = buf[0];
5269
+ return out;
5270
+ }
5271
+ return null;
5272
+ }
5273
+ function matchXmlAttr(line) {
5274
+ return pairScan(line, "key", "value");
5275
+ }
5276
+ function matchXmlElement(line) {
5277
+ return pairScan(line, "value", "key");
5278
+ }
5279
+ var VERIFICATION_META_KEYWORDS = ["site-verification", "domain-verification", "msvalidate", "domain_verify"];
5280
+ function ciIncludes(hay, word) {
5281
+ for (let p = 0; p + word.length <= hay.length; p++) if (ciAt(hay, p, word)) return true;
5282
+ return false;
5283
+ }
5284
+ function matchVerificationMeta(line) {
5285
+ const good = [];
5286
+ for (let p = 0; p < line.length; p++) {
5287
+ if (!ciAt(line, p, "name")) continue;
5288
+ const q = eqQuote(line, p + 4);
5289
+ if (q < 0) continue;
5290
+ const e = litAt(line, q, 0, Number.POSITIVE_INFINITY);
5291
+ if (e < 0) continue;
5292
+ const lit = line.slice(q, e);
5293
+ if (VERIFICATION_META_KEYWORDS.some((w) => ciIncludes(lit, w))) good.push([p]);
5294
+ }
5295
+ if (good.length === 0) return false;
5296
+ const gts = gtOffsets(line);
5297
+ for (let s = 0; s < line.length; s++) {
5298
+ if (!ciAt(line, s, "<meta")) continue;
5299
+ if (rightmostIn(good, s + 6, firstGtAt(gts, line.length, s + 5))) return true;
5300
+ }
5301
+ return false;
5302
+ }
5303
+ var entropyLineMatchers = {
5304
+ configAssign: matchConfigAssign,
5305
+ xmlAttr: matchXmlAttr,
5306
+ xmlElement: matchXmlElement,
5307
+ verificationMeta: matchVerificationMeta
5308
+ };
5097
5309
  var SECRET_VAR_NAMES = /(?:^|[^a-z])(?:key|secret|token|password|passwd|pwd|api[_-]?key|auth|credential|private|signing|bearer|access[_-]?token|refresh[_-]?token|session[_-]?id)(?:$|[^a-z])/i;
5098
5310
  var CAMEL_SECRET_VAR_NAMES = /(?:Key|Secret|Token|Password|Passwd|Credential|Private|Signing|Bearer|Auth)$/;
5099
5311
  var HUMAN_READABLE_ENV_REFERENCE_RE = /^(?:[a-z][a-z'-]*\s+){1,6}[A-Z][A-Z0-9_]{2,}$/;
@@ -5184,7 +5396,7 @@ function scanEntropyFiles(files, collect) {
5184
5396
  }
5185
5397
  } else {
5186
5398
  if (KEY_VALUE_CONFIG_RE.test(filePath)) {
5187
- const configAssign = /^\s*([A-Za-z][\w.-]{1,120})\s*[:=]\s*(.+?)\s*$/.exec(line);
5399
+ const configAssign = entropyLineMatchers.configAssign(line);
5188
5400
  if (configAssign && isSecretVariableName(configAssign[1])) {
5189
5401
  const value = dotenvValue(configAssign[2]);
5190
5402
  if (value.length >= 20 && value.length <= MAX_DOTENV_VALUE) {
@@ -5197,7 +5409,7 @@ function scanEntropyFiles(files, collect) {
5197
5409
  }
5198
5410
  }
5199
5411
  if (XML_CONFIG_RE.test(filePath)) {
5200
- const xmlPair = /\b(?:key|name)\s*=\s*["']([^"']+)["'][^>]*\bvalue\s*=\s*["']([^"']{20,256})["']/i.exec(line) || /\bvalue\s*=\s*["']([^"']{20,256})["'][^>]*\b(?:key|name)\s*=\s*["']([^"']+)["']/i.exec(line);
5412
+ const xmlPair = entropyLineMatchers.xmlAttr(line) || entropyLineMatchers.xmlElement(line);
5201
5413
  if (xmlPair) {
5202
5414
  const valueFirst = /^\s*<[^>]*\bvalue\s*=/i.test(line);
5203
5415
  const variableName = valueFirst ? xmlPair[2] : xmlPair[1];
@@ -5289,7 +5501,7 @@ function scanEntropyFiles(files, collect) {
5289
5501
  continue;
5290
5502
  }
5291
5503
  if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
5292
- if (verificationMeta === void 0) verificationMeta = VERIFICATION_META_RE.test(line);
5504
+ if (verificationMeta === void 0) verificationMeta = entropyLineMatchers.verificationMeta(line);
5293
5505
  if (verificationMeta) continue;
5294
5506
  if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
5295
5507
  if (JWT_RE.test(value) && !isSecretVariableName(varName)) continue;