xploitscan-shared-rules 1.27.3 → 1.27.5

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.js CHANGED
@@ -2004,11 +2004,12 @@ var stripeWebhookUnprotected = {
2004
2004
  check(content, filePath) {
2005
2005
  if (!filePath.match(/\.(js|ts|jsx|tsx|py|rb|go|java|php)$/)) return [];
2006
2006
  if (isTestFile(filePath)) return [];
2007
+ const code = maskComments(content);
2007
2008
  const pathSaysStripeWebhook = /(?:^|\/)(?:stripe[_-]?webhooks?|webhooks?[_-]?stripe)(?:\/|\.|$)/i.test(filePath) || /webhooks?\/stripe/i.test(filePath) || /stripe\/webhooks?/i.test(filePath);
2008
- if (!/stripe/i.test(content) && !pathSaysStripeWebhook) return [];
2009
- const hasStripeWebhookHandler = pathSaysStripeWebhook || /(?:stripe.*webhook|webhook.*stripe)/i.test(content) || /(?:checkout\.session\.completed|invoice\.paid|payment_intent|customer\.subscription)/i.test(content);
2009
+ if (!/stripe/i.test(code) && !pathSaysStripeWebhook) return [];
2010
+ const hasStripeWebhookHandler = pathSaysStripeWebhook || /(?:stripe.*webhook|webhook.*stripe)/i.test(code) || /(?:checkout\.session\.completed|invoice\.paid|payment_intent|customer\.subscription)/i.test(code);
2010
2011
  if (!hasStripeWebhookHandler) return [];
2011
- if (/constructEvent|verifyHeader|stripe[_-]?signature|webhook[_-]?secret|STRIPE_WEBHOOK_SECRET/i.test(content) || /\b\w*verif\w*\s*\(/i.test(content) && /\bverif\w*(?:stripe|webhook|signature|sig)\w*\s*\(/i.test(content)) return [];
2012
+ if (/constructEvent|verifyHeader|stripe[_-]?signature|webhook[_-]?secret|STRIPE_WEBHOOK_SECRET/i.test(code) || /\b\w*verif\w*\s*\(/i.test(code) && /\bverif\w*(?:stripe|webhook|signature|sig)\w*\s*\(/i.test(code)) return [];
2012
2013
  const handlerPatterns = [
2013
2014
  // POST handler that processes Stripe events
2014
2015
  /export\s+(?:async\s+)?function\s+POST\s*\(/g,
@@ -2026,7 +2027,7 @@ var stripeWebhookUnprotected = {
2026
2027
  for (const pattern of handlerPatterns) {
2027
2028
  matches.push(
2028
2029
  ...findMatches(
2029
- content,
2030
+ code,
2030
2031
  pattern,
2031
2032
  stripeWebhookUnprotected,
2032
2033
  filePath,
@@ -9776,6 +9777,9 @@ var SKIP_FILENAMES = /(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|composer\
9776
9777
  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;
9777
9778
  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;
9778
9779
  var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
9780
+ var VERIFICATION_BLOCK_RE = /\bverification\s*:\s*\{/;
9781
+ 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;
9782
+ var VERIFICATION_META_RE = /<meta[^>]+name\s*=\s*["'][^"']*(?:site-verification|domain-verification|msvalidate|domain_verify)[^"']*["']/i;
9779
9783
  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;
9780
9784
  function getSnippet2(content, line) {
9781
9785
  const lines = content.split("\n");
@@ -9800,8 +9804,21 @@ function scanEntropy(files) {
9800
9804
  if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(filePath)) continue;
9801
9805
  const vendored = isVendoredPath(filePath);
9802
9806
  const lines = content.split("\n");
9807
+ let verificationDepth = -1;
9808
+ let braceDepth = 0;
9803
9809
  for (let i = 0; i < lines.length; i++) {
9804
9810
  const line = lines[i];
9811
+ if (VERIFICATION_BLOCK_RE.test(line) && verificationDepth === -1) {
9812
+ verificationDepth = braceDepth;
9813
+ }
9814
+ const opens = (line.match(/\{/g) || []).length;
9815
+ const closes = (line.match(/\}/g) || []).length;
9816
+ const depthBefore = braceDepth;
9817
+ braceDepth += opens - closes;
9818
+ if (verificationDepth !== -1 && braceDepth <= verificationDepth && depthBefore > verificationDepth) {
9819
+ verificationDepth = -1;
9820
+ }
9821
+ const inVerificationBlock = verificationDepth !== -1;
9805
9822
  const trimmed = line.trimStart();
9806
9823
  if (trimmed.startsWith("//") || trimmed.startsWith("#") || trimmed.startsWith("*") || trimmed.startsWith("/*")) continue;
9807
9824
  const stringPattern = /(?:[:=]\s*)(["'`])([^"'`\n]{20,120})\1/g;
@@ -9823,7 +9840,9 @@ function scanEntropy(files) {
9823
9840
  if (value.length < 20) continue;
9824
9841
  const entropy = shannonEntropy(value);
9825
9842
  if (entropy < threshold) continue;
9826
- const varName = beforeAssign.match(/(\w+)\s*[:=]\s*$/)?.[1] || "";
9843
+ const varName = beforeAssign.match(/["']([^"']+)["']\s*$/)?.[1] || beforeAssign.match(/([\w$-]+)\s*$/)?.[1] || "";
9844
+ if (inVerificationBlock && VERIFICATION_KEY_NAMES.test(varName)) continue;
9845
+ if (VERIFICATION_META_RE.test(line)) continue;
9827
9846
  if (HASH_LIKE_VAR_NAMES.test(varName) && (isHex || isBase64)) continue;
9828
9847
  const isLikelySecret = SECRET_VAR_NAMES.test(varName);
9829
9848
  if (entropy < 4.5 && !isLikelySecret) continue;