xploitscan-shared-rules 1.14.4 → 1.15.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/dist/index.cjs +130 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +155 -2
- package/dist/index.d.ts +155 -2
- package/dist/index.js +125 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
NON_APP_PATH_PATTERNS: () => NON_APP_PATH_PATTERNS,
|
|
33
34
|
RULE_IMPACTS: () => RULE_IMPACTS,
|
|
34
35
|
allCustomRules: () => allCustomRules,
|
|
35
36
|
allRules: () => allRules,
|
|
@@ -156,6 +157,8 @@ __export(index_exports, {
|
|
|
156
157
|
ipcPathTraversal: () => ipcPathTraversal,
|
|
157
158
|
isCalleeNamed: () => isCalleeNamed,
|
|
158
159
|
isMethodCall: () => isMethodCall,
|
|
160
|
+
isVendoredFinding: () => isVendoredFinding,
|
|
161
|
+
isVendoredPath: () => isVendoredPath,
|
|
159
162
|
javaDeserialization: () => javaDeserialization,
|
|
160
163
|
jwtAlgConfusion: () => jwtAlgConfusion,
|
|
161
164
|
k8sNoResourceLimits: () => k8sNoResourceLimits,
|
|
@@ -196,6 +199,7 @@ __export(index_exports, {
|
|
|
196
199
|
nPlusOneQuery: () => nPlusOneQuery,
|
|
197
200
|
nextPublicSecret: () => nextPublicSecret,
|
|
198
201
|
noRateLimiting: () => noRateLimiting,
|
|
202
|
+
normalizeScanPath: () => normalizeScanPath,
|
|
199
203
|
nosqlInjection: () => nosqlInjection,
|
|
200
204
|
openRedirectParams: () => openRedirectParams,
|
|
201
205
|
overlyPermissiveIAM: () => overlyPermissiveIAM,
|
|
@@ -253,6 +257,7 @@ __export(index_exports, {
|
|
|
253
257
|
unvalidatedRedirect: () => unvalidatedRedirect,
|
|
254
258
|
vectorStoreQueryNoUserFilter: () => vectorStoreQueryNoUserFilter,
|
|
255
259
|
vectorStoreUpsertNoMetadata: () => vectorStoreUpsertNoMetadata,
|
|
260
|
+
vendoredReason: () => vendoredReason,
|
|
256
261
|
visitBinary: () => visitBinary,
|
|
257
262
|
visitCalls: () => visitCalls,
|
|
258
263
|
vulnerableDependencies: () => vulnerableDependencies,
|
|
@@ -550,6 +555,97 @@ function classifyExposure(filePath) {
|
|
|
550
555
|
return "unknown";
|
|
551
556
|
}
|
|
552
557
|
|
|
558
|
+
// src/vendored.ts
|
|
559
|
+
var NON_APP_PATH_PATTERNS = [
|
|
560
|
+
// 1. vendored UI component libraries
|
|
561
|
+
"**/components/ui/**",
|
|
562
|
+
"**/ui/shadcn/**",
|
|
563
|
+
"**/shadcn/ui/**",
|
|
564
|
+
"**/shadcn/**",
|
|
565
|
+
// 2. documentation prose
|
|
566
|
+
"**/*.md",
|
|
567
|
+
"**/*.mdx",
|
|
568
|
+
// 3. AI-agent and editor tooling artifacts. Each gets a `**/`-prefixed form
|
|
569
|
+
// as well as the root-anchored one: these directories turn up per-package
|
|
570
|
+
// in a monorepo, and a finding's `file` is occasionally an absolute path,
|
|
571
|
+
// which makes even a repo-root `.claude/` a nested segment.
|
|
572
|
+
".claude/**",
|
|
573
|
+
".agent/**",
|
|
574
|
+
".cursor/**",
|
|
575
|
+
".superpowers/**",
|
|
576
|
+
".windsurf/**",
|
|
577
|
+
"**/.claude/**",
|
|
578
|
+
"**/.agent/**",
|
|
579
|
+
"**/.cursor/**",
|
|
580
|
+
"**/.superpowers/**",
|
|
581
|
+
"**/.windsurf/**",
|
|
582
|
+
// 4. explicitly third-party or machine-generated trees
|
|
583
|
+
"**/vendor/**",
|
|
584
|
+
"**/vendored/**",
|
|
585
|
+
"**/third_party/**",
|
|
586
|
+
"**/generated/**",
|
|
587
|
+
"**/__generated__/**"
|
|
588
|
+
];
|
|
589
|
+
function globToRegExp(pattern) {
|
|
590
|
+
const segments = pattern.split("/");
|
|
591
|
+
let src = "^";
|
|
592
|
+
for (let i = 0; i < segments.length; i++) {
|
|
593
|
+
const seg = segments[i];
|
|
594
|
+
const isLast = i === segments.length - 1;
|
|
595
|
+
if (seg === "**") {
|
|
596
|
+
src += isLast ? ".+" : "(?:[^/]+/)*";
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
src += seg.replace(/[.*+?^${}()|[\]\\]/g, (ch) => ch === "*" ? "[^/]*" : "\\" + ch);
|
|
600
|
+
if (!isLast) src += "/";
|
|
601
|
+
}
|
|
602
|
+
return new RegExp(src + "$", "i");
|
|
603
|
+
}
|
|
604
|
+
var NON_APP_MATCHERS = NON_APP_PATH_PATTERNS.map(globToRegExp);
|
|
605
|
+
function normalizeScanPath(filePath) {
|
|
606
|
+
const raw = typeof filePath === "string" ? filePath : "";
|
|
607
|
+
const trimmed = raw.trim();
|
|
608
|
+
const looksWindows = !trimmed.includes("/") && trimmed.includes("\\");
|
|
609
|
+
const withForwardSlashes = (looksWindows ? trimmed.replace(/\\/g, "/") : trimmed).replace(/^[A-Za-z]:\//, "/");
|
|
610
|
+
const out = [];
|
|
611
|
+
for (const segment of withForwardSlashes.split("/")) {
|
|
612
|
+
if (segment === "" || segment === ".") continue;
|
|
613
|
+
if (segment === "..") {
|
|
614
|
+
if (out.length > 0 && out[out.length - 1] !== "..") out.pop();
|
|
615
|
+
else out.push("..");
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
out.push(segment);
|
|
619
|
+
}
|
|
620
|
+
return out.join("/");
|
|
621
|
+
}
|
|
622
|
+
function isVendoredPath(filePath) {
|
|
623
|
+
const normalized = normalizeScanPath(filePath);
|
|
624
|
+
if (!normalized) return false;
|
|
625
|
+
return NON_APP_MATCHERS.some((re) => re.test(normalized));
|
|
626
|
+
}
|
|
627
|
+
var HEURISTIC_SECRET_RULES = /* @__PURE__ */ new Set(["ENTROPY"]);
|
|
628
|
+
var ALWAYS_GRADED_RULES = /* @__PURE__ */ new Set(["VC115", "VC062"]);
|
|
629
|
+
function isAlwaysGraded(finding) {
|
|
630
|
+
const rule = finding?.rule ?? "";
|
|
631
|
+
if (ALWAYS_GRADED_RULES.has(rule)) return true;
|
|
632
|
+
if (finding?.category !== "Secrets") return false;
|
|
633
|
+
return !HEURISTIC_SECRET_RULES.has(rule);
|
|
634
|
+
}
|
|
635
|
+
function isVendoredFinding(finding) {
|
|
636
|
+
if (isAlwaysGraded(finding)) return false;
|
|
637
|
+
return isVendoredPath(finding?.file ?? "");
|
|
638
|
+
}
|
|
639
|
+
function vendoredReason(filePath) {
|
|
640
|
+
const normalized = normalizeScanPath(filePath);
|
|
641
|
+
if (!normalized) return null;
|
|
642
|
+
if (/\.mdx?$/.test(normalized)) return "documentation";
|
|
643
|
+
if (/(^|\/)(components\/ui|shadcn)(\/|$)/.test(normalized)) return "vendored UI component library";
|
|
644
|
+
if (/(^|\/)\.(claude|agent|cursor|superpowers|windsurf)(\/|$)/.test(normalized)) return "AI-agent tooling artifact";
|
|
645
|
+
if (isVendoredPath(normalized)) return "third-party or generated code";
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
|
|
553
649
|
// src/ast/parse.ts
|
|
554
650
|
var import_parser = require("@babel/parser");
|
|
555
651
|
var MAX_CACHE = 256;
|
|
@@ -4160,12 +4256,20 @@ function detectPlatform(files) {
|
|
|
4160
4256
|
}
|
|
4161
4257
|
return [...platforms];
|
|
4162
4258
|
}
|
|
4163
|
-
function calculateGrade(findings, _totalFiles) {
|
|
4164
|
-
|
|
4165
|
-
|
|
4259
|
+
function calculateGrade(findings, _totalFiles, options = {}) {
|
|
4260
|
+
const scored = options.gradeVendored ? findings : findings.filter((f) => !isVendoredFinding(f));
|
|
4261
|
+
const ungraded = findings.length - scored.length;
|
|
4262
|
+
const holdout = ungraded > 0 ? ` ${ungraded} finding${ungraded === 1 ? "" : "s"} in vendored, generated, or documentation files ${ungraded === 1 ? "is" : "are"} reported but not graded.` : "";
|
|
4263
|
+
if (scored.length === 0) {
|
|
4264
|
+
return {
|
|
4265
|
+
grade: "A+",
|
|
4266
|
+
score: 100,
|
|
4267
|
+
summary: (ungraded > 0 ? "No security issues detected in your own code." : "No security issues detected. Excellent.") + holdout,
|
|
4268
|
+
ungraded
|
|
4269
|
+
};
|
|
4166
4270
|
}
|
|
4167
4271
|
let critical = 0, high = 0, medium = 0, low = 0;
|
|
4168
|
-
for (const f of
|
|
4272
|
+
for (const f of scored) {
|
|
4169
4273
|
if (f.severity === "critical") critical++;
|
|
4170
4274
|
else if (f.severity === "high") high++;
|
|
4171
4275
|
else if (f.severity === "medium") medium++;
|
|
@@ -4205,7 +4309,7 @@ function calculateGrade(findings, _totalFiles) {
|
|
|
4205
4309
|
} else {
|
|
4206
4310
|
summary = "No security issues detected.";
|
|
4207
4311
|
}
|
|
4208
|
-
return { grade, score: rawScore, summary };
|
|
4312
|
+
return { grade, score: rawScore, summary: summary + holdout, ungraded };
|
|
4209
4313
|
}
|
|
4210
4314
|
var jwtAlgConfusion = {
|
|
4211
4315
|
id: "VC079",
|
|
@@ -8783,13 +8887,16 @@ function runCustomRules(content, filePath, disabledRules = [], tier = "free", ex
|
|
|
8783
8887
|
}
|
|
8784
8888
|
if (maxLineLen > 5e4) return findings;
|
|
8785
8889
|
if (/onboarding|demo-data|example-vulnerable|code-sample/i.test(filePath)) return findings;
|
|
8890
|
+
const vendoredFile = isVendoredPath(filePath);
|
|
8786
8891
|
const ruleset = tier === "pro" && extraRules.length > 0 ? [...freeRules, ...extraRules] : freeRules;
|
|
8787
8892
|
for (const rule of ruleset) {
|
|
8788
8893
|
if (disabledRules.includes(rule.id)) continue;
|
|
8789
8894
|
const matches = rule.check(content, filePath);
|
|
8790
8895
|
const compliance = complianceMap[rule.id];
|
|
8896
|
+
const vendored = vendoredFile && isVendoredFinding({ file: filePath, rule: rule.id, category: rule.category });
|
|
8791
8897
|
for (const match of matches) {
|
|
8792
8898
|
findings.push({
|
|
8899
|
+
...vendored ? { vendored: true } : {},
|
|
8793
8900
|
id: `${match.rule}-${match.file}:${match.line}`,
|
|
8794
8901
|
rule: match.rule,
|
|
8795
8902
|
severity: match.severity,
|
|
@@ -8944,6 +9051,17 @@ async function filterFalsePositives(findings, fileContents) {
|
|
|
8944
9051
|
{
|
|
8945
9052
|
model: "claude-haiku-4-5-20251001",
|
|
8946
9053
|
max_tokens: 1024,
|
|
9054
|
+
// Pinned, NOT left to the API default of 1.0. This is a binary
|
|
9055
|
+
// classification (real vs. false positive), not generation — there
|
|
9056
|
+
// is no upside to sampling variety and a real downside to it: a
|
|
9057
|
+
// filtered finding is a finding the user never sees, so drift here
|
|
9058
|
+
// means scanning the same unchanged code twice can yield different
|
|
9059
|
+
// results. Temperature 0 does not make the model bit-deterministic
|
|
9060
|
+
// (Anthropic makes no such guarantee), but it removes the one
|
|
9061
|
+
// variance source that was ours to control. See
|
|
9062
|
+
// scripts/fp-filter-repeatability.cjs for the measured flip rate,
|
|
9063
|
+
// and the assertion in ai-fp-filter.test.ts that keeps it pinned.
|
|
9064
|
+
temperature: 0,
|
|
8947
9065
|
system: REVIEW_SYSTEM_PROMPT,
|
|
8948
9066
|
messages: [{ role: "user", content: prompt }]
|
|
8949
9067
|
},
|
|
@@ -9126,6 +9244,7 @@ function scanEntropy(files) {
|
|
|
9126
9244
|
if (filePath.includes(".min.")) continue;
|
|
9127
9245
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
9128
9246
|
if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(filePath)) continue;
|
|
9247
|
+
const vendored = isVendoredPath(filePath);
|
|
9129
9248
|
const lines = content.split("\n");
|
|
9130
9249
|
for (let i = 0; i < lines.length; i++) {
|
|
9131
9250
|
const line = lines[i];
|
|
@@ -9156,6 +9275,7 @@ function scanEntropy(files) {
|
|
|
9156
9275
|
if (entropy < 4.5 && !isLikelySecret) continue;
|
|
9157
9276
|
const masked = value.substring(0, 6) + "..." + value.substring(value.length - 4);
|
|
9158
9277
|
findings.push({
|
|
9278
|
+
...vendored ? { vendored: true } : {},
|
|
9159
9279
|
id: `ENTROPY-${filePath}:${i + 1}`,
|
|
9160
9280
|
rule: "ENTROPY",
|
|
9161
9281
|
severity: isLikelySecret ? "critical" : "high",
|
|
@@ -9177,6 +9297,7 @@ function scanEntropy(files) {
|
|
|
9177
9297
|
}
|
|
9178
9298
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9179
9299
|
0 && (module.exports = {
|
|
9300
|
+
NON_APP_PATH_PATTERNS,
|
|
9180
9301
|
RULE_IMPACTS,
|
|
9181
9302
|
allCustomRules,
|
|
9182
9303
|
allRules,
|
|
@@ -9303,6 +9424,8 @@ function scanEntropy(files) {
|
|
|
9303
9424
|
ipcPathTraversal,
|
|
9304
9425
|
isCalleeNamed,
|
|
9305
9426
|
isMethodCall,
|
|
9427
|
+
isVendoredFinding,
|
|
9428
|
+
isVendoredPath,
|
|
9306
9429
|
javaDeserialization,
|
|
9307
9430
|
jwtAlgConfusion,
|
|
9308
9431
|
k8sNoResourceLimits,
|
|
@@ -9343,6 +9466,7 @@ function scanEntropy(files) {
|
|
|
9343
9466
|
nPlusOneQuery,
|
|
9344
9467
|
nextPublicSecret,
|
|
9345
9468
|
noRateLimiting,
|
|
9469
|
+
normalizeScanPath,
|
|
9346
9470
|
nosqlInjection,
|
|
9347
9471
|
openRedirectParams,
|
|
9348
9472
|
overlyPermissiveIAM,
|
|
@@ -9400,6 +9524,7 @@ function scanEntropy(files) {
|
|
|
9400
9524
|
unvalidatedRedirect,
|
|
9401
9525
|
vectorStoreQueryNoUserFilter,
|
|
9402
9526
|
vectorStoreUpsertNoMetadata,
|
|
9527
|
+
vendoredReason,
|
|
9403
9528
|
visitBinary,
|
|
9404
9529
|
visitCalls,
|
|
9405
9530
|
vulnerableDependencies,
|