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/README.md
CHANGED
|
@@ -38,7 +38,7 @@ For the full API surface, see the TypeScript definitions in `dist/index.d.ts` (s
|
|
|
38
38
|
If you're scanning code, install the CLI instead:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
npx xploitscan@
|
|
41
|
+
npx xploitscan@1.17.0 scan .
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
This package is published as a building block for the official XploitScan surfaces and for advanced users who want to call the detection engine directly from their own tooling.
|
package/dist/index.cjs
CHANGED
|
@@ -101,11 +101,15 @@ __export(index_exports, {
|
|
|
101
101
|
isInlineSilenced: () => isInlineSilenced,
|
|
102
102
|
isInsideFixMessage: () => isInsideFixMessage,
|
|
103
103
|
isLineSilenced: () => isLineSilenced,
|
|
104
|
+
isLive: () => isLive,
|
|
104
105
|
isMethodCall: () => isMethodCall,
|
|
105
106
|
isPrivateAddress: () => isPrivateAddress,
|
|
107
|
+
isSbomPath: () => isSbomPath,
|
|
106
108
|
isServerSideFile: () => isServerSideFile,
|
|
107
109
|
isServerTarget: () => isServerTarget,
|
|
108
110
|
isTestFile: () => isTestFile,
|
|
111
|
+
isTestPath: () => isTestPath,
|
|
112
|
+
isUngradedFinding: () => isUngradedFinding,
|
|
109
113
|
isVendoredFinding: () => isVendoredFinding,
|
|
110
114
|
isVendoredPath: () => isVendoredPath,
|
|
111
115
|
lineNumberAt: () => lineNumberAt,
|
|
@@ -612,6 +616,92 @@ function vendoredReason(filePath) {
|
|
|
612
616
|
return null;
|
|
613
617
|
}
|
|
614
618
|
|
|
619
|
+
// src/test-path.ts
|
|
620
|
+
function normalize(filePath) {
|
|
621
|
+
return filePath.replace(/\\/g, "/");
|
|
622
|
+
}
|
|
623
|
+
function baseName(normalized) {
|
|
624
|
+
const slash = normalized.lastIndexOf("/");
|
|
625
|
+
return slash === -1 ? normalized : normalized.slice(slash + 1);
|
|
626
|
+
}
|
|
627
|
+
function isTestPath(filePath) {
|
|
628
|
+
const normalized = normalize(filePath);
|
|
629
|
+
if (!normalized) return false;
|
|
630
|
+
const base = baseName(normalized);
|
|
631
|
+
if (/(?:\.test\.|\.spec\.|\.stories\.|\.story\.|\.mock\.|\.cy\.|\.e2e\.)/i.test(base)) return true;
|
|
632
|
+
if (/^test_.*\.py$/i.test(base) || /_test\.py$/i.test(base)) return true;
|
|
633
|
+
if (/^Test[A-Z_]\w*\.py$/.test(base)) return true;
|
|
634
|
+
if (/^conftest\.py$/i.test(base)) return true;
|
|
635
|
+
if (/_test\.go$/.test(base)) return true;
|
|
636
|
+
if (/^[A-Z][A-Za-z0-9]*Tests\.cs$/.test(base)) return true;
|
|
637
|
+
if (/(?:^|\/)routes\/test\//i.test(normalized)) return false;
|
|
638
|
+
if (/(?:^|\/)(?:tests|testdata|spec|__tests__|__mocks__|fixtures?|mocks?)(?:\/|$)/i.test(normalized)) return true;
|
|
639
|
+
if (/(?:^|\/)test\//i.test(normalized)) return true;
|
|
640
|
+
if (/(?:^|\/)[^/]*\.(?:UnitTests|IntegrationTests|Tests)\//i.test(normalized)) return true;
|
|
641
|
+
if (/\.cs$/.test(base) && /(?:^|\/)[^/]*Tests\//.test(normalized)) return true;
|
|
642
|
+
if (/test-utils/i.test(normalized)) return true;
|
|
643
|
+
if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
647
|
+
function isSbomPath(filePath) {
|
|
648
|
+
return SBOM_FILE_RE.test(normalize(filePath));
|
|
649
|
+
}
|
|
650
|
+
function isPlaceholderToken(token) {
|
|
651
|
+
if (!token) return true;
|
|
652
|
+
if (/(.)\1{7,}/.test(token)) return true;
|
|
653
|
+
if (new Set(token).size < 8) return true;
|
|
654
|
+
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me|\b(?:test|fake|dummy|sample|your)\b/i.test(token);
|
|
655
|
+
}
|
|
656
|
+
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])`;
|
|
657
|
+
var LIVE_TOKEN_SOURCES = [
|
|
658
|
+
String.raw`(?:sk|rk)_live_[A-Za-z0-9]+`,
|
|
659
|
+
// OpenAI (`T3BlbkFJ` sits in every sk-proj- / sk-svcacct- / sk-admin- / legacy
|
|
660
|
+
// sk- key) and OpenRouter. A bare `sk-` is not a provider format.
|
|
661
|
+
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}`,
|
|
662
|
+
String.raw`sk-or-v1-[a-f0-9]{64}`,
|
|
663
|
+
String.raw`sk-ant-api03-[A-Za-z0-9_-]{80,}`,
|
|
664
|
+
String.raw`ghp_[A-Za-z0-9]{36}`,
|
|
665
|
+
String.raw`github_pat_[A-Za-z0-9_]{22,}`,
|
|
666
|
+
String.raw`xox[a-z]-[0-9A-Za-z-]{10,}`,
|
|
667
|
+
String.raw`AIza[A-Za-z0-9_-]{35}`,
|
|
668
|
+
String.raw`SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}`,
|
|
669
|
+
String.raw`\bhf_[A-Za-z]{34}\b`,
|
|
670
|
+
AWS_ACCESS_KEY_SOURCE
|
|
671
|
+
];
|
|
672
|
+
function providerTokens(text) {
|
|
673
|
+
if (!text) return [];
|
|
674
|
+
const out = [];
|
|
675
|
+
for (const source of LIVE_TOKEN_SOURCES) {
|
|
676
|
+
const found = text.match(new RegExp(source, "g"));
|
|
677
|
+
if (found) out.push(...found);
|
|
678
|
+
}
|
|
679
|
+
return out;
|
|
680
|
+
}
|
|
681
|
+
function tokenIsLive(token) {
|
|
682
|
+
if (isPlaceholderToken(token)) return false;
|
|
683
|
+
if (/^(?:AKIA|ABIA|ACCA|ASIA)/.test(token) && /EXAMPLE$/i.test(token)) return false;
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
function isLive(finding) {
|
|
687
|
+
const rule = finding?.rule ?? "";
|
|
688
|
+
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return false;
|
|
689
|
+
if (rule === "VC002" || rule === "VC014") return false;
|
|
690
|
+
if (rule === "VC001") return finding?.live === true;
|
|
691
|
+
if (finding?.live === true) return true;
|
|
692
|
+
const snippet = finding?.snippet ?? "";
|
|
693
|
+
if (providerTokens(snippet).length > 0 && !textHasLiveCredential(snippet)) return false;
|
|
694
|
+
return finding?.category === "Secrets";
|
|
695
|
+
}
|
|
696
|
+
function textHasLiveCredential(text) {
|
|
697
|
+
return providerTokens(text).some(tokenIsLive);
|
|
698
|
+
}
|
|
699
|
+
function isUngradedFinding(finding, options = {}) {
|
|
700
|
+
if (isTestPath(finding?.file ?? "")) return !isLive(finding);
|
|
701
|
+
if (options.gradeVendored) return false;
|
|
702
|
+
return isVendoredFinding(finding);
|
|
703
|
+
}
|
|
704
|
+
|
|
615
705
|
// src/routes.ts
|
|
616
706
|
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
617
707
|
var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
|
|
@@ -627,7 +717,7 @@ function hasDep(files, name) {
|
|
|
627
717
|
return false;
|
|
628
718
|
}
|
|
629
719
|
}
|
|
630
|
-
function
|
|
720
|
+
function normalize2(p) {
|
|
631
721
|
if (!p.startsWith("/")) return "";
|
|
632
722
|
if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
|
|
633
723
|
return p;
|
|
@@ -636,7 +726,7 @@ function extractRoutes(files) {
|
|
|
636
726
|
const routes = /* @__PURE__ */ new Map();
|
|
637
727
|
const frameworks = /* @__PURE__ */ new Set();
|
|
638
728
|
const add = (raw, framework, source, kindOverride) => {
|
|
639
|
-
const path =
|
|
729
|
+
const path = normalize2(raw);
|
|
640
730
|
if (!path || routes.has(path)) return;
|
|
641
731
|
routes.set(path, {
|
|
642
732
|
path,
|
|
@@ -1648,7 +1738,7 @@ function callSpreads(call, matcher) {
|
|
|
1648
1738
|
// src/rules.ts
|
|
1649
1739
|
var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.story\.|\/test\/|\/tests\/|\/fixtures?\/|\/mocks?\/|\.mock\.|test-utils|testing|\.cy\.|\.e2e\.)/i;
|
|
1650
1740
|
function isTestFile(filePath) {
|
|
1651
|
-
return
|
|
1741
|
+
return isTestPath(filePath);
|
|
1652
1742
|
}
|
|
1653
1743
|
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;
|
|
1654
1744
|
function maskComments(content) {
|
|
@@ -1863,11 +1953,6 @@ function isNamespacedSlotKey(name, value) {
|
|
|
1863
1953
|
}
|
|
1864
1954
|
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/;
|
|
1865
1955
|
var CREDENTIAL_WORD = /secret|passw|token|private|signing|apikey|credential/i;
|
|
1866
|
-
function isPlaceholderToken(token) {
|
|
1867
|
-
if (/(.)\1{7,}/.test(token)) return true;
|
|
1868
|
-
if (new Set(token).size < 8) return true;
|
|
1869
|
-
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me/i.test(token);
|
|
1870
|
-
}
|
|
1871
1956
|
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/;
|
|
1872
1957
|
var GEMINI_NAME_RE = /gemini|generative/i;
|
|
1873
1958
|
var PUBLIC_GOOGLE_KEY_NAME_RE = /firebase|maps?(?:\b|_)|places|recaptcha|youtube/i;
|
|
@@ -1884,6 +1969,39 @@ function isGeminiKeyContext(lines, line, fileIsGemini) {
|
|
|
1884
1969
|
}
|
|
1885
1970
|
return fileIsGemini || GEMINI_NAME_RE.test(before);
|
|
1886
1971
|
}
|
|
1972
|
+
function dbUrlLacksRealCredential(url) {
|
|
1973
|
+
const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
|
|
1974
|
+
const at = rest.lastIndexOf("@");
|
|
1975
|
+
if (at < 0) return true;
|
|
1976
|
+
const userinfo = rest.slice(0, at);
|
|
1977
|
+
const colon = userinfo.indexOf(":");
|
|
1978
|
+
const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
|
|
1979
|
+
const pass = colon < 0 ? "" : decodeURIComponentSafe(userinfo.slice(colon + 1));
|
|
1980
|
+
if (!pass) return true;
|
|
1981
|
+
if (isFormatPlaceholder(pass)) return true;
|
|
1982
|
+
if (isPlaceholderSecret(pass)) return true;
|
|
1983
|
+
if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
|
|
1984
|
+
return false;
|
|
1985
|
+
}
|
|
1986
|
+
function decodeURIComponentSafe(value) {
|
|
1987
|
+
try {
|
|
1988
|
+
return decodeURIComponent(value);
|
|
1989
|
+
} catch {
|
|
1990
|
+
return value;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
var FORMAT_PLACEHOLDER_MAX = 256;
|
|
1994
|
+
function isFormatPlaceholder(value) {
|
|
1995
|
+
const v = value.trim();
|
|
1996
|
+
if (!v) return true;
|
|
1997
|
+
if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
|
|
1998
|
+
if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
|
|
1999
|
+
if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
|
|
2000
|
+
return false;
|
|
2001
|
+
}
|
|
2002
|
+
function isPlaceholderSecret(value) {
|
|
2003
|
+
return /^(?:password|passwd|pwd|changeme|change[-_]?me|your[-_]?password)$/i.test(value.trim());
|
|
2004
|
+
}
|
|
1887
2005
|
var hardcodedSecrets = {
|
|
1888
2006
|
id: "VC001",
|
|
1889
2007
|
title: "Hardcoded API Key or Secret",
|
|
@@ -1892,13 +2010,14 @@ var hardcodedSecrets = {
|
|
|
1892
2010
|
description: "API keys, tokens, or secrets hardcoded in source code can be extracted by anyone with access to the code.",
|
|
1893
2011
|
check(content, filePath) {
|
|
1894
2012
|
if (filePath.endsWith(".example") || filePath.endsWith(".template")) return [];
|
|
1895
|
-
if (isTestFile(filePath)) return [];
|
|
1896
2013
|
if (filePath.match(/\.(md|txt|rst|adoc)$/)) return [];
|
|
1897
2014
|
const patterns = [
|
|
1898
2015
|
// Generic API key patterns — require actual value assignment, not variable declarations
|
|
1899
2016
|
/(?:api[_-]?key|apikey|api[_-]?secret)\s*[:=]\s*["'`]([a-zA-Z0-9_\-]{20,})["'`]/gi,
|
|
1900
|
-
// AWS
|
|
1901
|
-
|
|
2017
|
+
// AWS access key IDs: exactly 20 characters. Same source as the
|
|
2018
|
+
// live-key check. A longer ASIA token must not match, and a key
|
|
2019
|
+
// ending in EXAMPLE stays non-live in tokenIsLive.
|
|
2020
|
+
new RegExp(AWS_ACCESS_KEY_SOURCE, "g"),
|
|
1902
2021
|
// Stripe keys
|
|
1903
2022
|
/(?:sk_live|pk_live|sk_test|pk_test)_[a-zA-Z0-9]{20,}/g,
|
|
1904
2023
|
// Supabase anon/service keys (JWT format)
|
|
@@ -1918,7 +2037,9 @@ var hardcodedSecrets = {
|
|
|
1918
2037
|
// SCREAMING_CASE identifiers ending in SECRET/TOKEN/KEY/PASSWORD
|
|
1919
2038
|
// (OAUTH_CLIENT_SECRET, JWT_PRIVATE_KEY, STRIPE_WEBHOOK_SECRET, etc.)
|
|
1920
2039
|
// that are assigned a string literal, not an env var or function call.
|
|
1921
|
-
|
|
2040
|
+
// The name is capped at 64 characters so a long run of A's cannot
|
|
2041
|
+
// backtrack into the suffix.
|
|
2042
|
+
/[A-Z][A-Z0-9_]{0,64}_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD)\s*[:=]\s*["'`]([a-zA-Z0-9_\-!@#$%^&*.\/]{12,})["'`]/g,
|
|
1922
2043
|
// camelCase / snake_case object properties that look like credentials:
|
|
1923
2044
|
// apiKey: "...", webhookUrl: "https://...", accountSid: "...", authToken: "..."
|
|
1924
2045
|
// password: "..." caught here separately with a lower threshold (many
|
|
@@ -1928,8 +2049,11 @@ var hardcodedSecrets = {
|
|
|
1928
2049
|
/\b(?:password|passwd|pwd)\s*:\s*["'`]([a-zA-Z0-9_\-!@#$%^&*.\/:\-]{8,})["'`]/gi,
|
|
1929
2050
|
// Private keys
|
|
1930
2051
|
/-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/g,
|
|
1931
|
-
// Database URLs with credentials
|
|
1932
|
-
|
|
2052
|
+
// Database URLs with credentials. The user and password cannot cross
|
|
2053
|
+
// whitespace or a newline, and each is capped at 1024 characters, so
|
|
2054
|
+
// a localhost URL cannot run forward to a later `@` and a run of
|
|
2055
|
+
// `postgres://a:b` with no `@` cannot backtrack.
|
|
2056
|
+
/(?:postgres|mysql|mongodb(?:\+srv)?):\/\/[^:@\s/]{1,1024}:[^@\s]{1,1024}@[^/\s"'`]{1,256}/gi,
|
|
1933
2057
|
// ── [11]–[14] Fixed-prefix AI-provider and payment keys ──
|
|
1934
2058
|
// These match the token itself, so they fire whatever it is bound to:
|
|
1935
2059
|
// `const k = "…"`, a positional `new OpenAI("…")`, an unquoted .env
|
|
@@ -2026,13 +2150,17 @@ var hardcodedSecrets = {
|
|
|
2026
2150
|
if (isPlaceholderToken(token)) continue;
|
|
2027
2151
|
if (pi === GOOGLE_PI) {
|
|
2028
2152
|
if (!isGeminiKeyContext(lines, rm.line, fileIsGemini)) continue;
|
|
2029
|
-
matches.push({ ...rm, severity: "high" });
|
|
2153
|
+
matches.push(textHasLiveCredential(token) ? { ...rm, severity: "high", live: true } : { ...rm, severity: "high" });
|
|
2030
2154
|
continue;
|
|
2031
2155
|
}
|
|
2032
2156
|
if (pi === STRIPE_RESTRICTED_PI && !token.startsWith("rk_live_")) {
|
|
2033
2157
|
matches.push({ ...rm, severity: "high" });
|
|
2034
2158
|
continue;
|
|
2035
2159
|
}
|
|
2160
|
+
if (textHasLiveCredential(token)) {
|
|
2161
|
+
matches.push({ ...rm, live: true });
|
|
2162
|
+
continue;
|
|
2163
|
+
}
|
|
2036
2164
|
}
|
|
2037
2165
|
if (floor > 0) {
|
|
2038
2166
|
const secretMatch = lineText.match(/[:=]\s*["'`]([^"'`]*)["'`]/);
|
|
@@ -2040,7 +2168,7 @@ var hardcodedSecrets = {
|
|
|
2040
2168
|
}
|
|
2041
2169
|
if (pi === 6) {
|
|
2042
2170
|
const valMatch = lineText.match(/[:=]\s*["'`]([^"'`]+)["'`]/);
|
|
2043
|
-
const nameMatch = lineText.match(
|
|
2171
|
+
const nameMatch = lineText.match(/([A-Z][A-Z0-9_]*_(?:SECRET|TOKEN|KEY|PASSWORD|PASSWD))\b/);
|
|
2044
2172
|
if (valMatch && nameMatch) {
|
|
2045
2173
|
const value = valMatch[1];
|
|
2046
2174
|
const isKeySuffix = nameMatch[1].endsWith("_KEY");
|
|
@@ -2048,7 +2176,9 @@ var hardcodedSecrets = {
|
|
|
2048
2176
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
2049
2177
|
}
|
|
2050
2178
|
}
|
|
2051
|
-
|
|
2179
|
+
if (pi === 10 && dbUrlLacksRealCredential(matchedText[ri] ?? "")) continue;
|
|
2180
|
+
const matched = matchedText[ri] ?? "";
|
|
2181
|
+
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
2052
2182
|
}
|
|
2053
2183
|
}
|
|
2054
2184
|
return matches;
|
|
@@ -2698,7 +2828,7 @@ var stripeWebhookUnprotected = {
|
|
|
2698
2828
|
const code = maskComments(content);
|
|
2699
2829
|
const pathSaysStripeWebhook = /(?:^|\/)(?:stripe[_-]?webhooks?|webhooks?[_-]?stripe)(?:\/|\.|$)/i.test(filePath) || /webhooks?\/stripe/i.test(filePath) || /stripe\/webhooks?/i.test(filePath);
|
|
2700
2830
|
if (!/stripe/i.test(code) && !pathSaysStripeWebhook) return [];
|
|
2701
|
-
const hasStripeWebhookHandler = pathSaysStripeWebhook || /(?:stripe
|
|
2831
|
+
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);
|
|
2702
2832
|
if (!hasStripeWebhookHandler) return [];
|
|
2703
2833
|
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 [];
|
|
2704
2834
|
const handlerPatterns = [
|
|
@@ -3514,10 +3644,12 @@ var missingHTTPS = {
|
|
|
3514
3644
|
category: "Configuration",
|
|
3515
3645
|
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3516
3646
|
check(content, filePath) {
|
|
3517
|
-
const
|
|
3518
|
-
const
|
|
3519
|
-
if (filePath.endsWith(".example") ||
|
|
3520
|
-
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
3647
|
+
const baseName2 = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
3648
|
+
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);
|
|
3649
|
+
if (filePath.endsWith(".example") || vc032SkipsTests || filePath.includes("README")) return [];
|
|
3650
|
+
if (filePath.match(/\.(md|txt|rst)$/)) return [];
|
|
3651
|
+
if (/(?:^|\/)(?:doc|docs)\//i.test(filePath)) return [];
|
|
3652
|
+
if (/(?:^|\/)conf\.py$/i.test(filePath) && /intersphinx/i.test(content)) return [];
|
|
3521
3653
|
const matches = [];
|
|
3522
3654
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3523
3655
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
@@ -3533,6 +3665,8 @@ var missingHTTPS = {
|
|
|
3533
3665
|
for (const rm of rawMatches) {
|
|
3534
3666
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3535
3667
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3668
|
+
if (/["']\$schema["']\s*:|["']\$id["']\s*:/.test(matchText)) continue;
|
|
3669
|
+
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;
|
|
3536
3670
|
matches.push(rm);
|
|
3537
3671
|
}
|
|
3538
3672
|
return matches;
|
|
@@ -3873,11 +4007,13 @@ var GRADE_SEVERITY_RANK = {
|
|
|
3873
4007
|
low: 1,
|
|
3874
4008
|
info: 0
|
|
3875
4009
|
};
|
|
4010
|
+
var ADVISORY_FAMILY_RE = /^(?:GHSA-|CVE-\d|OSV-|DEP\d)/i;
|
|
3876
4011
|
function gradeRuleFamily(finding) {
|
|
3877
4012
|
const rule = (finding.rule ?? "").trim();
|
|
4013
|
+
const id = finding.id ?? "";
|
|
4014
|
+
if (ADVISORY_FAMILY_RE.test(rule) || ADVISORY_FAMILY_RE.test(id)) return "ADVISORY";
|
|
3878
4015
|
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3879
4016
|
if (rule) return rule;
|
|
3880
|
-
const id = finding.id ?? "";
|
|
3881
4017
|
if (id === "ENTROPY" || id.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3882
4018
|
return id || "unknown";
|
|
3883
4019
|
}
|
|
@@ -3904,9 +4040,27 @@ function findingsCountedTowardGrade(findings) {
|
|
|
3904
4040
|
return counted;
|
|
3905
4041
|
}
|
|
3906
4042
|
function calculateGrade(findings, _totalFiles, options = {}) {
|
|
3907
|
-
const scored =
|
|
4043
|
+
const scored = findings.filter((f) => !isUngradedFinding(f, options));
|
|
3908
4044
|
const ungraded = findings.length - scored.length;
|
|
3909
|
-
|
|
4045
|
+
let testHeld = 0;
|
|
4046
|
+
let vendoredHeld = 0;
|
|
4047
|
+
for (const f of findings) {
|
|
4048
|
+
if (!isUngradedFinding(f, options)) continue;
|
|
4049
|
+
if (isTestPath(f.file ?? "")) testHeld++;
|
|
4050
|
+
else vendoredHeld++;
|
|
4051
|
+
}
|
|
4052
|
+
const holdoutParts = [];
|
|
4053
|
+
if (vendoredHeld > 0) {
|
|
4054
|
+
holdoutParts.push(
|
|
4055
|
+
`${vendoredHeld} finding${vendoredHeld === 1 ? "" : "s"} in vendored, generated, or documentation files ${vendoredHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
4056
|
+
);
|
|
4057
|
+
}
|
|
4058
|
+
if (testHeld > 0) {
|
|
4059
|
+
holdoutParts.push(
|
|
4060
|
+
`${testHeld} finding${testHeld === 1 ? "" : "s"} in a test or fixture file, not counted toward the grade, ${testHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
const holdout = holdoutParts.length > 0 ? ` ${holdoutParts.join(" ")}` : "";
|
|
3910
4064
|
if (scored.length === 0) {
|
|
3911
4065
|
return {
|
|
3912
4066
|
grade: "A+",
|
|
@@ -4442,6 +4596,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4442
4596
|
}
|
|
4443
4597
|
if (maxLineLen > 5e4) return findings;
|
|
4444
4598
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4599
|
+
if (isSbomPath(filePath)) return findings;
|
|
4445
4600
|
const vendoredFile = isVendoredPath(filePath);
|
|
4446
4601
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4447
4602
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
@@ -4450,12 +4605,21 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4450
4605
|
const matches = rule.check(content, filePath, project);
|
|
4451
4606
|
const compliance = complianceMap[rule.id];
|
|
4452
4607
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
4608
|
+
const onTestPath = isTestPath(filePath);
|
|
4453
4609
|
for (const match of matches) {
|
|
4454
4610
|
if (silenceableLines && isLineSilenced(silenceableLines, match.line - 1, match.rule)) {
|
|
4455
4611
|
continue;
|
|
4456
4612
|
}
|
|
4613
|
+
const live = isLive({
|
|
4614
|
+
rule: match.rule,
|
|
4615
|
+
category: match.category,
|
|
4616
|
+
live: match.live,
|
|
4617
|
+
snippet: match.snippet
|
|
4618
|
+
});
|
|
4457
4619
|
findings.push({
|
|
4458
4620
|
...vendored ? { vendored: true } : {},
|
|
4621
|
+
...onTestPath && !live ? { testFile: true } : {},
|
|
4622
|
+
...live ? { live: true } : {},
|
|
4459
4623
|
id: `${match.rule}-${match.file}:${match.line}`,
|
|
4460
4624
|
rule: match.rule,
|
|
4461
4625
|
severity: match.severity,
|
|
@@ -4850,20 +5014,6 @@ var SAFE_PATTERNS = [
|
|
|
4850
5014
|
];
|
|
4851
5015
|
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;
|
|
4852
5016
|
var SKIP_FILENAMES = /(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|composer\.lock|Gemfile\.lock|Cargo\.lock|poetry\.lock|Pipfile\.lock|shrinkwrap\.json)$/i;
|
|
4853
|
-
var SKIP_SBOM_FILES = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json)$/i;
|
|
4854
|
-
function isEntropyTestPath(filePath) {
|
|
4855
|
-
const normalized = filePath.replace(/\\/g, "/");
|
|
4856
|
-
if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(normalized)) return true;
|
|
4857
|
-
if (/(?:^|\/)(?:tests|spec)\//i.test(normalized)) return true;
|
|
4858
|
-
if (/(?:^|\/)test\//i.test(normalized) && !/(?:^|\/)routes\/test\//i.test(normalized)) return true;
|
|
4859
|
-
if (/(?:^|\/)[^/]+\.Tests\//.test(normalized)) return true;
|
|
4860
|
-
const base = normalized.split("/").pop() ?? "";
|
|
4861
|
-
if (/^test_.*\.py$/i.test(base)) return true;
|
|
4862
|
-
if (/_test\.py$/i.test(base)) return true;
|
|
4863
|
-
if (/^Test[A-Z_]\w*\.py$/.test(base)) return true;
|
|
4864
|
-
if (/_test\.go$/.test(base)) return true;
|
|
4865
|
-
return false;
|
|
4866
|
-
}
|
|
4867
5017
|
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;
|
|
4868
5018
|
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;
|
|
4869
5019
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
@@ -4890,11 +5040,11 @@ function scanEntropy(files) {
|
|
|
4890
5040
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
4891
5041
|
const basename = filePath.split("/").pop() || "";
|
|
4892
5042
|
if (SKIP_FILENAMES.test(basename)) continue;
|
|
4893
|
-
if (
|
|
5043
|
+
if (isSbomPath(filePath) || isSbomPath(basename)) continue;
|
|
4894
5044
|
if (filePath.includes("node_modules")) continue;
|
|
4895
5045
|
if (filePath.includes(".min.")) continue;
|
|
4896
5046
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
4897
|
-
if (
|
|
5047
|
+
if (isTestPath(filePath)) continue;
|
|
4898
5048
|
const vendored = isVendoredPath(filePath);
|
|
4899
5049
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
4900
5050
|
const lines = content.split("\n");
|
|
@@ -5199,6 +5349,7 @@ function getSnippet3(content, line) {
|
|
|
5199
5349
|
function scanDependencies(files) {
|
|
5200
5350
|
const findings = [];
|
|
5201
5351
|
for (const { path: filePath, content } of files) {
|
|
5352
|
+
if (isSbomPath(filePath)) continue;
|
|
5202
5353
|
if (filePath.endsWith("package.json") && !filePath.includes("node_modules")) {
|
|
5203
5354
|
try {
|
|
5204
5355
|
const pkg = JSON.parse(content);
|
|
@@ -5544,6 +5695,7 @@ var CONFIG_CHECKS = [
|
|
|
5544
5695
|
function scanConfigs(files) {
|
|
5545
5696
|
const findings = [];
|
|
5546
5697
|
for (const { path: filePath, content } of files) {
|
|
5698
|
+
if (isSbomPath(filePath)) continue;
|
|
5547
5699
|
for (const check of CONFIG_CHECKS) {
|
|
5548
5700
|
if (!check.filePattern.test(filePath)) continue;
|
|
5549
5701
|
const result = check.check(content, filePath);
|
|
@@ -5581,6 +5733,7 @@ function getSnippet5(content, line) {
|
|
|
5581
5733
|
}).join("\n");
|
|
5582
5734
|
}
|
|
5583
5735
|
function scanMultiFile(files) {
|
|
5736
|
+
files = files.filter((f) => !isSbomPath(f.path));
|
|
5584
5737
|
const findings = [];
|
|
5585
5738
|
const fileMap = /* @__PURE__ */ new Map();
|
|
5586
5739
|
for (const f of files) {
|
|
@@ -5931,7 +6084,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
5931
6084
|
|
|
5932
6085
|
// src/quality/context.ts
|
|
5933
6086
|
function isExcludedPath(path) {
|
|
5934
|
-
if (
|
|
6087
|
+
if (isTestPath(path)) return true;
|
|
5935
6088
|
if (/(?:^|\/)[\w.-]*(?:fixtures?|mocks?|examples?|samples?)\//i.test(path)) return true;
|
|
5936
6089
|
if (isVendoredPath(path)) return true;
|
|
5937
6090
|
if (/(?:^|\/)(?:\.next|dist|build|out|coverage|node_modules)\//.test(path)) return true;
|
|
@@ -7744,8 +7897,8 @@ function hasOpenStateEarlyReturn(fn) {
|
|
|
7744
7897
|
}
|
|
7745
7898
|
return false;
|
|
7746
7899
|
}
|
|
7747
|
-
function isOpenGated(element, parents,
|
|
7748
|
-
if (MODAL_FILENAME.test(
|
|
7900
|
+
function isOpenGated(element, parents, baseName2) {
|
|
7901
|
+
if (MODAL_FILENAME.test(baseName2)) return true;
|
|
7749
7902
|
let child = element;
|
|
7750
7903
|
let parent = parents.get(child);
|
|
7751
7904
|
for (let steps = 0; parent && steps < 256; steps++) {
|
|
@@ -7788,7 +7941,7 @@ var undeclaredModal = {
|
|
|
7788
7941
|
if (DIALOG_PRIMITIVE.test(file.code)) continue;
|
|
7789
7942
|
const program = parsed.ast.program;
|
|
7790
7943
|
const parents = buildParents(program);
|
|
7791
|
-
const
|
|
7944
|
+
const baseName2 = baseNameWithoutExtension(file.path);
|
|
7792
7945
|
const elements = [];
|
|
7793
7946
|
walkNodes2(program, (node) => {
|
|
7794
7947
|
if (node.type === "JSXElement") elements.push(node);
|
|
@@ -7803,7 +7956,7 @@ var undeclaredModal = {
|
|
|
7803
7956
|
if (!rendersElementChild(element)) continue;
|
|
7804
7957
|
if (!hasFocusableDescendant(element)) continue;
|
|
7805
7958
|
if (declaresSemantics(element)) continue;
|
|
7806
|
-
if (!isOpenGated(element, parents,
|
|
7959
|
+
if (!isOpenGated(element, parents, baseName2)) continue;
|
|
7807
7960
|
const line = opening.loc?.start.line ?? lineAt(file.content, opening.start ?? 0);
|
|
7808
7961
|
hits.push({ file: file.path, line });
|
|
7809
7962
|
break;
|
|
@@ -9512,11 +9665,15 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9512
9665
|
isInlineSilenced,
|
|
9513
9666
|
isInsideFixMessage,
|
|
9514
9667
|
isLineSilenced,
|
|
9668
|
+
isLive,
|
|
9515
9669
|
isMethodCall,
|
|
9516
9670
|
isPrivateAddress,
|
|
9671
|
+
isSbomPath,
|
|
9517
9672
|
isServerSideFile,
|
|
9518
9673
|
isServerTarget,
|
|
9519
9674
|
isTestFile,
|
|
9675
|
+
isTestPath,
|
|
9676
|
+
isUngradedFinding,
|
|
9520
9677
|
isVendoredFinding,
|
|
9521
9678
|
isVendoredPath,
|
|
9522
9679
|
lineNumberAt,
|