flagrix 0.1.2 → 0.1.4
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.
|
@@ -445,6 +445,53 @@ function stringEnd(line, start) {
|
|
|
445
445
|
}
|
|
446
446
|
return line.length;
|
|
447
447
|
}
|
|
448
|
+
function maskStringLiterals(content) {
|
|
449
|
+
let out = "";
|
|
450
|
+
let i = 0;
|
|
451
|
+
let quote = null;
|
|
452
|
+
while (i < content.length) {
|
|
453
|
+
const ch = content[i];
|
|
454
|
+
if (quote) {
|
|
455
|
+
if (ch === "\\") {
|
|
456
|
+
out += " ";
|
|
457
|
+
i += 2;
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (ch === quote) {
|
|
461
|
+
quote = null;
|
|
462
|
+
out += ch;
|
|
463
|
+
} else {
|
|
464
|
+
out += ch === "\n" ? "\n" : " ";
|
|
465
|
+
}
|
|
466
|
+
i++;
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
470
|
+
quote = ch;
|
|
471
|
+
out += ch;
|
|
472
|
+
i++;
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
if (ch === "/" && content[i + 1] === "/") {
|
|
476
|
+
let j = content.indexOf("\n", i);
|
|
477
|
+
if (j === -1)
|
|
478
|
+
j = content.length;
|
|
479
|
+
out += content.slice(i, j);
|
|
480
|
+
i = j;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (ch === "/" && content[i + 1] === "*") {
|
|
484
|
+
const close = content.indexOf("*/", i + 2);
|
|
485
|
+
const j = close === -1 ? content.length : close + 2;
|
|
486
|
+
out += content.slice(i, j);
|
|
487
|
+
i = j;
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
out += ch;
|
|
491
|
+
i++;
|
|
492
|
+
}
|
|
493
|
+
return out;
|
|
494
|
+
}
|
|
448
495
|
|
|
449
496
|
// node_modules/@flagrix/scanner-core/dist/github/api-error.js
|
|
450
497
|
async function githubApiError(response, fallback = "GitHub API error") {
|
|
@@ -483,16 +530,24 @@ function getSeverityWeight(severity) {
|
|
|
483
530
|
};
|
|
484
531
|
return weights[severity];
|
|
485
532
|
}
|
|
486
|
-
function
|
|
487
|
-
|
|
533
|
+
function calculateRawRiskScore(findings) {
|
|
534
|
+
const strongestBySignal = /* @__PURE__ */ new Map();
|
|
488
535
|
for (const finding of findings) {
|
|
489
|
-
|
|
536
|
+
const confidenceMultiplier = finding.confidence === "low" ? 0.25 : finding.confidence === "medium" ? 0.6 : 1;
|
|
537
|
+
const contribution = getSeverityWeight(finding.severity) * confidenceMultiplier;
|
|
538
|
+
const obfuscationHeuristic = finding.type === "OBFUSCATED_CODE" || finding.type === "CODE_INTEGRITY_ISSUE" && /minified|obfuscat/i.test(finding.description) || /^OBF_(?:BASE64|HEX|EVAL|NEW_FUNCTION|SETTIMEOUT|FROMCHARCODE|CHARCODE)/.test(finding.pattern ?? "");
|
|
539
|
+
const signal = obfuscationHeuristic ? "OBFUSCATION_HEURISTIC" : finding.pattern ?? finding.type;
|
|
540
|
+
strongestBySignal.set(signal, Math.max(strongestBySignal.get(signal) ?? 0, contribution));
|
|
490
541
|
}
|
|
491
|
-
return
|
|
542
|
+
return [...strongestBySignal.values()].reduce((sum, contribution) => sum + contribution, 0);
|
|
543
|
+
}
|
|
544
|
+
function calculateRiskScore(findings) {
|
|
545
|
+
return Math.min(1, calculateRawRiskScore(findings));
|
|
492
546
|
}
|
|
493
547
|
function getRiskLevel(score, findings) {
|
|
494
|
-
if (findings?.some((f) => f.severity === "critical"))
|
|
548
|
+
if (findings?.some((f) => f.severity === "critical" && (f.confidence ?? "high") === "high" || f.type === "SUSPICIOUS_DEPENDENCY" && (f.severity === "high" || f.severity === "critical") && (f.confidence ?? "high") === "high")) {
|
|
495
549
|
return "high";
|
|
550
|
+
}
|
|
496
551
|
if (score < RISK_THRESHOLDS.low)
|
|
497
552
|
return "low";
|
|
498
553
|
if (score < RISK_THRESHOLDS.high)
|
|
@@ -502,10 +557,10 @@ function getRiskLevel(score, findings) {
|
|
|
502
557
|
|
|
503
558
|
// node_modules/@flagrix/scanner-core/dist/rules/rule-matcher.js
|
|
504
559
|
var TEST_FILE_PATTERNS = [
|
|
505
|
-
/__tests__\//i,
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
560
|
+
/(?:^|\/)__tests__\//i,
|
|
561
|
+
/(?:^|\/)tests?\//i,
|
|
562
|
+
/(?:^|\/)spec\//i,
|
|
563
|
+
/(?:^|\/)benchmarks?\//i,
|
|
509
564
|
/\.test\.[jt]sx?$/i,
|
|
510
565
|
/\.spec\.[jt]sx?$/i,
|
|
511
566
|
/_test\.[jt]sx?$/i,
|
|
@@ -521,28 +576,99 @@ var TEST_FILE_PATTERNS = [
|
|
|
521
576
|
function isTestFile(filePath) {
|
|
522
577
|
return TEST_FILE_PATTERNS.some((pattern) => pattern.test(filePath));
|
|
523
578
|
}
|
|
524
|
-
|
|
579
|
+
var KEYBOARD_LISTENER = /(?:addEventListener\s*\(\s*['"](?:keydown|keypress|keyup)['"]|\.on(?:keydown|keypress|keyup)\s*=)/gi;
|
|
580
|
+
var KEY_VALUE = /\b[A-Za-z_$][\w$]*\.(?:key|code|keyCode|which)\b/gi;
|
|
581
|
+
var KEYBOARD_SINKS = [
|
|
582
|
+
/(?:fetch|axios\.(?:post|put|patch)|navigator\.sendBeacon|XMLHttpRequest|WebSocket)\b/gi,
|
|
583
|
+
/(?:localStorage|sessionStorage)\.setItem\s*\(/gi,
|
|
584
|
+
/(?:writeFile|writeFileSync|appendFile|appendFileSync)\s*\(/gi,
|
|
585
|
+
/\b(?:send|post|emit|upload|transmit|report|collect|capture|record|store|save)\w*\s*\([^)]*\b[A-Za-z_$][\w$]*\.(?:key|code|keyCode|which)\b/gi,
|
|
586
|
+
/(?:\+=|\.push\s*\()\s*\b[A-Za-z_$][\w$]*\.(?:key|code|keyCode|which)\b/gi
|
|
587
|
+
];
|
|
588
|
+
var PLACEHOLDER_SECRET_WORDS = /(?:^|[-_.\s])(?:your|change|replace|example|dummy|placeholder|development|dev|test|sample|not[-_]?secret|changeme)(?:$|[-_.\s])/i;
|
|
589
|
+
function isObviousPlaceholderSecret(match) {
|
|
590
|
+
const quotedValue = match.match(/['"]([^'"]+)['"]\s*$/)?.[1];
|
|
591
|
+
if (!quotedValue)
|
|
592
|
+
return false;
|
|
593
|
+
return PLACEHOLDER_SECRET_WORDS.test(quotedValue);
|
|
594
|
+
}
|
|
595
|
+
function isDocumentedAwsExampleKey(match) {
|
|
596
|
+
return /\bAKIAIOSFODNN7EXAMPLE\b/.test(match);
|
|
597
|
+
}
|
|
598
|
+
var CASE_SENSITIVE_RULE_IDS = /* @__PURE__ */ new Set([
|
|
599
|
+
"HARDCODED_AWS_KEY",
|
|
600
|
+
"HARDCODED_GITHUB_TOKEN",
|
|
601
|
+
"HARDCODED_STRIPE_KEY",
|
|
602
|
+
"NETWORK_TELEGRAM_TOKEN"
|
|
603
|
+
]);
|
|
604
|
+
function detectKeyboardCapture(content) {
|
|
605
|
+
const listeners = [...content.matchAll(KEYBOARD_LISTENER)];
|
|
606
|
+
for (const listener of listeners) {
|
|
607
|
+
const start = listener.index ?? 0;
|
|
608
|
+
const region = content.slice(start, start + 2e3);
|
|
609
|
+
if (!KEY_VALUE.test(region))
|
|
610
|
+
continue;
|
|
611
|
+
KEY_VALUE.lastIndex = 0;
|
|
612
|
+
const sink = KEYBOARD_SINKS.find((pattern) => {
|
|
613
|
+
pattern.lastIndex = 0;
|
|
614
|
+
return pattern.test(region);
|
|
615
|
+
});
|
|
616
|
+
if (sink) {
|
|
617
|
+
KEYBOARD_LISTENER.lastIndex = 0;
|
|
618
|
+
KEY_VALUE.lastIndex = 0;
|
|
619
|
+
sink.lastIndex = 0;
|
|
620
|
+
return { evidencePatterns: [KEYBOARD_LISTENER, KEY_VALUE, sink] };
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
KEYBOARD_LISTENER.lastIndex = 0;
|
|
624
|
+
KEY_VALUE.lastIndex = 0;
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
function applyYaraRules(content, rules, filePath, scopePath = filePath) {
|
|
525
628
|
const findings = [];
|
|
526
|
-
const isTest = isTestFile(
|
|
629
|
+
const isTest = isTestFile(scopePath);
|
|
527
630
|
for (const rule of rules) {
|
|
528
631
|
try {
|
|
529
|
-
if (
|
|
632
|
+
if (isTest)
|
|
633
|
+
continue;
|
|
634
|
+
if (rule.fileExtensions && rule.fileExtensions.length > 0 && !rule.fileExtensions.some((ext) => scopePath.endsWith(ext))) {
|
|
530
635
|
continue;
|
|
531
636
|
}
|
|
532
|
-
|
|
637
|
+
if (rule.fileNames && rule.fileNames.length > 0 && !rule.fileNames.includes(scopePath.split("/").pop() ?? scopePath)) {
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
const regex = new RegExp(rule.pattern, CASE_SENSITIVE_RULE_IDS.has(rule.id) ? "g" : "gi");
|
|
533
641
|
const matches2 = content.match(regex);
|
|
534
642
|
const required = rule.minMatches && rule.minMatches > 1 ? rule.minMatches : 1;
|
|
535
643
|
if (matches2 && matches2.length >= required) {
|
|
536
|
-
if (
|
|
644
|
+
if (rule.id === "HARDCODED_AWS_KEY" && matches2.every(isDocumentedAwsExampleKey)) {
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (rule.id === "HARDCODED_API_KEY" && matches2.every(isObviousPlaceholderSecret)) {
|
|
648
|
+
findings.push({
|
|
649
|
+
severity: "low",
|
|
650
|
+
confidence: "high",
|
|
651
|
+
cloneBlocking: false,
|
|
652
|
+
type: "INSECURE_CONFIGURATION",
|
|
653
|
+
file: filePath,
|
|
654
|
+
pattern: rule.id,
|
|
655
|
+
description: "Predictable placeholder secret must be replaced before deployment",
|
|
656
|
+
evidence: collectEvidence(content, regex)
|
|
657
|
+
});
|
|
537
658
|
continue;
|
|
538
659
|
}
|
|
660
|
+
const contextName = rule.context ?? (rule.id === "EXFIL_KEYLOGGER" ? "keyboard-capture" : void 0);
|
|
661
|
+
const context = contextName === "keyboard-capture" ? detectKeyboardCapture(content) : null;
|
|
662
|
+
if (contextName && !context)
|
|
663
|
+
continue;
|
|
539
664
|
findings.push({
|
|
540
665
|
severity: rule.severity,
|
|
666
|
+
confidence: rule.confidence ?? "high",
|
|
541
667
|
type: "MALWARE_SIGNATURE",
|
|
542
668
|
file: filePath,
|
|
543
669
|
pattern: rule.id,
|
|
544
670
|
description: rule.description,
|
|
545
|
-
evidence: collectEvidence(content, regex)
|
|
671
|
+
evidence: collectEvidence(content, context?.evidencePatterns ?? regex)
|
|
546
672
|
});
|
|
547
673
|
}
|
|
548
674
|
} catch {
|
|
@@ -562,11 +688,44 @@ var PRIORITY_FILES = [
|
|
|
562
688
|
".yarnrc",
|
|
563
689
|
"Makefile"
|
|
564
690
|
];
|
|
565
|
-
var SCANNABLE_EXTENSIONS = [
|
|
566
|
-
|
|
691
|
+
var SCANNABLE_EXTENSIONS = [
|
|
692
|
+
".js",
|
|
693
|
+
".jsx",
|
|
694
|
+
".mjs",
|
|
695
|
+
".cjs",
|
|
696
|
+
".ts",
|
|
697
|
+
".tsx",
|
|
698
|
+
".py",
|
|
699
|
+
".rb",
|
|
700
|
+
".php",
|
|
701
|
+
".go",
|
|
702
|
+
".sh",
|
|
703
|
+
".ps1",
|
|
704
|
+
".psm1",
|
|
705
|
+
".bat",
|
|
706
|
+
".cmd",
|
|
707
|
+
".vbs",
|
|
708
|
+
".html",
|
|
709
|
+
".htm"
|
|
710
|
+
];
|
|
711
|
+
var MAX_FILES_TO_SCAN = 200;
|
|
712
|
+
var MAX_FILE_SIZE_BYTES = 1024 * 1024;
|
|
713
|
+
var MAX_SKIPPED_FILES_LISTED = 500;
|
|
567
714
|
var NPM_DOWNLOAD_CACHE = /* @__PURE__ */ new Map();
|
|
568
715
|
var NPM_CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
569
716
|
var NPM_HIGH_DOWNLOAD_THRESHOLD = 1e5;
|
|
717
|
+
function maskExceptInlineScripts(content) {
|
|
718
|
+
const masked = [...content].map((char) => char === "\n" || char === "\r" ? char : " ");
|
|
719
|
+
const script2 = /<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi;
|
|
720
|
+
for (const match of content.matchAll(script2)) {
|
|
721
|
+
const body = match[1] ?? "";
|
|
722
|
+
const bodyOffset = (match.index ?? 0) + match[0].indexOf(body);
|
|
723
|
+
for (let index = 0; index < body.length; index++) {
|
|
724
|
+
masked[bodyOffset + index] = body[index];
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return masked.join("");
|
|
728
|
+
}
|
|
570
729
|
async function scanGitHubRepo(repo, options) {
|
|
571
730
|
const findings = [];
|
|
572
731
|
let filesScanned = 0;
|
|
@@ -609,10 +768,33 @@ async function scanGitHubRepo(repo, options) {
|
|
|
609
768
|
throw await githubApiError(treeResponse);
|
|
610
769
|
}
|
|
611
770
|
const tree = await treeResponse.json();
|
|
612
|
-
const
|
|
771
|
+
const skippedFiles = [];
|
|
772
|
+
let skippedCount = 0;
|
|
773
|
+
const skip = (path, reason) => {
|
|
774
|
+
skippedCount++;
|
|
775
|
+
if (skippedFiles.length < MAX_SKIPPED_FILES_LISTED) {
|
|
776
|
+
skippedFiles.push({ path, reason });
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
const filesToScan = [];
|
|
780
|
+
for (const item of tree.tree) {
|
|
781
|
+
if (item.type !== "blob")
|
|
782
|
+
continue;
|
|
783
|
+
const eligible = PRIORITY_FILES.some((pf) => item.path.endsWith(pf)) || SCANNABLE_EXTENSIONS.some((ext) => item.path.endsWith(ext));
|
|
784
|
+
if (!eligible) {
|
|
785
|
+
skip(item.path, "unsupported-type");
|
|
786
|
+
} else if (item.size !== void 0 && item.size > MAX_FILE_SIZE_BYTES) {
|
|
787
|
+
skip(item.path, "too-large");
|
|
788
|
+
} else if (filesToScan.length >= MAX_FILES_TO_SCAN) {
|
|
789
|
+
skip(item.path, "over-file-limit");
|
|
790
|
+
} else {
|
|
791
|
+
filesToScan.push(item);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
613
794
|
const hiddenFiles = tree.tree.filter((item) => item.path.startsWith(".") && !item.path.startsWith(".github") && !item.path.startsWith(".git") && item.type === "blob");
|
|
614
795
|
for (const hidden of hiddenFiles) {
|
|
615
|
-
|
|
796
|
+
const basename = hidden.path.split("/").pop() ?? hidden.path;
|
|
797
|
+
if (/^\.(?:backdoor|payload|reverse[-_]?shell)(?:\.|$)/i.test(basename)) {
|
|
616
798
|
findings.push({
|
|
617
799
|
severity: "high",
|
|
618
800
|
type: "HIDDEN_FILE",
|
|
@@ -626,15 +808,25 @@ async function scanGitHubRepo(repo, options) {
|
|
|
626
808
|
const yaraRules = options.signatures.yaraRules;
|
|
627
809
|
const loadedRuleIds = new Set(yaraRules.map((r) => r.id));
|
|
628
810
|
const fileContents = [];
|
|
811
|
+
const scannedFiles = [];
|
|
629
812
|
for (const file of filesToScan) {
|
|
630
|
-
filesScanned++;
|
|
631
813
|
const contentUrl = `https://api.github.com/repos/${repo.owner}/${repo.repo}/contents/${file.path}?ref=${commitSha}`;
|
|
632
814
|
const contentResponse = await fetch(contentUrl, { headers });
|
|
633
|
-
if (!contentResponse.ok)
|
|
815
|
+
if (!contentResponse.ok) {
|
|
816
|
+
skip(file.path, "fetch-failed");
|
|
634
817
|
continue;
|
|
818
|
+
}
|
|
819
|
+
filesScanned++;
|
|
820
|
+
scannedFiles.push(file.path);
|
|
635
821
|
const fileData = await contentResponse.json();
|
|
636
822
|
const content = atob(fileData.content || "");
|
|
637
|
-
const
|
|
823
|
+
const isHtml = /\.html?$/i.test(file.path);
|
|
824
|
+
const isJsTs = /\.(?:[cm]?js|ts|[jt]sx)$/i.test(file.path);
|
|
825
|
+
const scriptContent = isHtml ? maskExceptInlineScripts(content) : content;
|
|
826
|
+
let matchable = isJsTs || isHtml ? maskRegexLiterals(scriptContent) : scriptContent;
|
|
827
|
+
if (isJsTs && isTestFile(file.path)) {
|
|
828
|
+
matchable = maskStringLiterals(matchable);
|
|
829
|
+
}
|
|
638
830
|
if (SCANNABLE_EXTENSIONS.some((ext) => file.path.endsWith(ext))) {
|
|
639
831
|
fileContents.push({ path: file.path, content: matchable });
|
|
640
832
|
}
|
|
@@ -653,7 +845,8 @@ async function scanGitHubRepo(repo, options) {
|
|
|
653
845
|
patternsMatched += pyFindings.length;
|
|
654
846
|
}
|
|
655
847
|
if (SCANNABLE_EXTENSIONS.some((ext) => file.path.endsWith(ext))) {
|
|
656
|
-
const
|
|
848
|
+
const ruleScopePath = isHtml ? `${file.path}.js` : file.path;
|
|
849
|
+
const yaraFindings = applyYaraRules(matchable, yaraRules, file.path, ruleScopePath);
|
|
657
850
|
findings.push(...yaraFindings);
|
|
658
851
|
patternsMatched += yaraFindings.length;
|
|
659
852
|
const obfuscationFindings = detectObfuscation(matchable, file.path, loadedRuleIds);
|
|
@@ -702,10 +895,15 @@ async function scanGitHubRepo(repo, options) {
|
|
|
702
895
|
const integrityFindings = await detectCodeIntegrityIssues(fileContents, allPaths, repo);
|
|
703
896
|
findings.push(...integrityFindings);
|
|
704
897
|
patternsMatched += integrityFindings.length;
|
|
898
|
+
const rawRiskScore = calculateRawRiskScore(findings);
|
|
705
899
|
const riskScore = calculateRiskScore(findings);
|
|
706
900
|
const riskLevel = getRiskLevel(riskScore, findings);
|
|
901
|
+
const cloneBlockingFindings = findings.filter((finding) => finding.cloneBlocking !== false);
|
|
902
|
+
const cloneRiskScore = calculateRiskScore(cloneBlockingFindings);
|
|
903
|
+
const cloneRiskLevel = getRiskLevel(cloneRiskScore, cloneBlockingFindings);
|
|
707
904
|
return {
|
|
708
905
|
riskScore,
|
|
906
|
+
rawRiskScore,
|
|
709
907
|
riskLevel,
|
|
710
908
|
factors: findings.map((f) => ({
|
|
711
909
|
factor: f.type,
|
|
@@ -715,9 +913,17 @@ async function scanGitHubRepo(repo, options) {
|
|
|
715
913
|
disclaimer: DEFAULT_DISCLAIMER,
|
|
716
914
|
repo,
|
|
717
915
|
commitSha,
|
|
718
|
-
scanSummary: {
|
|
916
|
+
scanSummary: {
|
|
917
|
+
filesScanned,
|
|
918
|
+
patternsMatched,
|
|
919
|
+
dependenciesChecked,
|
|
920
|
+
scannedFiles,
|
|
921
|
+
skippedFiles,
|
|
922
|
+
skippedCount,
|
|
923
|
+
treeTruncated: tree.truncated
|
|
924
|
+
},
|
|
719
925
|
findings,
|
|
720
|
-
safeToClone:
|
|
926
|
+
safeToClone: cloneRiskLevel === "low",
|
|
721
927
|
scannedAt: /* @__PURE__ */ new Date()
|
|
722
928
|
};
|
|
723
929
|
} catch (error) {
|
|
@@ -729,11 +935,12 @@ async function scanPackageJson(content, maliciousPackages, filePath) {
|
|
|
729
935
|
try {
|
|
730
936
|
const pkg = JSON.parse(content);
|
|
731
937
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
732
|
-
for (const [name] of Object.entries(allDeps)) {
|
|
938
|
+
for (const [name, declaredVersion] of Object.entries(allDeps)) {
|
|
733
939
|
const malicious = maliciousPackages.find((m) => m.name === name);
|
|
734
|
-
if (malicious) {
|
|
940
|
+
if (malicious && isAffectedPackageVersion(malicious, declaredVersion)) {
|
|
735
941
|
findings.push({
|
|
736
942
|
severity: malicious.severity,
|
|
943
|
+
confidence: "high",
|
|
737
944
|
type: "SUSPICIOUS_DEPENDENCY",
|
|
738
945
|
file: filePath,
|
|
739
946
|
package: name,
|
|
@@ -761,6 +968,23 @@ async function scanPackageJson(content, maliciousPackages, filePath) {
|
|
|
761
968
|
}
|
|
762
969
|
return findings;
|
|
763
970
|
}
|
|
971
|
+
function isAffectedPackageVersion(malicious, declaredVersion) {
|
|
972
|
+
const affected = malicious.versions ?? (malicious.version ? [malicious.version] : []);
|
|
973
|
+
if (affected.length === 0)
|
|
974
|
+
return true;
|
|
975
|
+
if (typeof declaredVersion !== "string")
|
|
976
|
+
return false;
|
|
977
|
+
let specifier = declaredVersion.trim();
|
|
978
|
+
if (specifier.startsWith("workspace:"))
|
|
979
|
+
specifier = specifier.slice("workspace:".length);
|
|
980
|
+
const npmAlias = specifier.match(/^npm:.+@([^@]+)$/);
|
|
981
|
+
if (npmAlias)
|
|
982
|
+
specifier = npmAlias[1];
|
|
983
|
+
return specifier.split(/\s*\|\|\s*/).some((part) => {
|
|
984
|
+
const normalized = part.trim().replace(/^[=v~^\s]+/, "");
|
|
985
|
+
return affected.includes(normalized);
|
|
986
|
+
});
|
|
987
|
+
}
|
|
764
988
|
function checkPostinstallScripts(content, filePath) {
|
|
765
989
|
const findings = [];
|
|
766
990
|
try {
|
|
@@ -803,6 +1027,7 @@ function scanPythonDeps(content, maliciousPackages, filePath) {
|
|
|
803
1027
|
if (malicious) {
|
|
804
1028
|
findings.push({
|
|
805
1029
|
severity: malicious.severity,
|
|
1030
|
+
confidence: "high",
|
|
806
1031
|
type: "SUSPICIOUS_DEPENDENCY",
|
|
807
1032
|
file: filePath,
|
|
808
1033
|
package: name,
|
|
@@ -849,7 +1074,8 @@ function detectObfuscation(content, filePath, coveredRuleIds = /* @__PURE__ */ n
|
|
|
849
1074
|
});
|
|
850
1075
|
}
|
|
851
1076
|
const evalPatterns = [
|
|
852
|
-
|
|
1077
|
+
// Non-empty argument required: bare "eval()" appears in prose/docs.
|
|
1078
|
+
{ pattern: /eval\s*\(\s*[^)\s][^)]{0,200}\)/gi, name: "eval", ruleId: BUILTIN_OBFUSCATION_RULE_IDS.eval },
|
|
853
1079
|
{ pattern: /new\s+Function\s*\([^)]{0,200}\)/gi, name: "Function constructor", ruleId: BUILTIN_OBFUSCATION_RULE_IDS.newFunction },
|
|
854
1080
|
{ pattern: /setTimeout\s*\(\s*["'`][^"'`]{0,200}["'`]/gi, name: "setTimeout with string", ruleId: BUILTIN_OBFUSCATION_RULE_IDS.timerString },
|
|
855
1081
|
{ pattern: /setInterval\s*\(\s*["'`][^"'`]{0,200}["'`]/gi, name: "setInterval with string", ruleId: BUILTIN_OBFUSCATION_RULE_IDS.timerString }
|
|
@@ -895,12 +1121,13 @@ function detectObfuscation(content, filePath, coveredRuleIds = /* @__PURE__ */ n
|
|
|
895
1121
|
const maxLength = Math.max(...suspiciousLines.map((l) => l.length));
|
|
896
1122
|
const linesWithMaliciousCode = suspiciousLines.filter((l) => l.hasMaliciousPattern);
|
|
897
1123
|
const lineDetails = suspiciousLines.slice(0, 3).map((l) => `Line ${l.lineNum} (${l.length.toLocaleString()} chars${l.hasMaliciousPattern ? ", contains suspicious code" : ""})`).join(", ");
|
|
898
|
-
const severity =
|
|
1124
|
+
const severity = "medium";
|
|
899
1125
|
const firstLine = lines[suspiciousLines[0].lineNum - 1];
|
|
900
1126
|
const codeSnippet = extractCodeSnippet(firstLine);
|
|
901
1127
|
const codeExplanation = explainSuspiciousCode(firstLine, "OBFUSCATED_CODE");
|
|
902
1128
|
findings.push({
|
|
903
1129
|
severity,
|
|
1130
|
+
confidence: linesWithMaliciousCode.length > 0 ? "medium" : "low",
|
|
904
1131
|
type: "OBFUSCATED_CODE",
|
|
905
1132
|
file: filePath,
|
|
906
1133
|
line: suspiciousLines[0].lineNum,
|
|
@@ -1134,31 +1361,54 @@ function detectHardcodedSecrets(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1134
1361
|
if (isTestFile(filePath))
|
|
1135
1362
|
return findings;
|
|
1136
1363
|
const secretPatterns = [
|
|
1137
|
-
{ pattern: /(?:api[_-]?key|apikey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "API Key", severity: "
|
|
1138
|
-
{ pattern: /(?:secret[_-]?key|secret)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Secret Key", severity: "
|
|
1139
|
-
{ pattern: /(?:password|passwd|pwd)\s*[:=]\s*['"]([^'"]{8,})['"]/gi, type: "Password", severity: "
|
|
1140
|
-
{ pattern: /(?:token|auth[_-]?token)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Auth Token", severity: "
|
|
1141
|
-
{ pattern: /(?:private[_-]?key|privatekey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Private Key", severity: "
|
|
1364
|
+
{ pattern: /(?:api[_-]?key|apikey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "API Key", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1365
|
+
{ pattern: /(?:secret[_-]?key|secret)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Secret Key", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1366
|
+
{ pattern: /(?:password|passwd|pwd)\s*[:=]\s*['"]([^'"]{8,})['"]/gi, type: "Password", severity: "medium", ruleId: null },
|
|
1367
|
+
{ pattern: /(?:token|auth[_-]?token)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Auth Token", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1368
|
+
{ pattern: /(?:private[_-]?key|privatekey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Private Key", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1142
1369
|
{ pattern: /AKIA[0-9A-Z]{16}/g, type: "AWS Access Key", severity: "critical", ruleId: "HARDCODED_AWS_KEY" },
|
|
1143
1370
|
{ pattern: /ghp_[a-zA-Z0-9]{36}/g, type: "GitHub Personal Access Token", severity: "critical", ruleId: "HARDCODED_GITHUB_TOKEN" },
|
|
1144
1371
|
{ pattern: /gho_[a-zA-Z0-9]{36}/g, type: "GitHub OAuth Token", severity: "critical", ruleId: "HARDCODED_GITHUB_TOKEN" },
|
|
1145
1372
|
{ pattern: /sk_live_[a-zA-Z0-9]{24,}/g, type: "Stripe Live Key", severity: "critical", ruleId: "HARDCODED_STRIPE_KEY" },
|
|
1146
|
-
{ pattern: /(?:mongodb|mongo)[+:\/\/]{0,6}[^@\s]+:[^@\s]+@/gi, type: "MongoDB Connection String", severity: "
|
|
1147
|
-
{ pattern: /postgres:\/\/[^@\s]+:[^@\s]+@/gi, type: "PostgreSQL Connection String", severity: "
|
|
1373
|
+
{ pattern: /(?:mongodb|mongo)[+:\/\/]{0,6}[^@\s]+:[^@\s]+@/gi, type: "MongoDB Connection String", severity: "medium", ruleId: "HARDCODED_DB_CONNECTION" },
|
|
1374
|
+
{ pattern: /postgres:\/\/[^@\s]+:[^@\s]+@/gi, type: "PostgreSQL Connection String", severity: "medium", ruleId: "HARDCODED_DB_CONNECTION" }
|
|
1148
1375
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1149
1376
|
const foundSecrets = [];
|
|
1150
1377
|
const matchedRegexes = [];
|
|
1378
|
+
const placeholderRegexes = [];
|
|
1151
1379
|
for (const { pattern, type, severity } of secretPatterns) {
|
|
1152
1380
|
const matches2 = content.match(pattern);
|
|
1153
1381
|
if (matches2 && matches2.length > 0) {
|
|
1154
|
-
|
|
1382
|
+
const genericSecret = ["API Key", "Secret Key", "Auth Token", "Private Key"].includes(type);
|
|
1383
|
+
const actionableMatches = type === "AWS Access Key" ? matches2.filter((match) => !isDocumentedAwsExampleKey(match)) : genericSecret ? matches2.filter((match) => !isObviousPlaceholderSecret(match)) : matches2;
|
|
1384
|
+
if (actionableMatches.length === 0) {
|
|
1385
|
+
placeholderRegexes.push(pattern);
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
foundSecrets.push({
|
|
1389
|
+
type,
|
|
1390
|
+
match: actionableMatches[0].substring(0, 50) + "...",
|
|
1391
|
+
severity
|
|
1392
|
+
});
|
|
1155
1393
|
matchedRegexes.push(pattern);
|
|
1156
1394
|
}
|
|
1157
1395
|
}
|
|
1396
|
+
if (placeholderRegexes.length > 0) {
|
|
1397
|
+
findings.push({
|
|
1398
|
+
severity: "low",
|
|
1399
|
+
confidence: "high",
|
|
1400
|
+
cloneBlocking: false,
|
|
1401
|
+
type: "INSECURE_CONFIGURATION",
|
|
1402
|
+
file: filePath,
|
|
1403
|
+
description: "Predictable placeholder secret must be replaced before deployment",
|
|
1404
|
+
evidence: collectEvidence(content, placeholderRegexes)
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1158
1407
|
if (foundSecrets.length > 0) {
|
|
1159
|
-
const highestSeverity = foundSecrets.some((s) => s.severity === "critical") ? "critical" : "high";
|
|
1408
|
+
const highestSeverity = foundSecrets.some((s) => s.severity === "critical") ? "critical" : foundSecrets.some((s) => s.severity === "high") ? "high" : "medium";
|
|
1160
1409
|
findings.push({
|
|
1161
1410
|
severity: highestSeverity,
|
|
1411
|
+
confidence: highestSeverity === "critical" ? "high" : "medium",
|
|
1162
1412
|
type: "HARDCODED_SECRETS",
|
|
1163
1413
|
file: filePath,
|
|
1164
1414
|
description: `Hardcoded credentials detected: ${foundSecrets.map((s) => s.type).join(", ")}`,
|
|
@@ -1177,7 +1427,7 @@ function detectNetworkPatterns(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1177
1427
|
// Valid public IPv4 only: each octet bounded 0–255, not embedded in a longer
|
|
1178
1428
|
// dotted/number sequence (avoids flagging version strings like "1.2.3.4.5" or
|
|
1179
1429
|
// impossible IPs like "999.999.999.999"), and excluding private/link-local ranges.
|
|
1180
|
-
{ pattern: /(?:https?:\/\/)?(?<![\d.])(?!(?:127\.|10\.|192\.168\.|169\.254\.|172\.(?:1[6-9]|2\d|3[01])\.))(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}(?![\d.])(?::\d{1,5})?/g, type: "Hardcoded IP Address", severity: "
|
|
1430
|
+
{ pattern: /(?:https?:\/\/)?(?<![\d.])(?!(?:0\.|127\.|10\.|192\.168\.|169\.254\.|172\.(?:1[6-9]|2\d|3[01])\.))(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}(?![\d.])(?::\d{1,5})?/g, type: "Hardcoded IP Address", severity: "medium", confidence: "low" },
|
|
1181
1431
|
{ pattern: /https?:\/\/discord(?:app)?\.com\/api\/webhooks\/\d+\/[a-zA-Z0-9_-]+/gi, type: "Discord Webhook", severity: "critical", ruleId: "NETWORK_DISCORD_WEBHOOK" },
|
|
1182
1432
|
{ pattern: /\d{8,10}:[a-zA-Z0-9_-]{35}/g, type: "Telegram Bot Token", severity: "high", ruleId: "NETWORK_TELEGRAM_TOKEN" },
|
|
1183
1433
|
{ pattern: /(?:pastebin\.com|hastebin\.com|paste\.ee)\/[a-zA-Z0-9]+/gi, type: "Pastebin URL", severity: "medium", ruleId: "NETWORK_PASTEBIN" },
|
|
@@ -1185,7 +1435,7 @@ function detectNetworkPatterns(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1185
1435
|
{ pattern: /https?:\/\/[a-zA-Z0-9-]+\.(?:tk|ml|ga|cf|gq|onion|xyz)(?:\/|$)/gi, type: "Suspicious Domain TLD", severity: "high", ruleId: "NETWORK_SUSPICIOUS_TLD" },
|
|
1186
1436
|
{ pattern: /https?:\/\/[a-zA-Z0-9-]+\.ngrok\.io/gi, type: "Ngrok Tunnel", severity: "medium", ruleId: "NETWORK_NGROK_TUNNEL" }
|
|
1187
1437
|
].filter((p) => !("ruleId" in p) || !coveredRuleIds.has(p.ruleId));
|
|
1188
|
-
for (const { pattern, type, severity } of suspiciousPatterns) {
|
|
1438
|
+
for (const { pattern, type, severity, confidence } of suspiciousPatterns) {
|
|
1189
1439
|
const matches2 = content.match(pattern);
|
|
1190
1440
|
if (matches2 && matches2.length > 0) {
|
|
1191
1441
|
const validMatches = matches2.filter((m) => {
|
|
@@ -1196,6 +1446,7 @@ function detectNetworkPatterns(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1196
1446
|
if (validMatches.length > 0) {
|
|
1197
1447
|
findings.push({
|
|
1198
1448
|
severity,
|
|
1449
|
+
confidence: confidence ?? "high",
|
|
1199
1450
|
type: "NETWORK_COMMUNICATION",
|
|
1200
1451
|
file: filePath,
|
|
1201
1452
|
description: `Suspicious network communication detected: ${type} (${validMatches.length} occurrence${validMatches.length > 1 ? "s" : ""})`,
|
|
@@ -1250,11 +1501,9 @@ function detectDataExfiltration(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1250
1501
|
return findings;
|
|
1251
1502
|
const exfiltrationPatterns = [
|
|
1252
1503
|
{ pattern: /navigator\.clipboard\.read(?:Text)?\s*\(/gi, type: "Clipboard Access", severity: "high", ruleId: "EXFIL_CLIPBOARD" },
|
|
1253
|
-
{ pattern: /localStorage\.getItem|sessionStorage\.getItem/gi, type: "Storage Access", severity: "medium", ruleId: null },
|
|
1254
1504
|
{ pattern: /document\.cookie/gi, type: "Cookie Access", severity: "high", ruleId: "EXFIL_COOKIE" },
|
|
1255
|
-
{ pattern: /(?:addEventListener|on)\s*\(\s*['"](?:keydown|keypress|keyup)['"]/gi, type: "Keylogger Pattern", severity: "critical", ruleId: "EXFIL_KEYLOGGER" },
|
|
1256
1505
|
{ pattern: /(?:input|password|email)[\w-]*\.value/gi, type: "Form Data Access", severity: "medium", ruleId: null },
|
|
1257
|
-
{ pattern: /new\s+FormData\s*\([^)]*\)[\s\S]{0,100}(?:fetch|axios|XMLHttpRequest)/gi, type: "Form Data Transmission", severity: "
|
|
1506
|
+
{ pattern: /new\s+FormData\s*\([^)]*\)[\s\S]{0,100}(?:fetch|axios|XMLHttpRequest)/gi, type: "Form Data Transmission", severity: "medium", ruleId: null }
|
|
1258
1507
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1259
1508
|
const detectedPatterns = [];
|
|
1260
1509
|
const matchedRegexes = [];
|
|
@@ -1263,14 +1512,34 @@ function detectDataExfiltration(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1263
1512
|
if (pattern.test(content)) {
|
|
1264
1513
|
detectedPatterns.push(type);
|
|
1265
1514
|
matchedRegexes.push(pattern);
|
|
1266
|
-
if (severity === "
|
|
1267
|
-
highestSeverity =
|
|
1268
|
-
|
|
1515
|
+
if (severity === "high")
|
|
1516
|
+
highestSeverity = "high";
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
const sensitiveStorageRead = /(?:localStorage|sessionStorage)\.getItem\s*\(\s*['"][^'"]*(?:token|secret|password|credential|session|auth|wallet|seed|private)[^'"]*['"]\s*\)/gi;
|
|
1520
|
+
for (const match of content.matchAll(sensitiveStorageRead)) {
|
|
1521
|
+
const start = match.index ?? 0;
|
|
1522
|
+
const region = content.slice(start, start + 2e3);
|
|
1523
|
+
const networkSink = /(?:fetch\s*\(|axios\.(?:post|put|patch)\s*\(|navigator\.sendBeacon\s*\(|XMLHttpRequest|WebSocket)/gi;
|
|
1524
|
+
if (networkSink.test(region)) {
|
|
1525
|
+
detectedPatterns.push("Sensitive Storage Transmission");
|
|
1526
|
+
matchedRegexes.push(sensitiveStorageRead, networkSink);
|
|
1527
|
+
highestSeverity = "high";
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
if (!coveredRuleIds.has("EXFIL_KEYLOGGER")) {
|
|
1532
|
+
const keyboardCapture = detectKeyboardCapture(content);
|
|
1533
|
+
if (keyboardCapture) {
|
|
1534
|
+
detectedPatterns.push("Keyboard Capture and Transmission");
|
|
1535
|
+
matchedRegexes.push(...keyboardCapture.evidencePatterns);
|
|
1536
|
+
highestSeverity = "critical";
|
|
1269
1537
|
}
|
|
1270
1538
|
}
|
|
1271
1539
|
if (detectedPatterns.length > 0) {
|
|
1272
1540
|
findings.push({
|
|
1273
1541
|
severity: highestSeverity,
|
|
1542
|
+
confidence: highestSeverity === "medium" ? "low" : "high",
|
|
1274
1543
|
type: "DATA_EXFILTRATION",
|
|
1275
1544
|
file: filePath,
|
|
1276
1545
|
description: `Data exfiltration patterns detected: ${detectedPatterns.join(", ")}`,
|
|
@@ -1287,7 +1556,6 @@ function detectBackdoors(content, filePath, coveredRuleIds = /* @__PURE__ */ new
|
|
|
1287
1556
|
{ pattern: /exec\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Command Injection Endpoint", severity: "critical", ruleId: "BACKDOOR_RCE_ENDPOINT" },
|
|
1288
1557
|
{ pattern: /require\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Dynamic Require", severity: "critical", ruleId: "BACKDOOR_DYNAMIC_REQUIRE" },
|
|
1289
1558
|
{ pattern: /new\s+Function\s*\([^)]*(?:request|req)/gi, type: "Dynamic Function from Request", severity: "critical", ruleId: null },
|
|
1290
|
-
{ pattern: /(?:admin|debug|backdoor|shell)[\w]*\s*[:=]\s*(?:true|1|"[^"]*")\s*(?:\/\/|#)?\s*(?:TODO|FIXME|HACK)?/gi, type: "Debug/Admin Flag", severity: "high", ruleId: null },
|
|
1291
1559
|
{ pattern: /(?:password|auth)\s*(?:===?|==)\s*['"][^'"]{0,20}['"]\s*\)/gi, type: "Hardcoded Auth Bypass", severity: "critical", ruleId: "BACKDOOR_HARDCODED_AUTH" }
|
|
1292
1560
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1293
1561
|
for (const { pattern, type, severity } of backdoorPatterns) {
|
|
@@ -1304,6 +1572,21 @@ function detectBackdoors(content, filePath, coveredRuleIds = /* @__PURE__ */ new
|
|
|
1304
1572
|
});
|
|
1305
1573
|
}
|
|
1306
1574
|
}
|
|
1575
|
+
const exposedFlaskDebugger = /app\.run\s*\((?=[\s\S]{0,400}\bdebug\s*=\s*True)(?=[\s\S]{0,400}\bhost\s*=\s*['"]0\.0\.0\.0['"])[\s\S]{0,400}\)/gi;
|
|
1576
|
+
const flaskDebugEnabled = /\bdebug\s*=\s*True/gi;
|
|
1577
|
+
const wildcardBind = /\bhost\s*=\s*['"]0\.0\.0\.0['"]/gi;
|
|
1578
|
+
if (exposedFlaskDebugger.test(content)) {
|
|
1579
|
+
findings.push({
|
|
1580
|
+
severity: "low",
|
|
1581
|
+
confidence: "high",
|
|
1582
|
+
cloneBlocking: false,
|
|
1583
|
+
type: "INSECURE_CONFIGURATION",
|
|
1584
|
+
file: filePath,
|
|
1585
|
+
description: "Flask debugger is exposed on all network interfaces; disable debug mode before deployment",
|
|
1586
|
+
evidence: collectEvidence(content, [flaskDebugEnabled, wildcardBind]),
|
|
1587
|
+
codeExplanation: "Flask's interactive debugger can execute code and must not be exposed in production. This is a deployment configuration issue, not a repository backdoor."
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1307
1590
|
return findings;
|
|
1308
1591
|
}
|
|
1309
1592
|
function detectSupplyChainRisks(content, filePath) {
|
|
@@ -1352,14 +1635,14 @@ function detectSuspiciousFileAccess(content, filePath, coveredRuleIds = /* @__PU
|
|
|
1352
1635
|
{ pattern: /(?:fs\.read|readFileSync|readFile)\s*\([^)]*(?:\.ssh|\.aws|\.gnupg|\.docker|id_rsa|credentials)/gi, type: "SSH/AWS Credentials Access", severity: "critical", ruleId: "FILE_ACCESS_CREDENTIALS" },
|
|
1353
1636
|
{ pattern: /(?:fs\.read|readFileSync|readFile)\s*\([^)]*(?:etc\/passwd|etc\/shadow|\.bash_history|\.zsh_history)/gi, type: "System File Access", severity: "critical", ruleId: "FILE_ACCESS_SYSTEM" },
|
|
1354
1637
|
{ pattern: /(?:fs\.read|readFileSync|readFile)\s*\([^)]*(?:Chrome|Firefox|Safari|Edge)[\w\s/\\]*(?:Cookies|Login|History)/gi, type: "Browser Data Access", severity: "critical", ruleId: "FILE_ACCESS_BROWSER_DATA" },
|
|
1355
|
-
{ pattern: /(?:fs\.write|writeFileSync|writeFile)\s*\([^)]*(?:\/etc|\/sys|\/bin|C:\\\\Windows)/gi, type: "System Directory Write", severity: "
|
|
1356
|
-
{ pattern: /(?:fs\.unlink|unlinkSync|rmSync|rm\s+-rf)/gi, type: "File Deletion", severity: "medium", ruleId: null }
|
|
1638
|
+
{ pattern: /(?:fs\.write|writeFileSync|writeFile)\s*\([^)]*(?:\/etc|\/sys|\/bin|C:\\\\Windows)/gi, type: "System Directory Write", severity: "medium", ruleId: null }
|
|
1357
1639
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1358
1640
|
for (const { pattern, type, severity } of fileAccessPatterns) {
|
|
1359
1641
|
const matches2 = content.match(pattern);
|
|
1360
1642
|
if (matches2) {
|
|
1361
1643
|
findings.push({
|
|
1362
1644
|
severity,
|
|
1645
|
+
confidence: severity === "critical" ? "high" : "medium",
|
|
1363
1646
|
type: "SUSPICIOUS_FILE_ACCESS",
|
|
1364
1647
|
file: filePath,
|
|
1365
1648
|
description: `Suspicious file access detected: ${type}`,
|
|
@@ -1369,6 +1652,18 @@ function detectSuspiciousFileAccess(content, filePath, coveredRuleIds = /* @__PU
|
|
|
1369
1652
|
});
|
|
1370
1653
|
}
|
|
1371
1654
|
}
|
|
1655
|
+
const destructiveDeletion = /(?:rm\s+-rf\s+(?:["']?(?:\/|~|\$HOME)(?!\/?(?:tmp|var\/tmp)\b)|[^\n]*[?*])|(?:fs\.)?(?:unlink|unlinkSync|rmSync)\s*\([^\n)]*(?:\.ssh|\.aws|\.gnupg|\.docker|\/etc|\/usr|\/home|Users[\\/]))/gi;
|
|
1656
|
+
if (destructiveDeletion.test(content)) {
|
|
1657
|
+
findings.push({
|
|
1658
|
+
severity: "medium",
|
|
1659
|
+
confidence: "medium",
|
|
1660
|
+
type: "SUSPICIOUS_FILE_ACCESS",
|
|
1661
|
+
file: filePath,
|
|
1662
|
+
description: "Suspicious file access detected: Destructive File Deletion",
|
|
1663
|
+
codeExplanation: "\u{1F4C1} Deletes a broad or sensitive user/system path. Verify that the target cannot escape an application-owned directory.",
|
|
1664
|
+
evidence: collectEvidence(content, destructiveDeletion)
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1372
1667
|
return findings;
|
|
1373
1668
|
}
|
|
1374
1669
|
async function detectCodeIntegrityIssues(files, allPaths, _repo) {
|
|
@@ -1385,6 +1680,7 @@ async function detectCodeIntegrityIssues(files, allPaths, _repo) {
|
|
|
1385
1680
|
if (shortVars / totalVars > 0.3) {
|
|
1386
1681
|
findings.push({
|
|
1387
1682
|
severity: "medium",
|
|
1683
|
+
confidence: "low",
|
|
1388
1684
|
type: "CODE_INTEGRITY_ISSUE",
|
|
1389
1685
|
file: file.path,
|
|
1390
1686
|
description: "Minified/obfuscated code detected in source repository",
|
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
scanGitHubRepo,
|
|
12
12
|
scanGitHubUser,
|
|
13
13
|
wantJson
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-YU3IO4GZ.js";
|
|
15
15
|
|
|
16
16
|
// src/cli.ts
|
|
17
17
|
import { parseArgs } from "util";
|
|
@@ -132,7 +132,7 @@ async function main() {
|
|
|
132
132
|
}
|
|
133
133
|
return runScanUser(target, { json: values.json, token: values.token });
|
|
134
134
|
case "mcp": {
|
|
135
|
-
const { runMcp } = await import("./mcp-
|
|
135
|
+
const { runMcp } = await import("./mcp-A3JZBGAA.js");
|
|
136
136
|
return runMcp();
|
|
137
137
|
}
|
|
138
138
|
default:
|