xploitscan-shared-rules 2.2.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 +323 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -2
- package/dist/index.d.ts +96 -2
- package/dist/index.js +317 -55
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
package/dist/index.js
CHANGED
|
@@ -390,6 +390,15 @@ var NON_APP_PATH_PATTERNS = [
|
|
|
390
390
|
"**/vendor/**",
|
|
391
391
|
"**/vendored/**",
|
|
392
392
|
"**/third_party/**",
|
|
393
|
+
// Hyphen, closed, and plural spellings. `third_party` alone left
|
|
394
|
+
// `third-party/licenses/*.spdx.json` in the grade.
|
|
395
|
+
"**/third-party/**",
|
|
396
|
+
"**/thirdparty/**",
|
|
397
|
+
"**/third_parties/**",
|
|
398
|
+
"**/third-parties/**",
|
|
399
|
+
"**/3rd_party/**",
|
|
400
|
+
"**/3rd-party/**",
|
|
401
|
+
"**/3rdparty/**",
|
|
393
402
|
"**/generated/**",
|
|
394
403
|
"**/__generated__/**"
|
|
395
404
|
];
|
|
@@ -453,6 +462,89 @@ function vendoredReason(filePath) {
|
|
|
453
462
|
return null;
|
|
454
463
|
}
|
|
455
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 (/(?:^|\/)routes\/test\//i.test(normalized)) return false;
|
|
483
|
+
if (/(?:^|\/)(?:tests|testdata|spec|__tests__|__mocks__|fixtures?|mocks?)(?:\/|$)/i.test(normalized)) return true;
|
|
484
|
+
if (/(?:^|\/)test\//i.test(normalized)) return true;
|
|
485
|
+
if (/(?:^|\/)[^/]*\.(?:UnitTests|IntegrationTests|Tests)\//i.test(normalized)) return true;
|
|
486
|
+
if (/test-utils/i.test(normalized)) return true;
|
|
487
|
+
if (/(?:^|\/)testing(?:\/|$)/i.test(normalized)) return true;
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
var SBOM_FILE_RE = /(?:^|\/)(?:[^/]*\.spdx(?:\.json)?|[^/]*\.cdx\.json|[^/]*\.cdx\.xml|bom\.json|sbom[^/]*\.json|[^/]*\.sbom\.json|[^/]*cyclonedx[^/]*\.(?:json|xml))$/i;
|
|
491
|
+
function isSbomPath(filePath) {
|
|
492
|
+
return SBOM_FILE_RE.test(normalize(filePath));
|
|
493
|
+
}
|
|
494
|
+
function isPlaceholderToken(token) {
|
|
495
|
+
if (!token) return true;
|
|
496
|
+
if (/(.)\1{7,}/.test(token)) return true;
|
|
497
|
+
if (new Set(token).size < 8) return true;
|
|
498
|
+
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me|\b(?:test|fake|dummy|sample|your)\b/i.test(token);
|
|
499
|
+
}
|
|
500
|
+
var LIVE_TOKEN_SOURCES = [
|
|
501
|
+
String.raw`(?:sk|rk)_live_[A-Za-z0-9]+`,
|
|
502
|
+
// OpenAI (`T3BlbkFJ` sits in every sk-proj- / sk-svcacct- / sk-admin- / legacy
|
|
503
|
+
// sk- key) and OpenRouter. A bare `sk-` is not a provider format.
|
|
504
|
+
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}`,
|
|
505
|
+
String.raw`sk-or-v1-[a-f0-9]{64}`,
|
|
506
|
+
String.raw`sk-ant-api03-[A-Za-z0-9_-]{80,}`,
|
|
507
|
+
String.raw`ghp_[A-Za-z0-9]{36}`,
|
|
508
|
+
String.raw`github_pat_[A-Za-z0-9_]{22,}`,
|
|
509
|
+
String.raw`xox[a-z]-[0-9A-Za-z-]{10,}`,
|
|
510
|
+
String.raw`AIza[A-Za-z0-9_-]{35}`,
|
|
511
|
+
String.raw`SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}`,
|
|
512
|
+
String.raw`\bhf_[A-Za-z]{34}\b`,
|
|
513
|
+
String.raw`(?:AKIA|ABIA|ACCA|ASIA)[A-Z0-9]{16}`
|
|
514
|
+
];
|
|
515
|
+
function providerTokens(text) {
|
|
516
|
+
if (!text) return [];
|
|
517
|
+
const out = [];
|
|
518
|
+
for (const source of LIVE_TOKEN_SOURCES) {
|
|
519
|
+
const found = text.match(new RegExp(source, "g"));
|
|
520
|
+
if (found) out.push(...found);
|
|
521
|
+
}
|
|
522
|
+
return out;
|
|
523
|
+
}
|
|
524
|
+
function tokenIsLive(token) {
|
|
525
|
+
if (isPlaceholderToken(token)) return false;
|
|
526
|
+
if (/^(?:AKIA|ABIA|ACCA|ASIA)/.test(token) && /EXAMPLE$/i.test(token)) return false;
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
function isLive(finding) {
|
|
530
|
+
const rule = finding?.rule ?? "";
|
|
531
|
+
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return false;
|
|
532
|
+
if (rule === "VC002" || rule === "VC014") return false;
|
|
533
|
+
if (rule === "VC001") return finding?.live === true;
|
|
534
|
+
if (finding?.live === true) return true;
|
|
535
|
+
const snippet = finding?.snippet ?? "";
|
|
536
|
+
if (providerTokens(snippet).length > 0 && !textHasLiveCredential(snippet)) return false;
|
|
537
|
+
return finding?.category === "Secrets";
|
|
538
|
+
}
|
|
539
|
+
function textHasLiveCredential(text) {
|
|
540
|
+
return providerTokens(text).some(tokenIsLive);
|
|
541
|
+
}
|
|
542
|
+
function isUngradedFinding(finding, options = {}) {
|
|
543
|
+
if (isTestPath(finding?.file ?? "")) return !isLive(finding);
|
|
544
|
+
if (options.gradeVendored) return false;
|
|
545
|
+
return isVendoredFinding(finding);
|
|
546
|
+
}
|
|
547
|
+
|
|
456
548
|
// src/routes.ts
|
|
457
549
|
var API_RE = /^\/api(\/|$)|^\/_|\.(json|js|xml|txt|ico)$/;
|
|
458
550
|
var DYNAMIC_RE = /:[A-Za-z_]|\[[^\]]+\]|<[^>]+>|\$[A-Za-z_]|\*/;
|
|
@@ -468,7 +560,7 @@ function hasDep(files, name) {
|
|
|
468
560
|
return false;
|
|
469
561
|
}
|
|
470
562
|
}
|
|
471
|
-
function
|
|
563
|
+
function normalize2(p) {
|
|
472
564
|
if (!p.startsWith("/")) return "";
|
|
473
565
|
if (p.length > 1 && p.endsWith("/")) return p.replace(/\/+$/, "");
|
|
474
566
|
return p;
|
|
@@ -477,7 +569,7 @@ function extractRoutes(files) {
|
|
|
477
569
|
const routes = /* @__PURE__ */ new Map();
|
|
478
570
|
const frameworks = /* @__PURE__ */ new Set();
|
|
479
571
|
const add = (raw, framework, source, kindOverride) => {
|
|
480
|
-
const path =
|
|
572
|
+
const path = normalize2(raw);
|
|
481
573
|
if (!path || routes.has(path)) return;
|
|
482
574
|
routes.set(path, {
|
|
483
575
|
path,
|
|
@@ -1489,7 +1581,7 @@ function callSpreads(call, matcher) {
|
|
|
1489
1581
|
// src/rules.ts
|
|
1490
1582
|
var TEST_FILE_PATTERN = /(?:\.test\.|\.spec\.|__tests__|__mocks__|\.stories\.|\.story\.|\/test\/|\/tests\/|\/fixtures?\/|\/mocks?\/|\.mock\.|test-utils|testing|\.cy\.|\.e2e\.)/i;
|
|
1491
1583
|
function isTestFile(filePath) {
|
|
1492
|
-
return
|
|
1584
|
+
return isTestPath(filePath);
|
|
1493
1585
|
}
|
|
1494
1586
|
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;
|
|
1495
1587
|
function maskComments(content) {
|
|
@@ -1704,11 +1796,6 @@ function isNamespacedSlotKey(name, value) {
|
|
|
1704
1796
|
}
|
|
1705
1797
|
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/;
|
|
1706
1798
|
var CREDENTIAL_WORD = /secret|passw|token|private|signing|apikey|credential/i;
|
|
1707
|
-
function isPlaceholderToken(token) {
|
|
1708
|
-
if (/(.)\1{7,}/.test(token)) return true;
|
|
1709
|
-
if (new Set(token).size < 8) return true;
|
|
1710
|
-
return /example|placeholder|redacted|your_?(?:api_?)?(?:key|token)|insert_?your|replace_?me/i.test(token);
|
|
1711
|
-
}
|
|
1712
1799
|
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/;
|
|
1713
1800
|
var GEMINI_NAME_RE = /gemini|generative/i;
|
|
1714
1801
|
var PUBLIC_GOOGLE_KEY_NAME_RE = /firebase|maps?(?:\b|_)|places|recaptcha|youtube/i;
|
|
@@ -1725,6 +1812,39 @@ function isGeminiKeyContext(lines, line, fileIsGemini) {
|
|
|
1725
1812
|
}
|
|
1726
1813
|
return fileIsGemini || GEMINI_NAME_RE.test(before);
|
|
1727
1814
|
}
|
|
1815
|
+
function dbUrlLacksRealCredential(url) {
|
|
1816
|
+
const rest = url.replace(/^[a-z0-9+]+:\/\//i, "");
|
|
1817
|
+
const at = rest.lastIndexOf("@");
|
|
1818
|
+
if (at < 0) return true;
|
|
1819
|
+
const userinfo = rest.slice(0, at);
|
|
1820
|
+
const colon = userinfo.indexOf(":");
|
|
1821
|
+
const user = colon < 0 ? userinfo : userinfo.slice(0, colon);
|
|
1822
|
+
const pass = colon < 0 ? "" : decodeURIComponentSafe(userinfo.slice(colon + 1));
|
|
1823
|
+
if (!pass) return true;
|
|
1824
|
+
if (isFormatPlaceholder(pass)) return true;
|
|
1825
|
+
if (isPlaceholderSecret(pass)) return true;
|
|
1826
|
+
if (/^(?:u|user|username)$/i.test(user) && /^(?:pass|password|passwd|pwd)$/i.test(pass)) return true;
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
function decodeURIComponentSafe(value) {
|
|
1830
|
+
try {
|
|
1831
|
+
return decodeURIComponent(value);
|
|
1832
|
+
} catch {
|
|
1833
|
+
return value;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
var FORMAT_PLACEHOLDER_MAX = 256;
|
|
1837
|
+
function isFormatPlaceholder(value) {
|
|
1838
|
+
const v = value.trim();
|
|
1839
|
+
if (!v) return true;
|
|
1840
|
+
if (v.length > FORMAT_PLACEHOLDER_MAX) return false;
|
|
1841
|
+
if (/^(?:%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>|\*+)$/i.test(v)) return true;
|
|
1842
|
+
if (/%(?:[%sdifvx]|\([^)]+\))|\{[0-9]*\}|\$\{[^}]*\}|<[^<>]*>/.test(v)) return true;
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
function isPlaceholderSecret(value) {
|
|
1846
|
+
return /^(?:password|passwd|pwd|changeme|change[-_]?me|your[-_]?password)$/i.test(value.trim());
|
|
1847
|
+
}
|
|
1728
1848
|
var hardcodedSecrets = {
|
|
1729
1849
|
id: "VC001",
|
|
1730
1850
|
title: "Hardcoded API Key or Secret",
|
|
@@ -1733,7 +1853,6 @@ var hardcodedSecrets = {
|
|
|
1733
1853
|
description: "API keys, tokens, or secrets hardcoded in source code can be extracted by anyone with access to the code.",
|
|
1734
1854
|
check(content, filePath) {
|
|
1735
1855
|
if (filePath.endsWith(".example") || filePath.endsWith(".template")) return [];
|
|
1736
|
-
if (isTestFile(filePath)) return [];
|
|
1737
1856
|
if (filePath.match(/\.(md|txt|rst|adoc)$/)) return [];
|
|
1738
1857
|
const patterns = [
|
|
1739
1858
|
// Generic API key patterns — require actual value assignment, not variable declarations
|
|
@@ -1867,13 +1986,17 @@ var hardcodedSecrets = {
|
|
|
1867
1986
|
if (isPlaceholderToken(token)) continue;
|
|
1868
1987
|
if (pi === GOOGLE_PI) {
|
|
1869
1988
|
if (!isGeminiKeyContext(lines, rm.line, fileIsGemini)) continue;
|
|
1870
|
-
matches.push({ ...rm, severity: "high" });
|
|
1989
|
+
matches.push(textHasLiveCredential(token) ? { ...rm, severity: "high", live: true } : { ...rm, severity: "high" });
|
|
1871
1990
|
continue;
|
|
1872
1991
|
}
|
|
1873
1992
|
if (pi === STRIPE_RESTRICTED_PI && !token.startsWith("rk_live_")) {
|
|
1874
1993
|
matches.push({ ...rm, severity: "high" });
|
|
1875
1994
|
continue;
|
|
1876
1995
|
}
|
|
1996
|
+
if (textHasLiveCredential(token)) {
|
|
1997
|
+
matches.push({ ...rm, live: true });
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
1877
2000
|
}
|
|
1878
2001
|
if (floor > 0) {
|
|
1879
2002
|
const secretMatch = lineText.match(/[:=]\s*["'`]([^"'`]*)["'`]/);
|
|
@@ -1889,7 +2012,9 @@ var hardcodedSecrets = {
|
|
|
1889
2012
|
if (isKeySuffix && isSlotIdentifier) continue;
|
|
1890
2013
|
}
|
|
1891
2014
|
}
|
|
1892
|
-
|
|
2015
|
+
if (pi === 10 && dbUrlLacksRealCredential(matchedText[ri] ?? "")) continue;
|
|
2016
|
+
const matched = matchedText[ri] ?? "";
|
|
2017
|
+
matches.push(textHasLiveCredential(matched) ? { ...rm, live: true } : rm);
|
|
1893
2018
|
}
|
|
1894
2019
|
}
|
|
1895
2020
|
return matches;
|
|
@@ -3355,10 +3480,12 @@ var missingHTTPS = {
|
|
|
3355
3480
|
category: "Configuration",
|
|
3356
3481
|
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3357
3482
|
check(content, filePath) {
|
|
3358
|
-
const
|
|
3359
|
-
const
|
|
3360
|
-
if (filePath.endsWith(".example") ||
|
|
3361
|
-
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
3483
|
+
const baseName2 = filePath.slice(filePath.lastIndexOf("/") + 1);
|
|
3484
|
+
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);
|
|
3485
|
+
if (filePath.endsWith(".example") || vc032SkipsTests || filePath.includes("README")) return [];
|
|
3486
|
+
if (filePath.match(/\.(md|txt|rst)$/)) return [];
|
|
3487
|
+
if (/(?:^|\/)(?:doc|docs)\//i.test(filePath)) return [];
|
|
3488
|
+
if (/(?:^|\/)conf\.py$/i.test(filePath) && /intersphinx/i.test(content)) return [];
|
|
3362
3489
|
const matches = [];
|
|
3363
3490
|
const isScriptFile = /\.(?:[cm]?[jt]sx?|vue|svelte)$/i.test(filePath);
|
|
3364
3491
|
if (!isScriptFile && /<!DOCTYPE|xmlns|\.dtd|\.xsd/i.test(content) && !/fetch|axios|request|http\.get/i.test(content)) return [];
|
|
@@ -3374,6 +3501,8 @@ var missingHTTPS = {
|
|
|
3374
3501
|
for (const rm of rawMatches) {
|
|
3375
3502
|
const matchText = lines[rm.line - 1] ?? "";
|
|
3376
3503
|
if (/DTD|DOCTYPE|w3\.org|apple\.com\/DTDs|\bxmlns[\w:-]*\s*=/i.test(matchText)) continue;
|
|
3504
|
+
if (/["']\$schema["']\s*:|["']\$id["']\s*:/.test(matchText)) continue;
|
|
3505
|
+
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;
|
|
3377
3506
|
matches.push(rm);
|
|
3378
3507
|
}
|
|
3379
3508
|
return matches;
|
|
@@ -3706,10 +3835,68 @@ function detectPlatform(files) {
|
|
|
3706
3835
|
}
|
|
3707
3836
|
return [...platforms];
|
|
3708
3837
|
}
|
|
3838
|
+
var GRADE_FINDINGS_PER_RULE = 3;
|
|
3839
|
+
var GRADE_SEVERITY_RANK = {
|
|
3840
|
+
critical: 4,
|
|
3841
|
+
high: 3,
|
|
3842
|
+
medium: 2,
|
|
3843
|
+
low: 1,
|
|
3844
|
+
info: 0
|
|
3845
|
+
};
|
|
3846
|
+
var ADVISORY_FAMILY_RE = /^(?:GHSA-|CVE-\d|OSV-|DEP\d)/i;
|
|
3847
|
+
function gradeRuleFamily(finding) {
|
|
3848
|
+
const rule = (finding.rule ?? "").trim();
|
|
3849
|
+
const id = finding.id ?? "";
|
|
3850
|
+
if (ADVISORY_FAMILY_RE.test(rule) || ADVISORY_FAMILY_RE.test(id)) return "ADVISORY";
|
|
3851
|
+
if (rule === "ENTROPY" || rule.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3852
|
+
if (rule) return rule;
|
|
3853
|
+
if (id === "ENTROPY" || id.startsWith("ENTROPY-")) return "ENTROPY";
|
|
3854
|
+
return id || "unknown";
|
|
3855
|
+
}
|
|
3856
|
+
function isDeductingSeverity(severity) {
|
|
3857
|
+
return severity === "critical" || severity === "high" || severity === "medium" || severity === "low";
|
|
3858
|
+
}
|
|
3859
|
+
function findingsCountedTowardGrade(findings) {
|
|
3860
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3861
|
+
findings.forEach((item, index) => {
|
|
3862
|
+
const key = gradeRuleFamily(item);
|
|
3863
|
+
const bucket = groups.get(key);
|
|
3864
|
+
const entry = { item, index };
|
|
3865
|
+
if (bucket) bucket.push(entry);
|
|
3866
|
+
else groups.set(key, [entry]);
|
|
3867
|
+
});
|
|
3868
|
+
const counted = [];
|
|
3869
|
+
for (const bucket of groups.values()) {
|
|
3870
|
+
const ranked = bucket.length <= GRADE_FINDINGS_PER_RULE ? bucket : [...bucket].sort((a, b) => {
|
|
3871
|
+
const bySeverity = (GRADE_SEVERITY_RANK[b.item.severity ?? ""] ?? 0) - (GRADE_SEVERITY_RANK[a.item.severity ?? ""] ?? 0);
|
|
3872
|
+
return bySeverity !== 0 ? bySeverity : a.index - b.index;
|
|
3873
|
+
}).slice(0, GRADE_FINDINGS_PER_RULE);
|
|
3874
|
+
for (const entry of ranked) counted.push(entry.item);
|
|
3875
|
+
}
|
|
3876
|
+
return counted;
|
|
3877
|
+
}
|
|
3709
3878
|
function calculateGrade(findings, _totalFiles, options = {}) {
|
|
3710
|
-
const scored =
|
|
3879
|
+
const scored = findings.filter((f) => !isUngradedFinding(f, options));
|
|
3711
3880
|
const ungraded = findings.length - scored.length;
|
|
3712
|
-
|
|
3881
|
+
let testHeld = 0;
|
|
3882
|
+
let vendoredHeld = 0;
|
|
3883
|
+
for (const f of findings) {
|
|
3884
|
+
if (!isUngradedFinding(f, options)) continue;
|
|
3885
|
+
if (isTestPath(f.file ?? "")) testHeld++;
|
|
3886
|
+
else vendoredHeld++;
|
|
3887
|
+
}
|
|
3888
|
+
const holdoutParts = [];
|
|
3889
|
+
if (vendoredHeld > 0) {
|
|
3890
|
+
holdoutParts.push(
|
|
3891
|
+
`${vendoredHeld} finding${vendoredHeld === 1 ? "" : "s"} in vendored, generated, or documentation files ${vendoredHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
3892
|
+
);
|
|
3893
|
+
}
|
|
3894
|
+
if (testHeld > 0) {
|
|
3895
|
+
holdoutParts.push(
|
|
3896
|
+
`${testHeld} finding${testHeld === 1 ? "" : "s"} in a test or fixture file, not counted toward the grade, ${testHeld === 1 ? "is" : "are"} reported but not graded.`
|
|
3897
|
+
);
|
|
3898
|
+
}
|
|
3899
|
+
const holdout = holdoutParts.length > 0 ? ` ${holdoutParts.join(" ")}` : "";
|
|
3713
3900
|
if (scored.length === 0) {
|
|
3714
3901
|
return {
|
|
3715
3902
|
grade: "A+",
|
|
@@ -3718,13 +3905,22 @@ function calculateGrade(findings, _totalFiles, options = {}) {
|
|
|
3718
3905
|
ungraded
|
|
3719
3906
|
};
|
|
3720
3907
|
}
|
|
3908
|
+
const counted = findingsCountedTowardGrade(scored);
|
|
3721
3909
|
let critical = 0, high = 0, medium = 0, low = 0;
|
|
3722
|
-
for (const f of
|
|
3910
|
+
for (const f of counted) {
|
|
3723
3911
|
if (f.severity === "critical") critical++;
|
|
3724
3912
|
else if (f.severity === "high") high++;
|
|
3725
3913
|
else if (f.severity === "medium") medium++;
|
|
3726
3914
|
else if (f.severity === "low") low++;
|
|
3727
3915
|
}
|
|
3916
|
+
let rawCritical = 0, rawHigh = 0, rawMedium = 0, rawLow = 0;
|
|
3917
|
+
for (const f of scored) {
|
|
3918
|
+
if (f.severity === "critical") rawCritical++;
|
|
3919
|
+
else if (f.severity === "high") rawHigh++;
|
|
3920
|
+
else if (f.severity === "medium") rawMedium++;
|
|
3921
|
+
else if (f.severity === "low") rawLow++;
|
|
3922
|
+
}
|
|
3923
|
+
const omitted = scored.filter((f) => isDeductingSeverity(f.severity)).length - counted.filter((f) => isDeductingSeverity(f.severity)).length;
|
|
3728
3924
|
const deductions = critical * 15 + high * 7 + medium * 3 + low * 1;
|
|
3729
3925
|
const rawScore = Math.max(0, 100 - deductions);
|
|
3730
3926
|
let grade;
|
|
@@ -3744,22 +3940,23 @@ function calculateGrade(findings, _totalFiles, options = {}) {
|
|
|
3744
3940
|
else if (medium >= 5) grade = capGrade("B");
|
|
3745
3941
|
else if (medium >= 1) grade = capGrade("A");
|
|
3746
3942
|
let summary;
|
|
3747
|
-
if (
|
|
3748
|
-
summary = `${
|
|
3749
|
-
} else if (
|
|
3750
|
-
summary = `${
|
|
3751
|
-
} else if (
|
|
3752
|
-
summary = `${
|
|
3753
|
-
} else if (
|
|
3754
|
-
summary = `${
|
|
3755
|
-
} else if (
|
|
3756
|
-
summary = `Clean of critical and high issues. ${
|
|
3757
|
-
} else if (
|
|
3758
|
-
summary = `Clean of critical, high, and medium issues. ${
|
|
3943
|
+
if (rawCritical > 0) {
|
|
3944
|
+
summary = `${rawCritical} critical ${rawCritical === 1 ? "vulnerability requires" : "vulnerabilities require"} immediate attention.`;
|
|
3945
|
+
} else if (rawHigh >= 3) {
|
|
3946
|
+
summary = `${rawHigh} high-severity issues require urgent attention.`;
|
|
3947
|
+
} else if (rawHigh > 0) {
|
|
3948
|
+
summary = `${rawHigh} high-severity ${rawHigh === 1 ? "issue needs" : "issues need"} attention.`;
|
|
3949
|
+
} else if (rawMedium >= 5) {
|
|
3950
|
+
summary = `${rawMedium} medium-severity issues to address.`;
|
|
3951
|
+
} else if (rawMedium > 0) {
|
|
3952
|
+
summary = `Clean of critical and high issues. ${rawMedium} medium-severity ${rawMedium === 1 ? "issue" : "issues"} to review.`;
|
|
3953
|
+
} else if (rawLow > 0) {
|
|
3954
|
+
summary = `Clean of critical, high, and medium issues. ${rawLow} low-severity best-practice ${rawLow === 1 ? "note" : "notes"}.`;
|
|
3759
3955
|
} else {
|
|
3760
3956
|
summary = "No security issues detected.";
|
|
3761
3957
|
}
|
|
3762
|
-
|
|
3958
|
+
const capNote = omitted > 0 ? ` ${omitted} more ${omitted === 1 ? "finding was" : "findings were"} not deducted (at most ${GRADE_FINDINGS_PER_RULE} findings per rule count toward the score and the severity caps).` : "";
|
|
3959
|
+
return { grade, score: rawScore, summary: summary + capNote + holdout, ungraded };
|
|
3763
3960
|
}
|
|
3764
3961
|
var complianceMap = {
|
|
3765
3962
|
VC001: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
@@ -4235,6 +4432,7 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4235
4432
|
}
|
|
4236
4433
|
if (maxLineLen > 5e4) return findings;
|
|
4237
4434
|
if (/demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
4435
|
+
if (isSbomPath(filePath)) return findings;
|
|
4238
4436
|
const vendoredFile = isVendoredPath(filePath);
|
|
4239
4437
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
4240
4438
|
const silenceableLines = /-OK\b/i.test(content) ? content.split("\n") : null;
|
|
@@ -4243,12 +4441,21 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
4243
4441
|
const matches = rule.check(content, filePath, project);
|
|
4244
4442
|
const compliance = complianceMap[rule.id];
|
|
4245
4443
|
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
4444
|
+
const onTestPath = isTestPath(filePath);
|
|
4246
4445
|
for (const match of matches) {
|
|
4247
4446
|
if (silenceableLines && isLineSilenced(silenceableLines, match.line - 1, match.rule)) {
|
|
4248
4447
|
continue;
|
|
4249
4448
|
}
|
|
4449
|
+
const live = isLive({
|
|
4450
|
+
rule: match.rule,
|
|
4451
|
+
category: match.category,
|
|
4452
|
+
live: match.live,
|
|
4453
|
+
snippet: match.snippet
|
|
4454
|
+
});
|
|
4250
4455
|
findings.push({
|
|
4251
4456
|
...vendored ? { vendored: true } : {},
|
|
4457
|
+
...onTestPath && !live ? { testFile: true } : {},
|
|
4458
|
+
...live ? { live: true } : {},
|
|
4252
4459
|
id: `${match.rule}-${match.file}:${match.line}`,
|
|
4253
4460
|
rule: match.rule,
|
|
4254
4461
|
severity: match.severity,
|
|
@@ -4313,6 +4520,20 @@ var MAX_CONCURRENT = (() => {
|
|
|
4313
4520
|
if (!Number.isFinite(n) || n < 1) return DEFAULT_MAX_CONCURRENT;
|
|
4314
4521
|
return Math.min(n, 20);
|
|
4315
4522
|
})();
|
|
4523
|
+
var DEFAULT_AI_FILTER_BUDGET_MS = 8e3;
|
|
4524
|
+
var AI_FILTER_BUDGET_MS = (() => {
|
|
4525
|
+
const raw = process.env.AI_FILTER_BUDGET_MS;
|
|
4526
|
+
if (!raw) return DEFAULT_AI_FILTER_BUDGET_MS;
|
|
4527
|
+
const n = parseInt(raw, 10);
|
|
4528
|
+
if (!Number.isFinite(n) || n < 1) return DEFAULT_AI_FILTER_BUDGET_MS;
|
|
4529
|
+
return Math.min(n, 6e4);
|
|
4530
|
+
})();
|
|
4531
|
+
var PER_CALL_TIMEOUT_MS = 8e3;
|
|
4532
|
+
function isAbortError(err) {
|
|
4533
|
+
if (!err || typeof err !== "object") return false;
|
|
4534
|
+
const name = "name" in err ? String(err.name) : "";
|
|
4535
|
+
return name === "AbortError" || name === "APIUserAbortError";
|
|
4536
|
+
}
|
|
4316
4537
|
var SEVERITY_PRIORITY = {
|
|
4317
4538
|
critical: 0,
|
|
4318
4539
|
high: 1,
|
|
@@ -4363,10 +4584,18 @@ function parseReviewResponse(text) {
|
|
|
4363
4584
|
return [];
|
|
4364
4585
|
}
|
|
4365
4586
|
}
|
|
4366
|
-
async function filterFalsePositives(findings, fileContents) {
|
|
4587
|
+
async function filterFalsePositives(findings, fileContents, budgetMs = AI_FILTER_BUDGET_MS) {
|
|
4367
4588
|
const empty = { findings, filteredFindings: [], aiReviewed: false, removedCount: 0, totalBefore: findings.length, unreviewedCount: 0 };
|
|
4368
4589
|
if (!process.env.ANTHROPIC_API_KEY) return empty;
|
|
4369
4590
|
if (findings.length === 0) return empty;
|
|
4591
|
+
const deadlineMs = Date.now() + Math.max(0, budgetMs);
|
|
4592
|
+
const abortController = new AbortController();
|
|
4593
|
+
let budgetExpired = budgetMs <= 0;
|
|
4594
|
+
if (budgetExpired) abortController.abort();
|
|
4595
|
+
const budgetTimer = budgetExpired ? void 0 : setTimeout(() => {
|
|
4596
|
+
budgetExpired = true;
|
|
4597
|
+
abortController.abort();
|
|
4598
|
+
}, budgetMs);
|
|
4370
4599
|
const prioritized = [...findings].sort((a, b) => {
|
|
4371
4600
|
const pa = SEVERITY_PRIORITY[(a.severity || "").toLowerCase()] ?? 5;
|
|
4372
4601
|
const pb = SEVERITY_PRIORITY[(b.severity || "").toLowerCase()] ?? 5;
|
|
@@ -4402,7 +4631,13 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
4402
4631
|
}
|
|
4403
4632
|
const reviewBatch = async (task) => {
|
|
4404
4633
|
const { batch, content } = task;
|
|
4634
|
+
if (abortController.signal.aborted || Date.now() >= deadlineMs) {
|
|
4635
|
+
budgetExpired = true;
|
|
4636
|
+
unreviewedCount += batch.length;
|
|
4637
|
+
return;
|
|
4638
|
+
}
|
|
4405
4639
|
try {
|
|
4640
|
+
const remaining = Math.max(1, deadlineMs - Date.now());
|
|
4406
4641
|
const prompt = buildReviewPrompt(batch, content);
|
|
4407
4642
|
const response = await client.messages.create(
|
|
4408
4643
|
{
|
|
@@ -4422,12 +4657,9 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
4422
4657
|
system: REVIEW_SYSTEM_PROMPT,
|
|
4423
4658
|
messages: [{ role: "user", content: prompt }]
|
|
4424
4659
|
},
|
|
4425
|
-
//
|
|
4426
|
-
//
|
|
4427
|
-
|
|
4428
|
-
// (which would skip the graceful-degradation fallback). A timeout
|
|
4429
|
-
// turns a stuck batch into an unreviewed batch, handled below.
|
|
4430
|
-
{ timeout: 2e4 }
|
|
4660
|
+
// Shared AbortController plus a per-call timeout capped at remaining
|
|
4661
|
+
// budget. Previously 20s with no overall deadline.
|
|
4662
|
+
{ timeout: Math.min(PER_CALL_TIMEOUT_MS, remaining), signal: abortController.signal }
|
|
4431
4663
|
);
|
|
4432
4664
|
const text = response.content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
4433
4665
|
const results = parseReviewResponse(text);
|
|
@@ -4441,20 +4673,33 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
4441
4673
|
}
|
|
4442
4674
|
}
|
|
4443
4675
|
} catch (err) {
|
|
4444
|
-
failedBatches++;
|
|
4445
4676
|
unreviewedCount += batch.length;
|
|
4677
|
+
if (isAbortError(err) || abortController.signal.aborted) {
|
|
4678
|
+
budgetExpired = true;
|
|
4679
|
+
return;
|
|
4680
|
+
}
|
|
4681
|
+
failedBatches++;
|
|
4446
4682
|
if (!firstError) firstError = err;
|
|
4447
4683
|
}
|
|
4448
4684
|
};
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4685
|
+
try {
|
|
4686
|
+
let next = 0;
|
|
4687
|
+
const workerCount = Math.min(MAX_CONCURRENT, tasks.length);
|
|
4688
|
+
const workers = Array.from({ length: workerCount }, async () => {
|
|
4689
|
+
while (next < tasks.length) {
|
|
4690
|
+
const cur = next++;
|
|
4691
|
+
await reviewBatch(tasks[cur]);
|
|
4692
|
+
}
|
|
4693
|
+
});
|
|
4694
|
+
await Promise.all(workers);
|
|
4695
|
+
} finally {
|
|
4696
|
+
if (budgetTimer) clearTimeout(budgetTimer);
|
|
4697
|
+
}
|
|
4698
|
+
if (budgetExpired && unreviewedCount > 0) {
|
|
4699
|
+
console.warn(
|
|
4700
|
+
`[ai-fp-filter] budget expired (${budgetMs}ms) \u2014 ${unreviewedCount} finding(s) not reviewed; returning them unchanged`
|
|
4701
|
+
);
|
|
4702
|
+
}
|
|
4458
4703
|
if (firstError) {
|
|
4459
4704
|
const msg = firstError instanceof Error ? firstError.message : String(firstError);
|
|
4460
4705
|
if (!reviewedAny) {
|
|
@@ -4594,7 +4839,14 @@ var SAFE_PATTERNS = [
|
|
|
4594
4839
|
// HTTP security-header directive values (HSTS, etc.) — `max-age=63072000;
|
|
4595
4840
|
// includeSubDomains; preload`. Config strings a security scanner actively
|
|
4596
4841
|
// tells users to add; never secrets.
|
|
4597
|
-
/^max-age=\d+/i
|
|
4842
|
+
/^max-age=\d+/i,
|
|
4843
|
+
// SPDX element ids, package URLs, and URNs. SBOM and license documents are
|
|
4844
|
+
// full of these (`SPDXRef-Package-…`, `pkg:golang/…`, `urn:uuid:…`) and they
|
|
4845
|
+
// are identifiers, not credentials. The filename skip below drops whole
|
|
4846
|
+
// SBOM files; this catches the same strings in a file we still scan.
|
|
4847
|
+
/^SPDXRef-/,
|
|
4848
|
+
/^pkg:[a-z0-9.+-]+\//,
|
|
4849
|
+
/^urn:/
|
|
4598
4850
|
];
|
|
4599
4851
|
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;
|
|
4600
4852
|
var SKIP_FILENAMES = /(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|composer\.lock|Gemfile\.lock|Cargo\.lock|poetry\.lock|Pipfile\.lock|shrinkwrap\.json)$/i;
|
|
@@ -4624,10 +4876,11 @@ function scanEntropy(files) {
|
|
|
4624
4876
|
if (SKIP_FILENAMES.test(filePath)) continue;
|
|
4625
4877
|
const basename = filePath.split("/").pop() || "";
|
|
4626
4878
|
if (SKIP_FILENAMES.test(basename)) continue;
|
|
4879
|
+
if (isSbomPath(filePath) || isSbomPath(basename)) continue;
|
|
4627
4880
|
if (filePath.includes("node_modules")) continue;
|
|
4628
4881
|
if (filePath.includes(".min.")) continue;
|
|
4629
4882
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
4630
|
-
if (
|
|
4883
|
+
if (isTestPath(filePath)) continue;
|
|
4631
4884
|
const vendored = isVendoredPath(filePath);
|
|
4632
4885
|
const dotenv = isDotenvPath(filePath) && !DOTENV_EXAMPLE_RE.test(filePath);
|
|
4633
4886
|
const lines = content.split("\n");
|
|
@@ -4932,6 +5185,7 @@ function getSnippet3(content, line) {
|
|
|
4932
5185
|
function scanDependencies(files) {
|
|
4933
5186
|
const findings = [];
|
|
4934
5187
|
for (const { path: filePath, content } of files) {
|
|
5188
|
+
if (isSbomPath(filePath)) continue;
|
|
4935
5189
|
if (filePath.endsWith("package.json") && !filePath.includes("node_modules")) {
|
|
4936
5190
|
try {
|
|
4937
5191
|
const pkg = JSON.parse(content);
|
|
@@ -5277,6 +5531,7 @@ var CONFIG_CHECKS = [
|
|
|
5277
5531
|
function scanConfigs(files) {
|
|
5278
5532
|
const findings = [];
|
|
5279
5533
|
for (const { path: filePath, content } of files) {
|
|
5534
|
+
if (isSbomPath(filePath)) continue;
|
|
5280
5535
|
for (const check of CONFIG_CHECKS) {
|
|
5281
5536
|
if (!check.filePattern.test(filePath)) continue;
|
|
5282
5537
|
const result = check.check(content, filePath);
|
|
@@ -5314,6 +5569,7 @@ function getSnippet5(content, line) {
|
|
|
5314
5569
|
}).join("\n");
|
|
5315
5570
|
}
|
|
5316
5571
|
function scanMultiFile(files) {
|
|
5572
|
+
files = files.filter((f) => !isSbomPath(f.path));
|
|
5317
5573
|
const findings = [];
|
|
5318
5574
|
const fileMap = /* @__PURE__ */ new Map();
|
|
5319
5575
|
for (const f of files) {
|
|
@@ -5664,7 +5920,7 @@ function extractScriptUrls(html, pageUrl, limit = 12) {
|
|
|
5664
5920
|
|
|
5665
5921
|
// src/quality/context.ts
|
|
5666
5922
|
function isExcludedPath(path) {
|
|
5667
|
-
if (
|
|
5923
|
+
if (isTestPath(path)) return true;
|
|
5668
5924
|
if (/(?:^|\/)[\w.-]*(?:fixtures?|mocks?|examples?|samples?)\//i.test(path)) return true;
|
|
5669
5925
|
if (isVendoredPath(path)) return true;
|
|
5670
5926
|
if (/(?:^|\/)(?:\.next|dist|build|out|coverage|node_modules)\//.test(path)) return true;
|
|
@@ -7477,8 +7733,8 @@ function hasOpenStateEarlyReturn(fn) {
|
|
|
7477
7733
|
}
|
|
7478
7734
|
return false;
|
|
7479
7735
|
}
|
|
7480
|
-
function isOpenGated(element, parents,
|
|
7481
|
-
if (MODAL_FILENAME.test(
|
|
7736
|
+
function isOpenGated(element, parents, baseName2) {
|
|
7737
|
+
if (MODAL_FILENAME.test(baseName2)) return true;
|
|
7482
7738
|
let child = element;
|
|
7483
7739
|
let parent = parents.get(child);
|
|
7484
7740
|
for (let steps = 0; parent && steps < 256; steps++) {
|
|
@@ -7521,7 +7777,7 @@ var undeclaredModal = {
|
|
|
7521
7777
|
if (DIALOG_PRIMITIVE.test(file.code)) continue;
|
|
7522
7778
|
const program = parsed.ast.program;
|
|
7523
7779
|
const parents = buildParents(program);
|
|
7524
|
-
const
|
|
7780
|
+
const baseName2 = baseNameWithoutExtension(file.path);
|
|
7525
7781
|
const elements = [];
|
|
7526
7782
|
walkNodes2(program, (node) => {
|
|
7527
7783
|
if (node.type === "JSXElement") elements.push(node);
|
|
@@ -7536,7 +7792,7 @@ var undeclaredModal = {
|
|
|
7536
7792
|
if (!rendersElementChild(element)) continue;
|
|
7537
7793
|
if (!hasFocusableDescendant(element)) continue;
|
|
7538
7794
|
if (declaresSemantics(element)) continue;
|
|
7539
|
-
if (!isOpenGated(element, parents,
|
|
7795
|
+
if (!isOpenGated(element, parents, baseName2)) continue;
|
|
7540
7796
|
const line = opening.loc?.start.line ?? lineAt(file.content, opening.start ?? 0);
|
|
7541
7797
|
hits.push({ file: file.path, line });
|
|
7542
7798
|
break;
|
|
@@ -9176,6 +9432,7 @@ export {
|
|
|
9176
9432
|
CHECKABLE_CLAIMS,
|
|
9177
9433
|
DOTENV_ASSIGN_RE,
|
|
9178
9434
|
FREE_RULE_COUNT,
|
|
9435
|
+
GRADE_FINDINGS_PER_RULE,
|
|
9179
9436
|
INTENT_EXPECTATIONS,
|
|
9180
9437
|
MODEL_ANALYSIS,
|
|
9181
9438
|
MODEL_POLICY_REVIEWED,
|
|
@@ -9230,6 +9487,7 @@ export {
|
|
|
9230
9487
|
freeRules,
|
|
9231
9488
|
getObjectProperty,
|
|
9232
9489
|
getSnippet,
|
|
9490
|
+
gradeRuleFamily,
|
|
9233
9491
|
hardcodedJWTSecret,
|
|
9234
9492
|
hardcodedSecrets,
|
|
9235
9493
|
harvestIntent,
|
|
@@ -9242,11 +9500,15 @@ export {
|
|
|
9242
9500
|
isInlineSilenced,
|
|
9243
9501
|
isInsideFixMessage,
|
|
9244
9502
|
isLineSilenced,
|
|
9503
|
+
isLive,
|
|
9245
9504
|
isMethodCall,
|
|
9246
9505
|
isPrivateAddress,
|
|
9506
|
+
isSbomPath,
|
|
9247
9507
|
isServerSideFile,
|
|
9248
9508
|
isServerTarget,
|
|
9249
9509
|
isTestFile,
|
|
9510
|
+
isTestPath,
|
|
9511
|
+
isUngradedFinding,
|
|
9250
9512
|
isVendoredFinding,
|
|
9251
9513
|
isVendoredPath,
|
|
9252
9514
|
lineNumberAt,
|