xploitscan-shared-rules 2.3.0 → 2.4.1
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/README.md +1 -1
- package/dist/index.cjs +203 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -9
- package/dist/index.d.ts +83 -9
- package/dist/index.js +199 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -462,6 +462,92 @@ function vendoredReason(filePath) {
|
|
|
462
462
|
return null;
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
+
// src/test-path.ts
|
|
466
|
+
function normalize(filePath) {
|
|
467
|
+
return filePath.replace(/\\/g, "/");
|
|
468
|
+
}
|
|
469
|
+
function baseName(normalized) {
|
|
470
|
+
const slash = normalized.lastIndexOf("/");
|
|
471
|
+
return slash === -1 ? normalized : normalized.slice(slash + 1);
|
|
472
|
+
}
|
|
473
|
+
function isTestPath(filePath) {
|
|
474
|
+
const normalized = normalize(filePath);
|
|
475
|
+
if (!normalized) return false;
|
|
476
|
+
const base = baseName(normalized);
|
|
477
|
+
if (/(?:\.test\.|\.spec\.|\.stories\.|\.story\.|\.mock\.|\.cy\.|\.e2e\.)/i.test(base)) return true;
|
|
478
|
+
if (/^test_.*\.py$/i.test(base) || /_test\.py$/i.test(base)) return true;
|
|
479
|
+
if (/^Test[A-Z_]\w*\.py$/.test(base)) return true;
|
|
480
|
+
if (/^conftest\.py$/i.test(base)) return true;
|
|
481
|
+
if (/_test\.go$/.test(base)) return true;
|
|
482
|
+
if (/^[A-Z][A-Za-z0-9]*Tests\.cs$/.test(base)) return true;
|
|
483
|
+
if (/(?:^|\/)routes\/test\//i.test(normalized)) return false;
|
|
484
|
+
if (/(?:^|\/)(?:tests|testdata|spec|__tests__|__mocks__|fixtures?|mocks?)(?:\/|$)/i.test(normalized)) return true;
|
|
485
|
+
if (/(?:^|\/)test\//i.test(normalized)) return true;
|
|
486
|
+
if (/(?:^|\/)[^/]*\.(?:UnitTests|IntegrationTests|Tests)\//i.test(normalized)) return true;
|
|
487
|
+
if (/\.cs$/.test(base) && /(?:^|\/)[^/]*Tests\//.test(normalized)) return true;
|
|
488
|
+
if (/test-utils/i.test(normalized)) return true;
|
|
489
|
+
if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
493
|
+
function isSbomPath(filePath) {
|
|
494
|
+
return SBOM_FILE_RE.test(normalize(filePath));
|
|
495
|
+
}
|
|
496
|
+
function isPlaceholderToken(token) {
|
|
497
|
+
if (!token) return true;
|
|
498
|
+
if (/(.)\1{7,}/.test(token)) return true;
|
|
499
|
+
if (new Set(token).size < 8) return true;
|
|
500
|
+
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me|\b(?:test|fake|dummy|sample|your)\b/i.test(token);
|
|
501
|
+
}
|
|
502
|
+
var AWS_ACCESS_KEY_SOURCE = String.raw`(?:(?<![A-Z0-9])|(?<=%3[Dd]|\\x[0-9A-Fa-f]{2}|\\u[0-9A-Fa-f]{4}))(?:AKIA|ABIA|ACCA|ASIA)[A-Z0-9]{16}(?![A-Z0-9])`;
|
|
503
|
+
var LIVE_TOKEN_SOURCES = [
|
|
504
|
+
String.raw`(?:sk|rk)_live_[A-Za-z0-9]+`,
|
|
505
|
+
// OpenAI (`T3BlbkFJ` sits in every sk-proj- / sk-svcacct- / sk-admin- / legacy
|
|
506
|
+
// sk- key) and OpenRouter. A bare `sk-` is not a provider format.
|
|
507
|
+
String.raw`sk-(?:(?:proj|svcacct|admin)-[A-Za-z0-9_-]{20,80}|[A-Za-z0-9]{20,80})T3BlbkFJ[A-Za-z0-9_-]{20,80}`,
|
|
508
|
+
String.raw`sk-or-v1-[a-f0-9]{64}`,
|
|
509
|
+
String.raw`sk-ant-api03-[A-Za-z0-9_-]{80,}`,
|
|
510
|
+
String.raw`ghp_[A-Za-z0-9]{36}`,
|
|
511
|
+
String.raw`github_pat_[A-Za-z0-9_]{22,}`,
|
|
512
|
+
String.raw`xox[a-z]-[0-9A-Za-z-]{10,}`,
|
|
513
|
+
String.raw`AIza[A-Za-z0-9_-]{35}`,
|
|
514
|
+
String.raw`SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}`,
|
|
515
|
+
String.raw`\bhf_[A-Za-z]{34}\b`,
|
|
516
|
+
AWS_ACCESS_KEY_SOURCE
|
|
517
|
+
];
|
|
518
|
+
function providerTokens(text) {
|
|
519
|
+
if (!text) return [];
|
|
520
|
+
const out = [];
|
|
521
|
+
for (const source of LIVE_TOKEN_SOURCES) {
|
|
522
|
+
const found = text.match(new RegExp(source, "g"));
|
|
523
|
+
if (found) out.push(...found);
|
|
524
|
+
}
|
|
525
|
+
return out;
|
|
526
|
+
}
|
|
527
|
+
function tokenIsLive(token) {
|
|
528
|
+
if (isPlaceholderToken(token)) return false;
|
|
529
|
+
if (/^(?:AKIA|ABIA|ACCA|ASIA)/.test(token) && /EXAMPLE$/i.test(token)) return false;
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
function isLive(finding) {
|
|
533
|
+
const rule = finding?.rule ?? "";
|
|
534
|
+
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return false;
|
|
535
|
+
if (rule === "VC002" || rule === "VC014") return false;
|
|
536
|
+
if (rule === "VC001") return finding?.live === true;
|
|
537
|
+
if (finding?.live === true) return true;
|
|
538
|
+
const snippet = finding?.snippet ?? "";
|
|
539
|
+
if (providerTokens(snippet).length > 0 && !textHasLiveCredential(snippet)) return false;
|
|
540
|
+
return finding?.category === "Secrets";
|
|
541
|
+
}
|
|
542
|
+
function textHasLiveCredential(text) {
|
|
543
|
+
return providerTokens(text).some(tokenIsLive);
|
|
544
|
+
}
|
|
545
|
+
function isUngradedFinding(finding, options = {}) {
|
|
546
|
+
if (isTestPath(finding?.file ?? "")) return !isLive(finding);
|
|
547
|
+
if (options.gradeVendored) return false;
|
|
548
|
+
return isVendoredFinding(finding);
|
|
549
|
+
}
|
|
550
|
+
|
|
465
551
|
// src/routes.ts
|
|
466
552
|
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
467
553
|
var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
|
|
@@ -477,7 +563,7 @@ function hasDep(files, name) {
|
|
|
477
563
|
return false;
|
|
478
564
|
}
|
|
479
565
|
}
|
|
480
|
-
function
|
|
566
|
+
function normalize2(p) {
|
|
481
567
|
if (!p.startsWith("/")) return "";
|
|
482
568
|
if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
|
|
483
569
|
return p;
|
|
@@ -486,7 +572,7 @@ function extractRoutes(files) {
|
|
|
486
572
|
const routes = /* @__PURE__ */ new Map();
|
|
487
573
|
const frameworks = /* @__PURE__ */ new Set();
|
|
488
574
|
const add = (raw, framework, source, kindOverride) => {
|
|
489
|
-
const path =
|
|
575
|
+
const path = normalize2(raw);
|
|
490
576
|
if (!path || routes.has(path)) return;
|
|
491
577
|
routes.set(path, {
|
|
492
578
|
path,
|
|
@@ -1498,7 +1584,7 @@ function callSpreads(call, matcher) {
|
|
|
1498
1584
|
// src/rules.ts
|
|
1499
1585
|
var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.story\.|\/test\/|\/tests\/|\/fixtures?\/|\/mocks?\/|\.mock\.|test-utils|testing|\.cy\.|\.e2e\.)/i;
|
|
1500
1586
|
function isTestFile(filePath) {
|
|
1501
|
-
return
|
|
1587
|
+
return isTestPath(filePath);
|
|
1502
1588
|
}
|
|
1503
1589
|
var HANDLER_HEADER_RE = /(?:\b(?:async\s+)?function\b|=>\s*$|=>\s*\{?\s*$|\.(?:get|post|put|patch|delete|use|all)\s*\(|\bexport\s+(?:async\s+)?(?:function|const)\s+(?:GET|POST|PUT|PATCH|DELETE)\b|\b(?:Deno\.)?serve\s*\()/i;
|
|
1504
1590
|
function maskComments(content) {
|
|
@@ -1713,11 +1799,6 @@ function isNamespacedSlotKey(name, value) {
|
|
|
1713
1799
|
}
|
|
1714
1800
|
var CREDENTIAL_NAME = /SECRET|SIGN|ENCRYPT|CRYPT|CIPHER|HMAC|JWT|PRIVATE|API|ACCESS|AUTH|MASTER|ADMIN|SESSION|PASS|TOKEN|CLIENT|SALT|PEPPER|LICEN[CS]E|WEBHOOK|STRIPE|AWS|SERVICE/;
|
|
1715
1801
|
var CREDENTIAL_WORD = /secret|passw|token|private|signing|apikey|credential/i;
|
|
1716
|
-
function isPlaceholderToken(token) {
|
|
1717
|
-
if (/(.)\1{7,}/.test(token)) return true;
|
|
1718
|
-
if (new Set(token).size < 8) return true;
|
|
1719
|
-
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me/i.test(token);
|
|
1720
|
-
}
|
|
1721
1802
|
var GEMINI_FILE_CONTEXT_RE = /generativelanguage\.googleapis\.com|@google\/generative-ai|@google\/genai|\bGoogleGenerativeAI\b|\bGoogleGenAI\b|\bgoogle\.generativeai\b|\bfrom\s+google\s+import\s+genai\b/;
|
|
1722
1803
|
var GEMINI_NAME_RE = /gemini|generative/i;
|
|
1723
1804
|
var PUBLIC_GOOGLE_KEY_NAME_RE = /firebase|maps?(?:\b|_)|places|recaptcha|youtube/i;
|
|
@@ -1734,6 +1815,39 @@ function isGeminiKeyContext(lines, line, fileIsGemini) {
|
|
|
1734
1815
|
}
|
|
1735
1816
|
return fileIsGemini || GEMINI_NAME_RE.test(before);
|
|
1736
1817
|
}
|
|
1818
|
+
function dbUrlLacksRealCredential(url) {
|
|
1819
|
+
const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
|
|
1820
|
+
const at = rest.lastIndexOf("@");
|
|
1821
|
+
if (at < 0) return true;
|
|
1822
|
+
const userinfo = rest.slice(0, at);
|
|
1823
|
+
const colon = userinfo.indexOf(":");
|
|
1824
|
+
const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
|
|
1825
|
+
const pass = colon < 0 ? "" : decodeURIComponentSafe(userinfo.slice(colon + 1));
|
|
1826
|
+
if (!pass) return true;
|
|
1827
|
+
if (isFormatPlaceholder(pass)) return true;
|
|
1828
|
+
if (isPlaceholderSecret(pass)) return true;
|
|
1829
|
+
if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
|
|
1830
|
+
return false;
|
|
1831
|
+
}
|
|
1832
|
+
function decodeURIComponentSafe(value) {
|
|
1833
|
+
try {
|
|
1834
|
+
return decodeURIComponent(value);
|
|
1835
|
+
} catch {
|
|
1836
|
+
return value;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
var FORMAT_PLACEHOLDER_MAX = 256;
|
|
1840
|
+
function isFormatPlaceholder(value) {
|
|
1841
|
+
const v = value.trim();
|
|
1842
|
+
if (!v) return true;
|
|
1843
|
+
if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
|
|
1844
|
+
if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
|
|
1845
|
+
if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
|
|
1846
|
+
return false;
|
|
1847
|
+
}
|
|
1848
|
+
function isPlaceholderSecret(value) {
|
|
1849
|
+
return /^(?:password|passwd|pwd|changeme|change[-_]?me|your[-_]?password)$/i.test(value.trim());
|
|
1850
|
+
}
|
|
1737
1851
|
var hardcodedSecrets = {
|
|
1738
1852
|
id: "VC001",
|
|
1739
1853
|
title: "Hardcoded API Key or Secret",
|
|
@@ -1742,13 +1856,14 @@ var hardcodedSecrets = {
|
|
|
1742
1856
|
description: "API keys, tokens, or secrets hardcoded in source code can be extracted by anyone with access to the code.",
|
|
1743
1857
|
check(content, filePath) {
|
|
1744
1858
|
if (filePath.endsWith(".example") || filePath.endsWith(".template")) return [];
|
|
1745
|
-
if (isTestFile(filePath)) return [];
|
|
1746
1859
|
if (filePath.match(/\.(md|txt|rst|adoc)$/)) return [];
|
|
1747
1860
|
const patterns = [
|
|
1748
1861
|
// Generic API key patterns — require actual value assignment, not variable declarations
|
|
1749
1862
|
/(?:api[_-]?key|apikey|api[_-]?secret)\s*[:=]\s*["'`]([a-zA-Z0-9_\-]{20,})["'`]/gi,
|
|
1750
|
-
// AWS
|
|
1751
|
-
|
|
1863
|
+
// AWS access key IDs: exactly 20 characters. Same source as the
|
|
1864
|
+
// live-key check. A longer ASIA token must not match, and a key
|
|
1865
|
+
// ending in EXAMPLE stays non-live in tokenIsLive.
|
|
1866
|
+
new RegExp(AWS_ACCESS_KEY_SOURCE, "g"),
|
|
1752
1867
|
// Stripe keys
|
|
1753
1868
|
/(?:sk_live|pk_live|sk_test|pk_test)_[a-zA-Z0-9]{20,}/g,
|
|
1754
1869
|
// Supabase anon/service keys (JWT format)
|
|
@@ -1768,7 +1883,9 @@ var hardcodedSecrets = {
|
|
|
1768
1883
|
// SCREAMING_CASE identifiers ending in SECRET/TOKEN/KEY/PASSWORD
|
|
1769
1884
|
// (OAUTH_CLIENT_SECRET, JWT_PRIVATE_KEY, STRIPE_WEBHOOK_SECRET, etc.)
|
|
1770
1885
|
// that are assigned a string literal, not an env var or function call.
|
|
1771
|
-
|
|
1886
|
+
// The name is capped at 64 characters so a long run of A's cannot
|
|
1887
|
+
// backtrack into the suffix.
|
|
1888
|
+
/[A-Z][A-Z0-9_]{0,64}_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD)\s*[:=]\s*["'`]([a-zA-Z0-9_\-!@#$%^&*.\/]{12,})["'`]/g,
|
|
1772
1889
|
// camelCase / snake_case object properties that look like credentials:
|
|
1773
1890
|
// apiKey: "...", webhookUrl: "https://...", accountSid: "...", authToken: "..."
|
|
1774
1891
|
// password: "..." caught here separately with a lower threshold (many
|
|
@@ -1778,8 +1895,11 @@ var hardcodedSecrets = {
|
|
|
1778
1895
|
/\b(?:password|passwd|pwd)\s*:\s*["'`]([a-zA-Z0-9_\-!@#$%^&*.\/:\-]{8,})["'`]/gi,
|
|
1779
1896
|
// Private keys
|
|
1780
1897
|
/-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/g,
|
|
1781
|
-
// Database URLs with credentials
|
|
1782
|
-
|
|
1898
|
+
// Database URLs with credentials. The user and password cannot cross
|
|
1899
|
+
// whitespace or a newline, and each is capped at 1024 characters, so
|
|
1900
|
+
// a localhost URL cannot run forward to a later `@` and a run of
|
|
1901
|
+
// `postgres://a:b` with no `@` cannot backtrack.
|
|
1902
|
+
/(?:postgres|mysql|mongodb(?:\+srv)?):\/\/[^:@\s/]{1,1024}:[^@\s]{1,1024}@[^/\s"'`]{1,256}/gi,
|
|
1783
1903
|
// ── [11]–[14] Fixed-prefix AI-provider and payment keys ──
|
|
1784
1904
|
// These match the token itself, so they fire whatever it is bound to:
|
|
1785
1905
|
// `const k = "…"`, a positional `new OpenAI("…")`, an unquoted .env
|
|
@@ -1876,13 +1996,17 @@ var hardcodedSecrets = {
|
|
|
1876
1996
|
if (isPlaceholderToken(token)) continue;
|
|
1877
1997
|
if (pi === GOOGLE_PI) {
|
|
1878
1998
|
if (!isGeminiKeyContext(lines, rm.line, fileIsGemini)) continue;
|
|
1879
|
-
matches.push({ ...rm, severity: "high" });
|
|
1999
|
+
matches.push(textHasLiveCredential(token) ? { ...rm, severity: "high", live: true } : { ...rm, severity: "high" });
|
|
1880
2000
|
continue;
|
|
1881
2001
|
}
|
|
1882
2002
|
if (pi === STRIPE_RESTRICTED_PI && !token.startsWith("rk_live_")) {
|
|
1883
2003
|
matches.push({ ...rm, severity: "high" });
|
|
1884
2004
|
continue;
|
|
1885
2005
|
}
|
|
2006
|
+
if (textHasLiveCredential(token)) {
|
|
2007
|
+
matches.push({ ...rm, live: true });
|
|
2008
|
+
continue;
|
|
2009
|
+
}
|
|
1886
2010
|
}
|
|
1887
2011
|
if (floor > 0) {
|
|
1888
2012
|
const secretMatch = lineText.match(/[:=]\s*["'`]([^"'`]*)["'`]/);
|
|
@@ -1890,7 +2014,7 @@ var hardcodedSecrets = {
|
|
|
1890
2014
|
}
|
|
1891
2015
|
if (pi === 6) {
|
|
1892
2016
|
const valMatch = lineText.match(/[:=]\s*["'`]([^"'`]+)["'`]/);
|
|
1893
|
-
const nameMatch = lineText.match(
|
|
2017
|
+
const nameMatch = lineText.match(/([A-Z][A-Z0-9_]*_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD))\b/);
|
|
1894
2018
|
if (valMatch && nameMatch) {
|
|
1895
2019
|
const value = valMatch[1];
|
|
1896
2020
|
const isKeySuffix = nameMatch[1].endsWith("_KEY");
|
|
@@ -1898,7 +2022,9 @@ var hardcodedSecrets = {
|
|
|
1898
2022
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
1899
2023
|
}
|
|
1900
2024
|
}
|
|
1901
|
-
|
|
2025
|
+
if (pi === 10 && dbUrlLacksRealCredential(matchedText[ri] ?? "")) continue;
|
|
2026
|
+
const matched = matchedText[ri] ?? "";
|
|
2027
|
+
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
1902
2028
|
}
|
|
1903
2029
|
}
|
|
1904
2030
|
return matches;
|
|
@@ -2548,7 +2674,7 @@ var stripeWebhookUnprotected = {
|
|
|
2548
2674
|
const code = maskComments(content);
|
|
2549
2675
|
const pathSaysStripeWebhook = /(?:^|\/)(?:stripe[_-]?webhooks?|webhooks?[_-]?stripe)(?:\/|\.|$)/i.test(filePath) || /webhooks?\/stripe/i.test(filePath) || /stripe\/webhooks?/i.test(filePath);
|
|
2550
2676
|
if (!/stripe/i.test(code) && !pathSaysStripeWebhook) return [];
|
|
2551
|
-
const hasStripeWebhookHandler = pathSaysStripeWebhook || /(?:stripe
|
|
2677
|
+
const hasStripeWebhookHandler = pathSaysStripeWebhook || /(?:stripe.{0,200}webhook|webhook.{0,200}stripe)/i.test(code) || /(?:checkout\.session\.completed|invoice\.paid|payment_intent|customer\.subscription)/i.test(code);
|
|
2552
2678
|
if (!hasStripeWebhookHandler) return [];
|
|
2553
2679
|
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 [];
|
|
2554
2680
|
const handlerPatterns = [
|
|
@@ -3364,10 +3490,12 @@ var missingHTTPS = {
|
|
|
3364
3490
|
category: "Configuration",
|
|
3365
3491
|
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3366
3492
|
check(content, filePath) {
|
|
3367
|
-
const
|
|
3368
|
-
const
|
|
3369
|
-
if (filePath.endsWith(".example") ||
|
|
3370
|
-
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
3493
|
+
const baseName2 = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
3494
|
+
const vc032SkipsTests = /(?:^|\/)(?:__tests__|tests?|testdata|testing|test[-_]?(?:utils?|helpers?|support))\//i.test(filePath) || /^(?:tests?(?![a-z])|conftest\.py$|setupTests\.)|[._-]tests?\.\w+$|\.spec\.\w+$|_spec\.rb$/.test(baseName2);
|
|
3495
|
+
if (filePath.endsWith(".example") || vc032SkipsTests || filePath.includes("README")) return [];
|
|
3496
|
+
if (filePath.match(/\.(md|txt|rst)$/)) return [];
|
|
3497
|
+
if (/(?:^|\/)(?:doc|docs)\//i.test(filePath)) return [];
|
|
3498
|
+
if (/(?:^|\/)conf\.py$/i.test(filePath) && /intersphinx/i.test(content)) return [];
|
|
3371
3499
|
const matches = [];
|
|
3372
3500
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3373
3501
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
@@ -3383,6 +3511,8 @@ var missingHTTPS = {
|
|
|
3383
3511
|
for (const rm of rawMatches) {
|
|
3384
3512
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3385
3513
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3514
|
+
if (/["']\$schema["']\s*:|["']\$id["']\s*:/.test(matchText)) continue;
|
|
3515
|
+
if (/--\s*tsaurl\b|\btsaurl\b|timestamp\.(?:digicert|sectigo|comodoca|globalsign|entrust|geotrust|verisign|apple)\.|timestamp\.acs\.microsoft\.com|freetsa\.org/i.test(matchText)) continue;
|
|
3386
3516
|
matches.push(rm);
|
|
3387
3517
|
}
|
|
3388
3518
|
return matches;
|
|
@@ -3723,11 +3853,13 @@ var GRADE_SEVERITY_RANK = {
|
|
|
3723
3853
|
low: 1,
|
|
3724
3854
|
info: 0
|
|
3725
3855
|
};
|
|
3856
|
+
var ADVISORY_FAMILY_RE = /^(?:GHSA-|CVE-\d|OSV-|DEP\d)/i;
|
|
3726
3857
|
function gradeRuleFamily(finding) {
|
|
3727
3858
|
const rule = (finding.rule ?? "").trim();
|
|
3859
|
+
const id = finding.id ?? "";
|
|
3860
|
+
if (ADVISORY_FAMILY_RE.test(rule) || ADVISORY_FAMILY_RE.test(id)) return "ADVISORY";
|
|
3728
3861
|
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3729
3862
|
if (rule) return rule;
|
|
3730
|
-
const id = finding.id ?? "";
|
|
3731
3863
|
if (id === "ENTROPY" || id.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3732
3864
|
return id || "unknown";
|
|
3733
3865
|
}
|
|
@@ -3754,9 +3886,27 @@ function findingsCountedTowardGrade(findings) {
|
|
|
3754
3886
|
return counted;
|
|
3755
3887
|
}
|
|
3756
3888
|
function calculateGrade(findings, _totalFiles, options = {}) {
|
|
3757
|
-
const scored =
|
|
3889
|
+
const scored = findings.filter((f) => !isUngradedFinding(f, options));
|
|
3758
3890
|
const ungraded = findings.length - scored.length;
|
|
3759
|
-
|
|
3891
|
+
let testHeld = 0;
|
|
3892
|
+
let vendoredHeld = 0;
|
|
3893
|
+
for (const f of findings) {
|
|
3894
|
+
if (!isUngradedFinding(f, options)) continue;
|
|
3895
|
+
if (isTestPath(f.file ?? "")) testHeld++;
|
|
3896
|
+
else vendoredHeld++;
|
|
3897
|
+
}
|
|
3898
|
+
const holdoutParts = [];
|
|
3899
|
+
if (vendoredHeld > 0) {
|
|
3900
|
+
holdoutParts.push(
|
|
3901
|
+
`${vendoredHeld} finding${vendoredHeld === 1 ? "" : "s"} in vendored, generated, or documentation files ${vendoredHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
3902
|
+
);
|
|
3903
|
+
}
|
|
3904
|
+
if (testHeld > 0) {
|
|
3905
|
+
holdoutParts.push(
|
|
3906
|
+
`${testHeld} finding${testHeld === 1 ? "" : "s"} in a test or fixture file, not counted toward the grade, ${testHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3909
|
+
const holdout = holdoutParts.length > 0 ? ` ${holdoutParts.join(" ")}` : "";
|
|
3760
3910
|
if (scored.length === 0) {
|
|
3761
3911
|
return {
|
|
3762
3912
|
grade: "A+",
|
|
@@ -4292,6 +4442,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4292
4442
|
}
|
|
4293
4443
|
if (maxLineLen > 5e4) return findings;
|
|
4294
4444
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4445
|
+
if (isSbomPath(filePath)) return findings;
|
|
4295
4446
|
const vendoredFile = isVendoredPath(filePath);
|
|
4296
4447
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4297
4448
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
@@ -4300,12 +4451,21 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4300
4451
|
const matches = rule.check(content, filePath, project);
|
|
4301
4452
|
const compliance = complianceMap[rule.id];
|
|
4302
4453
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
4454
|
+
const onTestPath = isTestPath(filePath);
|
|
4303
4455
|
for (const match of matches) {
|
|
4304
4456
|
if (silenceableLines && isLineSilenced(silenceableLines, match.line - 1, match.rule)) {
|
|
4305
4457
|
continue;
|
|
4306
4458
|
}
|
|
4459
|
+
const live = isLive({
|
|
4460
|
+
rule: match.rule,
|
|
4461
|
+
category: match.category,
|
|
4462
|
+
live: match.live,
|
|
4463
|
+
snippet: match.snippet
|
|
4464
|
+
});
|
|
4307
4465
|
findings.push({
|
|
4308
4466
|
...vendored ? { vendored: true } : {},
|
|
4467
|
+
...onTestPath && !live ? { testFile: true } : {},
|
|
4468
|
+
...live ? { live: true } : {},
|
|
4309
4469
|
id: `${match.rule}-${match.file}:${match.line}`,
|
|
4310
4470
|
rule: match.rule,
|
|
4311
4471
|
severity: match.severity,
|
|
@@ -4700,20 +4860,6 @@ var SAFE_PATTERNS = [
|
|
|
4700
4860
|
];
|
|
4701
4861
|
var SKIP_FILES = /\.(css|scss|less|svg|md|txt|html?|xml|yml|yaml|toml|lock|map|woff2?|ttf|eot|ico|png|jpg|gif|webp)$/i;
|
|
4702
4862
|
var SKIP_FILENAMES = /(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|composer\.lock|Gemfile\.lock|Cargo\.lock|poetry\.lock|Pipfile\.lock|shrinkwrap\.json)$/i;
|
|
4703
|
-
var SKIP_SBOM_FILES = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json)$/i;
|
|
4704
|
-
function isEntropyTestPath(filePath) {
|
|
4705
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
4706
|
-
if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(normalized)) return true;
|
|
4707
|
-
if (/(?:^|\/)(?:tests|spec)\//i.test(normalized)) return true;
|
|
4708
|
-
if (/(?:^|\/)test\//i.test(normalized) && !/(?:^|\/)routes\/test\//i.test(normalized)) return true;
|
|
4709
|
-
if (/(?:^|\/)[^/]+\.Tests\//.test(normalized)) return true;
|
|
4710
|
-
const base = normalized.split("/").pop() ?? "";
|
|
4711
|
-
if (/^test_.*\.py$/i.test(base)) return true;
|
|
4712
|
-
if (/_test\.py$/i.test(base)) return true;
|
|
4713
|
-
if (/^Test[A-Z_]\w*\.py$/.test(base)) return true;
|
|
4714
|
-
if (/_test\.go$/.test(base)) return true;
|
|
4715
|
-
return false;
|
|
4716
|
-
}
|
|
4717
4863
|
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;
|
|
4718
4864
|
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;
|
|
4719
4865
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
@@ -4740,11 +4886,11 @@ function scanEntropy(files) {
|
|
|
4740
4886
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
4741
4887
|
const basename = filePath.split("/").pop() || "";
|
|
4742
4888
|
if (SKIP_FILENAMES.test(basename)) continue;
|
|
4743
|
-
if (
|
|
4889
|
+
if (isSbomPath(filePath) || isSbomPath(basename)) continue;
|
|
4744
4890
|
if (filePath.includes("node_modules")) continue;
|
|
4745
4891
|
if (filePath.includes(".min.")) continue;
|
|
4746
4892
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
4747
|
-
if (
|
|
4893
|
+
if (isTestPath(filePath)) continue;
|
|
4748
4894
|
const vendored = isVendoredPath(filePath);
|
|
4749
4895
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
4750
4896
|
const lines = content.split("\n");
|
|
@@ -5049,6 +5195,7 @@ function getSnippet3(content, line) {
|
|
|
5049
5195
|
function scanDependencies(files) {
|
|
5050
5196
|
const findings = [];
|
|
5051
5197
|
for (const { path: filePath, content } of files) {
|
|
5198
|
+
if (isSbomPath(filePath)) continue;
|
|
5052
5199
|
if (filePath.endsWith("package.json") && !filePath.includes("node_modules")) {
|
|
5053
5200
|
try {
|
|
5054
5201
|
const pkg = JSON.parse(content);
|
|
@@ -5394,6 +5541,7 @@ var CONFIG_CHECKS = [
|
|
|
5394
5541
|
function scanConfigs(files) {
|
|
5395
5542
|
const findings = [];
|
|
5396
5543
|
for (const { path: filePath, content } of files) {
|
|
5544
|
+
if (isSbomPath(filePath)) continue;
|
|
5397
5545
|
for (const check of CONFIG_CHECKS) {
|
|
5398
5546
|
if (!check.filePattern.test(filePath)) continue;
|
|
5399
5547
|
const result = check.check(content, filePath);
|
|
@@ -5431,6 +5579,7 @@ function getSnippet5(content, line) {
|
|
|
5431
5579
|
}).join("\n");
|
|
5432
5580
|
}
|
|
5433
5581
|
function scanMultiFile(files) {
|
|
5582
|
+
files = files.filter((f) => !isSbomPath(f.path));
|
|
5434
5583
|
const findings = [];
|
|
5435
5584
|
const fileMap = /* @__PURE__ */ new Map();
|
|
5436
5585
|
for (const f of files) {
|
|
@@ -5781,7 +5930,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
5781
5930
|
|
|
5782
5931
|
// src/quality/context.ts
|
|
5783
5932
|
function isExcludedPath(path) {
|
|
5784
|
-
if (
|
|
5933
|
+
if (isTestPath(path)) return true;
|
|
5785
5934
|
if (/(?:^|\/)[\w.-]*(?:fixtures?|mocks?|examples?|samples?)\//i.test(path)) return true;
|
|
5786
5935
|
if (isVendoredPath(path)) return true;
|
|
5787
5936
|
if (/(?:^|\/)(?:\.next|dist|build|out|coverage|node_modules)\//.test(path)) return true;
|
|
@@ -7594,8 +7743,8 @@ function hasOpenStateEarlyReturn(fn) {
|
|
|
7594
7743
|
}
|
|
7595
7744
|
return false;
|
|
7596
7745
|
}
|
|
7597
|
-
function isOpenGated(element, parents,
|
|
7598
|
-
if (MODAL_FILENAME.test(
|
|
7746
|
+
function isOpenGated(element, parents, baseName2) {
|
|
7747
|
+
if (MODAL_FILENAME.test(baseName2)) return true;
|
|
7599
7748
|
let child = element;
|
|
7600
7749
|
let parent = parents.get(child);
|
|
7601
7750
|
for (let steps = 0; parent && steps < 256; steps++) {
|
|
@@ -7638,7 +7787,7 @@ var undeclaredModal = {
|
|
|
7638
7787
|
if (DIALOG_PRIMITIVE.test(file.code)) continue;
|
|
7639
7788
|
const program = parsed.ast.program;
|
|
7640
7789
|
const parents = buildParents(program);
|
|
7641
|
-
const
|
|
7790
|
+
const baseName2 = baseNameWithoutExtension(file.path);
|
|
7642
7791
|
const elements = [];
|
|
7643
7792
|
walkNodes2(program, (node) => {
|
|
7644
7793
|
if (node.type === "JSXElement") elements.push(node);
|
|
@@ -7653,7 +7802,7 @@ var undeclaredModal = {
|
|
|
7653
7802
|
if (!rendersElementChild(element)) continue;
|
|
7654
7803
|
if (!hasFocusableDescendant(element)) continue;
|
|
7655
7804
|
if (declaresSemantics(element)) continue;
|
|
7656
|
-
if (!isOpenGated(element, parents,
|
|
7805
|
+
if (!isOpenGated(element, parents, baseName2)) continue;
|
|
7657
7806
|
const line = opening.loc?.start.line ?? lineAt(file.content, opening.start ?? 0);
|
|
7658
7807
|
hits.push({ file: file.path, line });
|
|
7659
7808
|
break;
|
|
@@ -9361,11 +9510,15 @@ export {
|
|
|
9361
9510
|
isInlineSilenced,
|
|
9362
9511
|
isInsideFixMessage,
|
|
9363
9512
|
isLineSilenced,
|
|
9513
|
+
isLive,
|
|
9364
9514
|
isMethodCall,
|
|
9365
9515
|
isPrivateAddress,
|
|
9516
|
+
isSbomPath,
|
|
9366
9517
|
isServerSideFile,
|
|
9367
9518
|
isServerTarget,
|
|
9368
9519
|
isTestFile,
|
|
9520
|
+
isTestPath,
|
|
9521
|
+
isUngradedFinding,
|
|
9369
9522
|
isVendoredFinding,
|
|
9370
9523
|
isVendoredPath,
|
|
9371
9524
|
lineNumberAt,
|