xploitscan-shared-rules 1.14.4 → 1.15.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/dist/index.cjs +119 -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 +114 -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,
|
|
@@ -9126,6 +9233,7 @@ function scanEntropy(files) {
|
|
|
9126
9233
|
if (filePath.includes(".min.")) continue;
|
|
9127
9234
|
if (/pro-rules-bundle|\.bundle\.|\.chunk\./i.test(filePath)) continue;
|
|
9128
9235
|
if (/(?:\.test\.|\.spec\.|__tests__|__mocks__|fixtures?\/)/i.test(filePath)) continue;
|
|
9236
|
+
const vendored = isVendoredPath(filePath);
|
|
9129
9237
|
const lines = content.split("\n");
|
|
9130
9238
|
for (let i = 0; i < lines.length; i++) {
|
|
9131
9239
|
const line = lines[i];
|
|
@@ -9156,6 +9264,7 @@ function scanEntropy(files) {
|
|
|
9156
9264
|
if (entropy < 4.5 && !isLikelySecret) continue;
|
|
9157
9265
|
const masked = value.substring(0, 6) + "..." + value.substring(value.length - 4);
|
|
9158
9266
|
findings.push({
|
|
9267
|
+
...vendored ? { vendored: true } : {},
|
|
9159
9268
|
id: `ENTROPY-${filePath}:${i + 1}`,
|
|
9160
9269
|
rule: "ENTROPY",
|
|
9161
9270
|
severity: isLikelySecret ? "critical" : "high",
|
|
@@ -9177,6 +9286,7 @@ function scanEntropy(files) {
|
|
|
9177
9286
|
}
|
|
9178
9287
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9179
9288
|
0 && (module.exports = {
|
|
9289
|
+
NON_APP_PATH_PATTERNS,
|
|
9180
9290
|
RULE_IMPACTS,
|
|
9181
9291
|
allCustomRules,
|
|
9182
9292
|
allRules,
|
|
@@ -9303,6 +9413,8 @@ function scanEntropy(files) {
|
|
|
9303
9413
|
ipcPathTraversal,
|
|
9304
9414
|
isCalleeNamed,
|
|
9305
9415
|
isMethodCall,
|
|
9416
|
+
isVendoredFinding,
|
|
9417
|
+
isVendoredPath,
|
|
9306
9418
|
javaDeserialization,
|
|
9307
9419
|
jwtAlgConfusion,
|
|
9308
9420
|
k8sNoResourceLimits,
|
|
@@ -9343,6 +9455,7 @@ function scanEntropy(files) {
|
|
|
9343
9455
|
nPlusOneQuery,
|
|
9344
9456
|
nextPublicSecret,
|
|
9345
9457
|
noRateLimiting,
|
|
9458
|
+
normalizeScanPath,
|
|
9346
9459
|
nosqlInjection,
|
|
9347
9460
|
openRedirectParams,
|
|
9348
9461
|
overlyPermissiveIAM,
|
|
@@ -9400,6 +9513,7 @@ function scanEntropy(files) {
|
|
|
9400
9513
|
unvalidatedRedirect,
|
|
9401
9514
|
vectorStoreQueryNoUserFilter,
|
|
9402
9515
|
vectorStoreUpsertNoMetadata,
|
|
9516
|
+
vendoredReason,
|
|
9403
9517
|
visitBinary,
|
|
9404
9518
|
visitCalls,
|
|
9405
9519
|
vulnerableDependencies,
|