xploitscan-shared-rules 2.3.0 → 2.4.0
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 +186 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -9
- package/dist/index.d.ts +78 -9
- package/dist/index.js +182 -39
- 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,89 @@ 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 (/(?:^|\/)routes\/test\//i.test(normalized)) return false;
|
|
637
|
+
if (/(?:^|\/)(?:tests|testdata|spec|__tests__|__mocks__|fixtures?|mocks?)(?:\/|$)/i.test(normalized)) return true;
|
|
638
|
+
if (/(?:^|\/)test\//i.test(normalized)) return true;
|
|
639
|
+
if (/(?:^|\/)[^/]*\.(?:UnitTests|IntegrationTests|Tests)\//i.test(normalized)) return true;
|
|
640
|
+
if (/test-utils/i.test(normalized)) return true;
|
|
641
|
+
if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
645
|
+
function isSbomPath(filePath) {
|
|
646
|
+
return SBOM_FILE_RE.test(normalize(filePath));
|
|
647
|
+
}
|
|
648
|
+
function isPlaceholderToken(token) {
|
|
649
|
+
if (!token) return true;
|
|
650
|
+
if (/(.)\1{7,}/.test(token)) return true;
|
|
651
|
+
if (new Set(token).size < 8) return true;
|
|
652
|
+
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me|\b(?:test|fake|dummy|sample|your)\b/i.test(token);
|
|
653
|
+
}
|
|
654
|
+
var LIVE_TOKEN_SOURCES = [
|
|
655
|
+
String.raw`(?:sk|rk)_live_[A-Za-z0-9]+`,
|
|
656
|
+
// OpenAI (`T3BlbkFJ` sits in every sk-proj- / sk-svcacct- / sk-admin- / legacy
|
|
657
|
+
// sk- key) and OpenRouter. A bare `sk-` is not a provider format.
|
|
658
|
+
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}`,
|
|
659
|
+
String.raw`sk-or-v1-[a-f0-9]{64}`,
|
|
660
|
+
String.raw`sk-ant-api03-[A-Za-z0-9_-]{80,}`,
|
|
661
|
+
String.raw`ghp_[A-Za-z0-9]{36}`,
|
|
662
|
+
String.raw`github_pat_[A-Za-z0-9_]{22,}`,
|
|
663
|
+
String.raw`xox[a-z]-[0-9A-Za-z-]{10,}`,
|
|
664
|
+
String.raw`AIza[A-Za-z0-9_-]{35}`,
|
|
665
|
+
String.raw`SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}`,
|
|
666
|
+
String.raw`\bhf_[A-Za-z]{34}\b`,
|
|
667
|
+
String.raw`(?:AKIA|ABIA|ACCA|ASIA)[A-Z0-9]{16}`
|
|
668
|
+
];
|
|
669
|
+
function providerTokens(text) {
|
|
670
|
+
if (!text) return [];
|
|
671
|
+
const out = [];
|
|
672
|
+
for (const source of LIVE_TOKEN_SOURCES) {
|
|
673
|
+
const found = text.match(new RegExp(source, "g"));
|
|
674
|
+
if (found) out.push(...found);
|
|
675
|
+
}
|
|
676
|
+
return out;
|
|
677
|
+
}
|
|
678
|
+
function tokenIsLive(token) {
|
|
679
|
+
if (isPlaceholderToken(token)) return false;
|
|
680
|
+
if (/^(?:AKIA|ABIA|ACCA|ASIA)/.test(token) && /EXAMPLE$/i.test(token)) return false;
|
|
681
|
+
return true;
|
|
682
|
+
}
|
|
683
|
+
function isLive(finding) {
|
|
684
|
+
const rule = finding?.rule ?? "";
|
|
685
|
+
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return false;
|
|
686
|
+
if (rule === "VC002" || rule === "VC014") return false;
|
|
687
|
+
if (rule === "VC001") return finding?.live === true;
|
|
688
|
+
if (finding?.live === true) return true;
|
|
689
|
+
const snippet = finding?.snippet ?? "";
|
|
690
|
+
if (providerTokens(snippet).length > 0 && !textHasLiveCredential(snippet)) return false;
|
|
691
|
+
return finding?.category === "Secrets";
|
|
692
|
+
}
|
|
693
|
+
function textHasLiveCredential(text) {
|
|
694
|
+
return providerTokens(text).some(tokenIsLive);
|
|
695
|
+
}
|
|
696
|
+
function isUngradedFinding(finding, options = {}) {
|
|
697
|
+
if (isTestPath(finding?.file ?? "")) return !isLive(finding);
|
|
698
|
+
if (options.gradeVendored) return false;
|
|
699
|
+
return isVendoredFinding(finding);
|
|
700
|
+
}
|
|
701
|
+
|
|
615
702
|
// src/routes.ts
|
|
616
703
|
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
617
704
|
var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
|
|
@@ -627,7 +714,7 @@ function hasDep(files, name) {
|
|
|
627
714
|
return false;
|
|
628
715
|
}
|
|
629
716
|
}
|
|
630
|
-
function
|
|
717
|
+
function normalize2(p) {
|
|
631
718
|
if (!p.startsWith("/")) return "";
|
|
632
719
|
if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
|
|
633
720
|
return p;
|
|
@@ -636,7 +723,7 @@ function extractRoutes(files) {
|
|
|
636
723
|
const routes = /* @__PURE__ */ new Map();
|
|
637
724
|
const frameworks = /* @__PURE__ */ new Set();
|
|
638
725
|
const add = (raw, framework, source, kindOverride) => {
|
|
639
|
-
const path =
|
|
726
|
+
const path = normalize2(raw);
|
|
640
727
|
if (!path || routes.has(path)) return;
|
|
641
728
|
routes.set(path, {
|
|
642
729
|
path,
|
|
@@ -1648,7 +1735,7 @@ function callSpreads(call, matcher) {
|
|
|
1648
1735
|
// src/rules.ts
|
|
1649
1736
|
var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.story\.|\/test\/|\/tests\/|\/fixtures?\/|\/mocks?\/|\.mock\.|test-utils|testing|\.cy\.|\.e2e\.)/i;
|
|
1650
1737
|
function isTestFile(filePath) {
|
|
1651
|
-
return
|
|
1738
|
+
return isTestPath(filePath);
|
|
1652
1739
|
}
|
|
1653
1740
|
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
1741
|
function maskComments(content) {
|
|
@@ -1863,11 +1950,6 @@ function isNamespacedSlotKey(name, value) {
|
|
|
1863
1950
|
}
|
|
1864
1951
|
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
1952
|
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
1953
|
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
1954
|
var GEMINI_NAME_RE = /gemini|generative/i;
|
|
1873
1955
|
var PUBLIC_GOOGLE_KEY_NAME_RE = /firebase|maps?(?:\b|_)|places|recaptcha|youtube/i;
|
|
@@ -1884,6 +1966,39 @@ function isGeminiKeyContext(lines, line, fileIsGemini) {
|
|
|
1884
1966
|
}
|
|
1885
1967
|
return fileIsGemini || GEMINI_NAME_RE.test(before);
|
|
1886
1968
|
}
|
|
1969
|
+
function dbUrlLacksRealCredential(url) {
|
|
1970
|
+
const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
|
|
1971
|
+
const at = rest.lastIndexOf("@");
|
|
1972
|
+
if (at < 0) return true;
|
|
1973
|
+
const userinfo = rest.slice(0, at);
|
|
1974
|
+
const colon = userinfo.indexOf(":");
|
|
1975
|
+
const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
|
|
1976
|
+
const pass = colon < 0 ? "" : decodeURIComponentSafe(userinfo.slice(colon + 1));
|
|
1977
|
+
if (!pass) return true;
|
|
1978
|
+
if (isFormatPlaceholder(pass)) return true;
|
|
1979
|
+
if (isPlaceholderSecret(pass)) return true;
|
|
1980
|
+
if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
|
|
1981
|
+
return false;
|
|
1982
|
+
}
|
|
1983
|
+
function decodeURIComponentSafe(value) {
|
|
1984
|
+
try {
|
|
1985
|
+
return decodeURIComponent(value);
|
|
1986
|
+
} catch {
|
|
1987
|
+
return value;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
var FORMAT_PLACEHOLDER_MAX = 256;
|
|
1991
|
+
function isFormatPlaceholder(value) {
|
|
1992
|
+
const v = value.trim();
|
|
1993
|
+
if (!v) return true;
|
|
1994
|
+
if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
|
|
1995
|
+
if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
|
|
1996
|
+
if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
|
|
1997
|
+
return false;
|
|
1998
|
+
}
|
|
1999
|
+
function isPlaceholderSecret(value) {
|
|
2000
|
+
return /^(?:password|passwd|pwd|changeme|change[-_]?me|your[-_]?password)$/i.test(value.trim());
|
|
2001
|
+
}
|
|
1887
2002
|
var hardcodedSecrets = {
|
|
1888
2003
|
id: "VC001",
|
|
1889
2004
|
title: "Hardcoded API Key or Secret",
|
|
@@ -1892,7 +2007,6 @@ var hardcodedSecrets = {
|
|
|
1892
2007
|
description: "API keys, tokens, or secrets hardcoded in source code can be extracted by anyone with access to the code.",
|
|
1893
2008
|
check(content, filePath) {
|
|
1894
2009
|
if (filePath.endsWith(".example") || filePath.endsWith(".template")) return [];
|
|
1895
|
-
if (isTestFile(filePath)) return [];
|
|
1896
2010
|
if (filePath.match(/\.(md|txt|rst|adoc)$/)) return [];
|
|
1897
2011
|
const patterns = [
|
|
1898
2012
|
// Generic API key patterns — require actual value assignment, not variable declarations
|
|
@@ -2026,13 +2140,17 @@ var hardcodedSecrets = {
|
|
|
2026
2140
|
if (isPlaceholderToken(token)) continue;
|
|
2027
2141
|
if (pi === GOOGLE_PI) {
|
|
2028
2142
|
if (!isGeminiKeyContext(lines, rm.line, fileIsGemini)) continue;
|
|
2029
|
-
matches.push({ ...rm, severity: "high" });
|
|
2143
|
+
matches.push(textHasLiveCredential(token) ? { ...rm, severity: "high", live: true } : { ...rm, severity: "high" });
|
|
2030
2144
|
continue;
|
|
2031
2145
|
}
|
|
2032
2146
|
if (pi === STRIPE_RESTRICTED_PI && !token.startsWith("rk_live_")) {
|
|
2033
2147
|
matches.push({ ...rm, severity: "high" });
|
|
2034
2148
|
continue;
|
|
2035
2149
|
}
|
|
2150
|
+
if (textHasLiveCredential(token)) {
|
|
2151
|
+
matches.push({ ...rm, live: true });
|
|
2152
|
+
continue;
|
|
2153
|
+
}
|
|
2036
2154
|
}
|
|
2037
2155
|
if (floor > 0) {
|
|
2038
2156
|
const secretMatch = lineText.match(/[:=]\s*["'`]([^"'`]*)["'`]/);
|
|
@@ -2048,7 +2166,9 @@ var hardcodedSecrets = {
|
|
|
2048
2166
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
2049
2167
|
}
|
|
2050
2168
|
}
|
|
2051
|
-
|
|
2169
|
+
if (pi === 10 && dbUrlLacksRealCredential(matchedText[ri] ?? "")) continue;
|
|
2170
|
+
const matched = matchedText[ri] ?? "";
|
|
2171
|
+
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
2052
2172
|
}
|
|
2053
2173
|
}
|
|
2054
2174
|
return matches;
|
|
@@ -3514,10 +3634,12 @@ var missingHTTPS = {
|
|
|
3514
3634
|
category: "Configuration",
|
|
3515
3635
|
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3516
3636
|
check(content, filePath) {
|
|
3517
|
-
const
|
|
3518
|
-
const
|
|
3519
|
-
if (filePath.endsWith(".example") ||
|
|
3520
|
-
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
3637
|
+
const baseName2 = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
3638
|
+
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);
|
|
3639
|
+
if (filePath.endsWith(".example") || vc032SkipsTests || filePath.includes("README")) return [];
|
|
3640
|
+
if (filePath.match(/\.(md|txt|rst)$/)) return [];
|
|
3641
|
+
if (/(?:^|\/)(?:doc|docs)\//i.test(filePath)) return [];
|
|
3642
|
+
if (/(?:^|\/)conf\.py$/i.test(filePath) && /intersphinx/i.test(content)) return [];
|
|
3521
3643
|
const matches = [];
|
|
3522
3644
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3523
3645
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
@@ -3533,6 +3655,8 @@ var missingHTTPS = {
|
|
|
3533
3655
|
for (const rm of rawMatches) {
|
|
3534
3656
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3535
3657
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3658
|
+
if (/["']\$schema["']\s*:|["']\$id["']\s*:/.test(matchText)) continue;
|
|
3659
|
+
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
3660
|
matches.push(rm);
|
|
3537
3661
|
}
|
|
3538
3662
|
return matches;
|
|
@@ -3873,11 +3997,13 @@ var GRADE_SEVERITY_RANK = {
|
|
|
3873
3997
|
low: 1,
|
|
3874
3998
|
info: 0
|
|
3875
3999
|
};
|
|
4000
|
+
var ADVISORY_FAMILY_RE = /^(?:GHSA-|CVE-\d|OSV-|DEP\d)/i;
|
|
3876
4001
|
function gradeRuleFamily(finding) {
|
|
3877
4002
|
const rule = (finding.rule ?? "").trim();
|
|
4003
|
+
const id = finding.id ?? "";
|
|
4004
|
+
if (ADVISORY_FAMILY_RE.test(rule) || ADVISORY_FAMILY_RE.test(id)) return "ADVISORY";
|
|
3878
4005
|
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3879
4006
|
if (rule) return rule;
|
|
3880
|
-
const id = finding.id ?? "";
|
|
3881
4007
|
if (id === "ENTROPY" || id.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3882
4008
|
return id || "unknown";
|
|
3883
4009
|
}
|
|
@@ -3904,9 +4030,27 @@ function findingsCountedTowardGrade(findings) {
|
|
|
3904
4030
|
return counted;
|
|
3905
4031
|
}
|
|
3906
4032
|
function calculateGrade(findings, _totalFiles, options = {}) {
|
|
3907
|
-
const scored =
|
|
4033
|
+
const scored = findings.filter((f) => !isUngradedFinding(f, options));
|
|
3908
4034
|
const ungraded = findings.length - scored.length;
|
|
3909
|
-
|
|
4035
|
+
let testHeld = 0;
|
|
4036
|
+
let vendoredHeld = 0;
|
|
4037
|
+
for (const f of findings) {
|
|
4038
|
+
if (!isUngradedFinding(f, options)) continue;
|
|
4039
|
+
if (isTestPath(f.file ?? "")) testHeld++;
|
|
4040
|
+
else vendoredHeld++;
|
|
4041
|
+
}
|
|
4042
|
+
const holdoutParts = [];
|
|
4043
|
+
if (vendoredHeld > 0) {
|
|
4044
|
+
holdoutParts.push(
|
|
4045
|
+
`${vendoredHeld} finding${vendoredHeld === 1 ? "" : "s"} in vendored, generated, or documentation files ${vendoredHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
4046
|
+
);
|
|
4047
|
+
}
|
|
4048
|
+
if (testHeld > 0) {
|
|
4049
|
+
holdoutParts.push(
|
|
4050
|
+
`${testHeld} finding${testHeld === 1 ? "" : "s"} in a test or fixture file, not counted toward the grade, ${testHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
4051
|
+
);
|
|
4052
|
+
}
|
|
4053
|
+
const holdout = holdoutParts.length > 0 ? ` ${holdoutParts.join(" ")}` : "";
|
|
3910
4054
|
if (scored.length === 0) {
|
|
3911
4055
|
return {
|
|
3912
4056
|
grade: "A+",
|
|
@@ -4442,6 +4586,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4442
4586
|
}
|
|
4443
4587
|
if (maxLineLen > 5e4) return findings;
|
|
4444
4588
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4589
|
+
if (isSbomPath(filePath)) return findings;
|
|
4445
4590
|
const vendoredFile = isVendoredPath(filePath);
|
|
4446
4591
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4447
4592
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
@@ -4450,12 +4595,21 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4450
4595
|
const matches = rule.check(content, filePath, project);
|
|
4451
4596
|
const compliance = complianceMap[rule.id];
|
|
4452
4597
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
4598
|
+
const onTestPath = isTestPath(filePath);
|
|
4453
4599
|
for (const match of matches) {
|
|
4454
4600
|
if (silenceableLines && isLineSilenced(silenceableLines, match.line - 1, match.rule)) {
|
|
4455
4601
|
continue;
|
|
4456
4602
|
}
|
|
4603
|
+
const live = isLive({
|
|
4604
|
+
rule: match.rule,
|
|
4605
|
+
category: match.category,
|
|
4606
|
+
live: match.live,
|
|
4607
|
+
snippet: match.snippet
|
|
4608
|
+
});
|
|
4457
4609
|
findings.push({
|
|
4458
4610
|
...vendored ? { vendored: true } : {},
|
|
4611
|
+
...onTestPath && !live ? { testFile: true } : {},
|
|
4612
|
+
...live ? { live: true } : {},
|
|
4459
4613
|
id: `${match.rule}-${match.file}:${match.line}`,
|
|
4460
4614
|
rule: match.rule,
|
|
4461
4615
|
severity: match.severity,
|
|
@@ -4850,20 +5004,6 @@ var SAFE_PATTERNS = [
|
|
|
4850
5004
|
];
|
|
4851
5005
|
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
5006
|
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
5007
|
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
5008
|
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
5009
|
var HASH_PREFIX_RE = /^(?:sha\d+|md5|crc32|base64|bcrypt|argon2|pbkdf2|blake2b?)[:_]/i;
|
|
@@ -4890,11 +5030,11 @@ function scanEntropy(files) {
|
|
|
4890
5030
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
4891
5031
|
const basename = filePath.split("/").pop() || "";
|
|
4892
5032
|
if (SKIP_FILENAMES.test(basename)) continue;
|
|
4893
|
-
if (
|
|
5033
|
+
if (isSbomPath(filePath) || isSbomPath(basename)) continue;
|
|
4894
5034
|
if (filePath.includes("node_modules")) continue;
|
|
4895
5035
|
if (filePath.includes(".min.")) continue;
|
|
4896
5036
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
4897
|
-
if (
|
|
5037
|
+
if (isTestPath(filePath)) continue;
|
|
4898
5038
|
const vendored = isVendoredPath(filePath);
|
|
4899
5039
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
4900
5040
|
const lines = content.split("\n");
|
|
@@ -5199,6 +5339,7 @@ function getSnippet3(content, line) {
|
|
|
5199
5339
|
function scanDependencies(files) {
|
|
5200
5340
|
const findings = [];
|
|
5201
5341
|
for (const { path: filePath, content } of files) {
|
|
5342
|
+
if (isSbomPath(filePath)) continue;
|
|
5202
5343
|
if (filePath.endsWith("package.json") && !filePath.includes("node_modules")) {
|
|
5203
5344
|
try {
|
|
5204
5345
|
const pkg = JSON.parse(content);
|
|
@@ -5544,6 +5685,7 @@ var CONFIG_CHECKS = [
|
|
|
5544
5685
|
function scanConfigs(files) {
|
|
5545
5686
|
const findings = [];
|
|
5546
5687
|
for (const { path: filePath, content } of files) {
|
|
5688
|
+
if (isSbomPath(filePath)) continue;
|
|
5547
5689
|
for (const check of CONFIG_CHECKS) {
|
|
5548
5690
|
if (!check.filePattern.test(filePath)) continue;
|
|
5549
5691
|
const result = check.check(content, filePath);
|
|
@@ -5581,6 +5723,7 @@ function getSnippet5(content, line) {
|
|
|
5581
5723
|
}).join("\n");
|
|
5582
5724
|
}
|
|
5583
5725
|
function scanMultiFile(files) {
|
|
5726
|
+
files = files.filter((f) => !isSbomPath(f.path));
|
|
5584
5727
|
const findings = [];
|
|
5585
5728
|
const fileMap = /* @__PURE__ */ new Map();
|
|
5586
5729
|
for (const f of files) {
|
|
@@ -5931,7 +6074,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
5931
6074
|
|
|
5932
6075
|
// src/quality/context.ts
|
|
5933
6076
|
function isExcludedPath(path) {
|
|
5934
|
-
if (
|
|
6077
|
+
if (isTestPath(path)) return true;
|
|
5935
6078
|
if (/(?:^|\/)[\w.-]*(?:fixtures?|mocks?|examples?|samples?)\//i.test(path)) return true;
|
|
5936
6079
|
if (isVendoredPath(path)) return true;
|
|
5937
6080
|
if (/(?:^|\/)(?:\.next|dist|build|out|coverage|node_modules)\//.test(path)) return true;
|
|
@@ -7744,8 +7887,8 @@ function hasOpenStateEarlyReturn(fn) {
|
|
|
7744
7887
|
}
|
|
7745
7888
|
return false;
|
|
7746
7889
|
}
|
|
7747
|
-
function isOpenGated(element, parents,
|
|
7748
|
-
if (MODAL_FILENAME.test(
|
|
7890
|
+
function isOpenGated(element, parents, baseName2) {
|
|
7891
|
+
if (MODAL_FILENAME.test(baseName2)) return true;
|
|
7749
7892
|
let child = element;
|
|
7750
7893
|
let parent = parents.get(child);
|
|
7751
7894
|
for (let steps = 0; parent && steps < 256; steps++) {
|
|
@@ -7788,7 +7931,7 @@ var undeclaredModal = {
|
|
|
7788
7931
|
if (DIALOG_PRIMITIVE.test(file.code)) continue;
|
|
7789
7932
|
const program = parsed.ast.program;
|
|
7790
7933
|
const parents = buildParents(program);
|
|
7791
|
-
const
|
|
7934
|
+
const baseName2 = baseNameWithoutExtension(file.path);
|
|
7792
7935
|
const elements = [];
|
|
7793
7936
|
walkNodes2(program, (node) => {
|
|
7794
7937
|
if (node.type === "JSXElement") elements.push(node);
|
|
@@ -7803,7 +7946,7 @@ var undeclaredModal = {
|
|
|
7803
7946
|
if (!rendersElementChild(element)) continue;
|
|
7804
7947
|
if (!hasFocusableDescendant(element)) continue;
|
|
7805
7948
|
if (declaresSemantics(element)) continue;
|
|
7806
|
-
if (!isOpenGated(element, parents,
|
|
7949
|
+
if (!isOpenGated(element, parents, baseName2)) continue;
|
|
7807
7950
|
const line = opening.loc?.start.line ?? lineAt(file.content, opening.start ?? 0);
|
|
7808
7951
|
hits.push({ file: file.path, line });
|
|
7809
7952
|
break;
|
|
@@ -9512,11 +9655,15 @@ function scanQuality(input, rules = qualityRules) {
|
|
|
9512
9655
|
isInlineSilenced,
|
|
9513
9656
|
isInsideFixMessage,
|
|
9514
9657
|
isLineSilenced,
|
|
9658
|
+
isLive,
|
|
9515
9659
|
isMethodCall,
|
|
9516
9660
|
isPrivateAddress,
|
|
9661
|
+
isSbomPath,
|
|
9517
9662
|
isServerSideFile,
|
|
9518
9663
|
isServerTarget,
|
|
9519
9664
|
isTestFile,
|
|
9665
|
+
isTestPath,
|
|
9666
|
+
isUngradedFinding,
|
|
9520
9667
|
isVendoredFinding,
|
|
9521
9668
|
isVendoredPath,
|
|
9522
9669
|
lineNumberAt,
|