flagrix 0.1.3 → 0.2.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.
|
@@ -530,16 +530,36 @@ function getSeverityWeight(severity) {
|
|
|
530
530
|
};
|
|
531
531
|
return weights[severity];
|
|
532
532
|
}
|
|
533
|
-
function
|
|
534
|
-
|
|
533
|
+
function calculateSignalContributions(findings) {
|
|
534
|
+
const bySignal = /* @__PURE__ */ new Map();
|
|
535
535
|
for (const finding of findings) {
|
|
536
|
-
|
|
536
|
+
const confidenceMultiplier = finding.confidence === "low" ? 0.25 : finding.confidence === "medium" ? 0.6 : 1;
|
|
537
|
+
const weight = 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
|
+
const existing = bySignal.get(signal);
|
|
541
|
+
if (!existing) {
|
|
542
|
+
bySignal.set(signal, { signal, weight, finding, findingCount: 1 });
|
|
543
|
+
} else {
|
|
544
|
+
existing.findingCount++;
|
|
545
|
+
if (weight > existing.weight) {
|
|
546
|
+
existing.weight = weight;
|
|
547
|
+
existing.finding = finding;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
537
550
|
}
|
|
538
|
-
return
|
|
551
|
+
return [...bySignal.values()];
|
|
552
|
+
}
|
|
553
|
+
function calculateRawRiskScore(findings) {
|
|
554
|
+
return calculateSignalContributions(findings).reduce((sum, contribution) => sum + contribution.weight, 0);
|
|
555
|
+
}
|
|
556
|
+
function calculateRiskScore(findings) {
|
|
557
|
+
return Math.min(1, calculateRawRiskScore(findings));
|
|
539
558
|
}
|
|
540
559
|
function getRiskLevel(score, findings) {
|
|
541
|
-
if (findings?.some((f) => f.severity === "critical"))
|
|
560
|
+
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")) {
|
|
542
561
|
return "high";
|
|
562
|
+
}
|
|
543
563
|
if (score < RISK_THRESHOLDS.low)
|
|
544
564
|
return "low";
|
|
545
565
|
if (score < RISK_THRESHOLDS.high)
|
|
@@ -549,10 +569,10 @@ function getRiskLevel(score, findings) {
|
|
|
549
569
|
|
|
550
570
|
// node_modules/@flagrix/scanner-core/dist/rules/rule-matcher.js
|
|
551
571
|
var TEST_FILE_PATTERNS = [
|
|
552
|
-
/__tests__\//i,
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
572
|
+
/(?:^|\/)__tests__\//i,
|
|
573
|
+
/(?:^|\/)tests?\//i,
|
|
574
|
+
/(?:^|\/)spec\//i,
|
|
575
|
+
/(?:^|\/)benchmarks?\//i,
|
|
556
576
|
/\.test\.[jt]sx?$/i,
|
|
557
577
|
/\.spec\.[jt]sx?$/i,
|
|
558
578
|
/_test\.[jt]sx?$/i,
|
|
@@ -568,28 +588,99 @@ var TEST_FILE_PATTERNS = [
|
|
|
568
588
|
function isTestFile(filePath) {
|
|
569
589
|
return TEST_FILE_PATTERNS.some((pattern) => pattern.test(filePath));
|
|
570
590
|
}
|
|
571
|
-
|
|
591
|
+
var KEYBOARD_LISTENER = /(?:addEventListener\s*\(\s*['"](?:keydown|keypress|keyup)['"]|\.on(?:keydown|keypress|keyup)\s*=)/gi;
|
|
592
|
+
var KEY_VALUE = /\b[A-Za-z_$][\w$]*\.(?:key|code|keyCode|which)\b/gi;
|
|
593
|
+
var KEYBOARD_SINKS = [
|
|
594
|
+
/(?:fetch|axios\.(?:post|put|patch)|navigator\.sendBeacon|XMLHttpRequest|WebSocket)\b/gi,
|
|
595
|
+
/(?:localStorage|sessionStorage)\.setItem\s*\(/gi,
|
|
596
|
+
/(?:writeFile|writeFileSync|appendFile|appendFileSync)\s*\(/gi,
|
|
597
|
+
/\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,
|
|
598
|
+
/(?:\+=|\.push\s*\()\s*\b[A-Za-z_$][\w$]*\.(?:key|code|keyCode|which)\b/gi
|
|
599
|
+
];
|
|
600
|
+
var PLACEHOLDER_SECRET_WORDS = /(?:^|[-_.\s])(?:your|change|replace|example|dummy|placeholder|development|dev|test|sample|not[-_]?secret|changeme)(?:$|[-_.\s])/i;
|
|
601
|
+
function isObviousPlaceholderSecret(match) {
|
|
602
|
+
const quotedValue = match.match(/['"]([^'"]+)['"]\s*$/)?.[1];
|
|
603
|
+
if (!quotedValue)
|
|
604
|
+
return false;
|
|
605
|
+
return PLACEHOLDER_SECRET_WORDS.test(quotedValue);
|
|
606
|
+
}
|
|
607
|
+
function isDocumentedAwsExampleKey(match) {
|
|
608
|
+
return /\bAKIAIOSFODNN7EXAMPLE\b/.test(match);
|
|
609
|
+
}
|
|
610
|
+
var CASE_SENSITIVE_RULE_IDS = /* @__PURE__ */ new Set([
|
|
611
|
+
"HARDCODED_AWS_KEY",
|
|
612
|
+
"HARDCODED_GITHUB_TOKEN",
|
|
613
|
+
"HARDCODED_STRIPE_KEY",
|
|
614
|
+
"NETWORK_TELEGRAM_TOKEN"
|
|
615
|
+
]);
|
|
616
|
+
function detectKeyboardCapture(content) {
|
|
617
|
+
const listeners = [...content.matchAll(KEYBOARD_LISTENER)];
|
|
618
|
+
for (const listener of listeners) {
|
|
619
|
+
const start = listener.index ?? 0;
|
|
620
|
+
const region = content.slice(start, start + 2e3);
|
|
621
|
+
if (!KEY_VALUE.test(region))
|
|
622
|
+
continue;
|
|
623
|
+
KEY_VALUE.lastIndex = 0;
|
|
624
|
+
const sink = KEYBOARD_SINKS.find((pattern) => {
|
|
625
|
+
pattern.lastIndex = 0;
|
|
626
|
+
return pattern.test(region);
|
|
627
|
+
});
|
|
628
|
+
if (sink) {
|
|
629
|
+
KEYBOARD_LISTENER.lastIndex = 0;
|
|
630
|
+
KEY_VALUE.lastIndex = 0;
|
|
631
|
+
sink.lastIndex = 0;
|
|
632
|
+
return { evidencePatterns: [KEYBOARD_LISTENER, KEY_VALUE, sink] };
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
KEYBOARD_LISTENER.lastIndex = 0;
|
|
636
|
+
KEY_VALUE.lastIndex = 0;
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
function applyYaraRules(content, rules, filePath, scopePath = filePath) {
|
|
572
640
|
const findings = [];
|
|
573
|
-
const isTest = isTestFile(
|
|
641
|
+
const isTest = isTestFile(scopePath);
|
|
574
642
|
for (const rule of rules) {
|
|
575
643
|
try {
|
|
576
|
-
if (
|
|
644
|
+
if (isTest)
|
|
645
|
+
continue;
|
|
646
|
+
if (rule.fileExtensions && rule.fileExtensions.length > 0 && !rule.fileExtensions.some((ext) => scopePath.endsWith(ext))) {
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
if (rule.fileNames && rule.fileNames.length > 0 && !rule.fileNames.includes(scopePath.split("/").pop() ?? scopePath)) {
|
|
577
650
|
continue;
|
|
578
651
|
}
|
|
579
|
-
const regex = new RegExp(rule.pattern, "gi");
|
|
652
|
+
const regex = new RegExp(rule.pattern, CASE_SENSITIVE_RULE_IDS.has(rule.id) ? "g" : "gi");
|
|
580
653
|
const matches2 = content.match(regex);
|
|
581
654
|
const required = rule.minMatches && rule.minMatches > 1 ? rule.minMatches : 1;
|
|
582
655
|
if (matches2 && matches2.length >= required) {
|
|
583
|
-
if (
|
|
656
|
+
if (rule.id === "HARDCODED_AWS_KEY" && matches2.every(isDocumentedAwsExampleKey)) {
|
|
584
657
|
continue;
|
|
585
658
|
}
|
|
659
|
+
if (rule.id === "HARDCODED_API_KEY" && matches2.every(isObviousPlaceholderSecret)) {
|
|
660
|
+
findings.push({
|
|
661
|
+
severity: "low",
|
|
662
|
+
confidence: "high",
|
|
663
|
+
cloneBlocking: false,
|
|
664
|
+
type: "INSECURE_CONFIGURATION",
|
|
665
|
+
file: filePath,
|
|
666
|
+
pattern: rule.id,
|
|
667
|
+
description: "Predictable placeholder secret must be replaced before deployment",
|
|
668
|
+
evidence: collectEvidence(content, regex)
|
|
669
|
+
});
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
const contextName = rule.context ?? (rule.id === "EXFIL_KEYLOGGER" ? "keyboard-capture" : void 0);
|
|
673
|
+
const context = contextName === "keyboard-capture" ? detectKeyboardCapture(content) : null;
|
|
674
|
+
if (contextName && !context)
|
|
675
|
+
continue;
|
|
586
676
|
findings.push({
|
|
587
677
|
severity: rule.severity,
|
|
678
|
+
confidence: rule.confidence ?? "high",
|
|
588
679
|
type: "MALWARE_SIGNATURE",
|
|
589
680
|
file: filePath,
|
|
590
681
|
pattern: rule.id,
|
|
591
682
|
description: rule.description,
|
|
592
|
-
evidence: collectEvidence(content, regex)
|
|
683
|
+
evidence: collectEvidence(content, context?.evidencePatterns ?? regex)
|
|
593
684
|
});
|
|
594
685
|
}
|
|
595
686
|
} catch {
|
|
@@ -609,11 +700,73 @@ var PRIORITY_FILES = [
|
|
|
609
700
|
".yarnrc",
|
|
610
701
|
"Makefile"
|
|
611
702
|
];
|
|
612
|
-
var SCANNABLE_EXTENSIONS = [
|
|
613
|
-
|
|
703
|
+
var SCANNABLE_EXTENSIONS = [
|
|
704
|
+
".js",
|
|
705
|
+
".jsx",
|
|
706
|
+
".mjs",
|
|
707
|
+
".cjs",
|
|
708
|
+
".ts",
|
|
709
|
+
".tsx",
|
|
710
|
+
".py",
|
|
711
|
+
".rb",
|
|
712
|
+
".php",
|
|
713
|
+
".go",
|
|
714
|
+
".sh",
|
|
715
|
+
".ps1",
|
|
716
|
+
".psm1",
|
|
717
|
+
".bat",
|
|
718
|
+
".cmd",
|
|
719
|
+
".vbs",
|
|
720
|
+
".html",
|
|
721
|
+
".htm"
|
|
722
|
+
];
|
|
723
|
+
var CONFIG_FILE_PATTERNS = [
|
|
724
|
+
/(?:^|\/)\.vscode\/(?:tasks|settings|launch|mcp)\.json$/,
|
|
725
|
+
/(?:^|\/)\.claude\/settings(?:\.local)?\.json$/,
|
|
726
|
+
/(?:^|\/)\.(?:cursor|amazonq|gemini|windsurf|roo|kiro)\/(?:mcp|settings)\.json$/,
|
|
727
|
+
/(?:^|\/)\.mcp\.json$/,
|
|
728
|
+
/^\.github\/workflows\/[^/]+\.ya?ml$/,
|
|
729
|
+
/^README(?:\.md|\.txt|\.rst)?$/i,
|
|
730
|
+
/(?:^|\/)(?:AGENTS|CLAUDE|GEMINI)\.md$/,
|
|
731
|
+
/(?:^|\/)\.(?:cursorrules|windsurfrules|clinerules)$/,
|
|
732
|
+
/(?:^|\/)\.cursor\/rules\/[^/]+\.mdc?$/,
|
|
733
|
+
/^\.github\/copilot-instructions\.md$/
|
|
734
|
+
];
|
|
735
|
+
var UTF8 = new TextDecoder("utf-8");
|
|
736
|
+
function decodeUtf8(binary) {
|
|
737
|
+
const bytes = new Uint8Array(binary.length);
|
|
738
|
+
for (let index = 0; index < binary.length; index++)
|
|
739
|
+
bytes[index] = binary.charCodeAt(index);
|
|
740
|
+
return UTF8.decode(bytes);
|
|
741
|
+
}
|
|
742
|
+
function isConfigFile(path) {
|
|
743
|
+
return CONFIG_FILE_PATTERNS.some((pattern) => pattern.test(path));
|
|
744
|
+
}
|
|
745
|
+
var FONT_EXTENSIONS = [".woff", ".woff2", ".ttf", ".otf", ".eot"];
|
|
746
|
+
var MAX_FONT_FILES = 10;
|
|
747
|
+
var MAX_FONT_BYTES = 512 * 1024;
|
|
748
|
+
function isFontFile(path) {
|
|
749
|
+
return FONT_EXTENSIONS.some((ext) => path.toLowerCase().endsWith(ext));
|
|
750
|
+
}
|
|
751
|
+
var MAX_CONFIG_FILES = 25;
|
|
752
|
+
var MAX_FILES_TO_SCAN = 200;
|
|
753
|
+
var MAX_FILE_SIZE_BYTES = 1024 * 1024;
|
|
754
|
+
var MAX_SKIPPED_FILES_LISTED = 500;
|
|
614
755
|
var NPM_DOWNLOAD_CACHE = /* @__PURE__ */ new Map();
|
|
615
756
|
var NPM_CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
616
757
|
var NPM_HIGH_DOWNLOAD_THRESHOLD = 1e5;
|
|
758
|
+
function maskExceptInlineScripts(content) {
|
|
759
|
+
const masked = [...content].map((char) => char === "\n" || char === "\r" ? char : " ");
|
|
760
|
+
const script2 = /<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi;
|
|
761
|
+
for (const match of content.matchAll(script2)) {
|
|
762
|
+
const body = match[1] ?? "";
|
|
763
|
+
const bodyOffset = (match.index ?? 0) + match[0].indexOf(body);
|
|
764
|
+
for (let index = 0; index < body.length; index++) {
|
|
765
|
+
masked[bodyOffset + index] = body[index];
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
return masked.join("");
|
|
769
|
+
}
|
|
617
770
|
async function scanGitHubRepo(repo, options) {
|
|
618
771
|
const findings = [];
|
|
619
772
|
let filesScanned = 0;
|
|
@@ -656,10 +809,54 @@ async function scanGitHubRepo(repo, options) {
|
|
|
656
809
|
throw await githubApiError(treeResponse);
|
|
657
810
|
}
|
|
658
811
|
const tree = await treeResponse.json();
|
|
659
|
-
const
|
|
812
|
+
const skippedFiles = [];
|
|
813
|
+
let skippedCount = 0;
|
|
814
|
+
const skip = (path, reason) => {
|
|
815
|
+
skippedCount++;
|
|
816
|
+
if (skippedFiles.length < MAX_SKIPPED_FILES_LISTED) {
|
|
817
|
+
skippedFiles.push({ path, reason });
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
const extraFiles = [];
|
|
821
|
+
let configSelected = 0;
|
|
822
|
+
let fontsSelected = 0;
|
|
823
|
+
const sourceBlobs = [];
|
|
824
|
+
for (const item of tree.tree) {
|
|
825
|
+
if (item.type !== "blob")
|
|
826
|
+
continue;
|
|
827
|
+
const config = isConfigFile(item.path);
|
|
828
|
+
const font = !config && isFontFile(item.path);
|
|
829
|
+
if (config || font) {
|
|
830
|
+
const sizeLimit = font ? MAX_FONT_BYTES : MAX_FILE_SIZE_BYTES;
|
|
831
|
+
if (item.size !== void 0 && item.size > sizeLimit) {
|
|
832
|
+
skip(item.path, "too-large");
|
|
833
|
+
} else if (config ? configSelected >= MAX_CONFIG_FILES : fontsSelected >= MAX_FONT_FILES) {
|
|
834
|
+
skip(item.path, "over-file-limit");
|
|
835
|
+
} else {
|
|
836
|
+
if (config)
|
|
837
|
+
configSelected++;
|
|
838
|
+
else
|
|
839
|
+
fontsSelected++;
|
|
840
|
+
extraFiles.push(item);
|
|
841
|
+
}
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
const eligible = PRIORITY_FILES.some((pf) => item.path.endsWith(pf)) || SCANNABLE_EXTENSIONS.some((ext) => item.path.endsWith(ext));
|
|
845
|
+
if (!eligible) {
|
|
846
|
+
skip(item.path, "unsupported-type");
|
|
847
|
+
} else if (item.size !== void 0 && item.size > MAX_FILE_SIZE_BYTES) {
|
|
848
|
+
skip(item.path, "too-large");
|
|
849
|
+
} else if (sourceBlobs.length >= MAX_FILES_TO_SCAN) {
|
|
850
|
+
skip(item.path, "over-file-limit");
|
|
851
|
+
} else {
|
|
852
|
+
sourceBlobs.push(item);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const filesToScan = [...extraFiles, ...sourceBlobs];
|
|
660
856
|
const hiddenFiles = tree.tree.filter((item) => item.path.startsWith(".") && !item.path.startsWith(".github") && !item.path.startsWith(".git") && item.type === "blob");
|
|
661
857
|
for (const hidden of hiddenFiles) {
|
|
662
|
-
|
|
858
|
+
const basename = hidden.path.split("/").pop() ?? hidden.path;
|
|
859
|
+
if (/^\.(?:backdoor|payload|reverse[-_]?shell)(?:\.|$)/i.test(basename)) {
|
|
663
860
|
findings.push({
|
|
664
861
|
severity: "high",
|
|
665
862
|
type: "HIDDEN_FILE",
|
|
@@ -673,16 +870,23 @@ async function scanGitHubRepo(repo, options) {
|
|
|
673
870
|
const yaraRules = options.signatures.yaraRules;
|
|
674
871
|
const loadedRuleIds = new Set(yaraRules.map((r) => r.id));
|
|
675
872
|
const fileContents = [];
|
|
873
|
+
const scannedFiles = [];
|
|
676
874
|
for (const file of filesToScan) {
|
|
677
|
-
filesScanned++;
|
|
678
875
|
const contentUrl = `https://api.github.com/repos/${repo.owner}/${repo.repo}/contents/${file.path}?ref=${commitSha}`;
|
|
679
876
|
const contentResponse = await fetch(contentUrl, { headers });
|
|
680
|
-
if (!contentResponse.ok)
|
|
877
|
+
if (!contentResponse.ok) {
|
|
878
|
+
skip(file.path, "fetch-failed");
|
|
681
879
|
continue;
|
|
880
|
+
}
|
|
881
|
+
filesScanned++;
|
|
882
|
+
scannedFiles.push(file.path);
|
|
682
883
|
const fileData = await contentResponse.json();
|
|
683
|
-
const
|
|
684
|
-
const
|
|
685
|
-
|
|
884
|
+
const binary = atob(fileData.content || "");
|
|
885
|
+
const content = isFontFile(file.path) ? binary : decodeUtf8(binary);
|
|
886
|
+
const isHtml = /\.html?$/i.test(file.path);
|
|
887
|
+
const isJsTs = /\.(?:[cm]?js|ts|[jt]sx)$/i.test(file.path);
|
|
888
|
+
const scriptContent = isHtml ? maskExceptInlineScripts(content) : content;
|
|
889
|
+
let matchable = isJsTs || isHtml ? maskRegexLiterals(scriptContent) : scriptContent;
|
|
686
890
|
if (isJsTs && isTestFile(file.path)) {
|
|
687
891
|
matchable = maskStringLiterals(matchable);
|
|
688
892
|
}
|
|
@@ -698,13 +902,30 @@ async function scanGitHubRepo(repo, options) {
|
|
|
698
902
|
findings.push(...postinstallFindings);
|
|
699
903
|
patternsMatched += postinstallFindings.length;
|
|
700
904
|
}
|
|
905
|
+
if (isFontFile(file.path)) {
|
|
906
|
+
const masquerade = detectMasqueradedScript(content, file.path);
|
|
907
|
+
findings.push(...masquerade);
|
|
908
|
+
patternsMatched += masquerade.length;
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
if (!SCANNABLE_EXTENSIONS.some((ext) => file.path.endsWith(ext)) && (isConfigFile(file.path) || file.path.endsWith("package.json"))) {
|
|
912
|
+
const configFindings = applyYaraRules(content, yaraRules, file.path);
|
|
913
|
+
findings.push(...configFindings);
|
|
914
|
+
patternsMatched += configFindings.length;
|
|
915
|
+
if (/^README/i.test(file.path)) {
|
|
916
|
+
const socialFindings = detectSocialEngineering(content, file.path);
|
|
917
|
+
findings.push(...socialFindings);
|
|
918
|
+
patternsMatched += socialFindings.length;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
701
921
|
if (file.path.endsWith("requirements.txt") || file.path.endsWith("setup.py")) {
|
|
702
922
|
const pyFindings = scanPythonDeps(content, maliciousPackages, file.path);
|
|
703
923
|
findings.push(...pyFindings);
|
|
704
924
|
patternsMatched += pyFindings.length;
|
|
705
925
|
}
|
|
706
926
|
if (SCANNABLE_EXTENSIONS.some((ext) => file.path.endsWith(ext))) {
|
|
707
|
-
const
|
|
927
|
+
const ruleScopePath = isHtml ? `${file.path}.js` : file.path;
|
|
928
|
+
const yaraFindings = applyYaraRules(matchable, yaraRules, file.path, ruleScopePath);
|
|
708
929
|
findings.push(...yaraFindings);
|
|
709
930
|
patternsMatched += yaraFindings.length;
|
|
710
931
|
const obfuscationFindings = detectObfuscation(matchable, file.path, loadedRuleIds);
|
|
@@ -753,22 +974,38 @@ async function scanGitHubRepo(repo, options) {
|
|
|
753
974
|
const integrityFindings = await detectCodeIntegrityIssues(fileContents, allPaths, repo);
|
|
754
975
|
findings.push(...integrityFindings);
|
|
755
976
|
patternsMatched += integrityFindings.length;
|
|
977
|
+
const rawRiskScore = calculateRawRiskScore(findings);
|
|
756
978
|
const riskScore = calculateRiskScore(findings);
|
|
757
979
|
const riskLevel = getRiskLevel(riskScore, findings);
|
|
980
|
+
const cloneBlockingFindings = findings.filter((finding) => finding.cloneBlocking !== false);
|
|
981
|
+
const cloneRiskScore = calculateRiskScore(cloneBlockingFindings);
|
|
982
|
+
const cloneRiskLevel = getRiskLevel(cloneRiskScore, cloneBlockingFindings);
|
|
758
983
|
return {
|
|
759
984
|
riskScore,
|
|
985
|
+
rawRiskScore,
|
|
760
986
|
riskLevel,
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
987
|
+
// One factor per deduped signal, carrying the confidence-adjusted
|
|
988
|
+
// weight actually counted — factors always sum to rawRiskScore, so
|
|
989
|
+
// consumers can render a deduction breakdown that reconciles.
|
|
990
|
+
factors: calculateSignalContributions(findings).map((c) => ({
|
|
991
|
+
factor: c.finding.type,
|
|
992
|
+
weight: c.weight,
|
|
993
|
+
description: c.findingCount > 1 ? `${c.finding.description} (strongest of ${c.findingCount} matches counted once)` : c.finding.description
|
|
765
994
|
})),
|
|
766
995
|
disclaimer: DEFAULT_DISCLAIMER,
|
|
767
996
|
repo,
|
|
768
997
|
commitSha,
|
|
769
|
-
scanSummary: {
|
|
998
|
+
scanSummary: {
|
|
999
|
+
filesScanned,
|
|
1000
|
+
patternsMatched,
|
|
1001
|
+
dependenciesChecked,
|
|
1002
|
+
scannedFiles,
|
|
1003
|
+
skippedFiles,
|
|
1004
|
+
skippedCount,
|
|
1005
|
+
treeTruncated: tree.truncated
|
|
1006
|
+
},
|
|
770
1007
|
findings,
|
|
771
|
-
safeToClone:
|
|
1008
|
+
safeToClone: cloneRiskLevel === "low",
|
|
772
1009
|
scannedAt: /* @__PURE__ */ new Date()
|
|
773
1010
|
};
|
|
774
1011
|
} catch (error) {
|
|
@@ -780,11 +1017,12 @@ async function scanPackageJson(content, maliciousPackages, filePath) {
|
|
|
780
1017
|
try {
|
|
781
1018
|
const pkg = JSON.parse(content);
|
|
782
1019
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
783
|
-
for (const [name] of Object.entries(allDeps)) {
|
|
1020
|
+
for (const [name, declaredVersion] of Object.entries(allDeps)) {
|
|
784
1021
|
const malicious = maliciousPackages.find((m) => m.name === name);
|
|
785
|
-
if (malicious) {
|
|
1022
|
+
if (malicious && isAffectedPackageVersion(malicious, declaredVersion)) {
|
|
786
1023
|
findings.push({
|
|
787
1024
|
severity: malicious.severity,
|
|
1025
|
+
confidence: "high",
|
|
788
1026
|
type: "SUSPICIOUS_DEPENDENCY",
|
|
789
1027
|
file: filePath,
|
|
790
1028
|
package: name,
|
|
@@ -812,6 +1050,23 @@ async function scanPackageJson(content, maliciousPackages, filePath) {
|
|
|
812
1050
|
}
|
|
813
1051
|
return findings;
|
|
814
1052
|
}
|
|
1053
|
+
function isAffectedPackageVersion(malicious, declaredVersion) {
|
|
1054
|
+
const affected = malicious.versions ?? (malicious.version ? [malicious.version] : []);
|
|
1055
|
+
if (affected.length === 0)
|
|
1056
|
+
return true;
|
|
1057
|
+
if (typeof declaredVersion !== "string")
|
|
1058
|
+
return false;
|
|
1059
|
+
let specifier = declaredVersion.trim();
|
|
1060
|
+
if (specifier.startsWith("workspace:"))
|
|
1061
|
+
specifier = specifier.slice("workspace:".length);
|
|
1062
|
+
const npmAlias = specifier.match(/^npm:.+@([^@]+)$/);
|
|
1063
|
+
if (npmAlias)
|
|
1064
|
+
specifier = npmAlias[1];
|
|
1065
|
+
return specifier.split(/\s*\|\|\s*/).some((part) => {
|
|
1066
|
+
const normalized = part.trim().replace(/^[=v~^\s]+/, "");
|
|
1067
|
+
return affected.includes(normalized);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
815
1070
|
function checkPostinstallScripts(content, filePath) {
|
|
816
1071
|
const findings = [];
|
|
817
1072
|
try {
|
|
@@ -854,6 +1109,7 @@ function scanPythonDeps(content, maliciousPackages, filePath) {
|
|
|
854
1109
|
if (malicious) {
|
|
855
1110
|
findings.push({
|
|
856
1111
|
severity: malicious.severity,
|
|
1112
|
+
confidence: "high",
|
|
857
1113
|
type: "SUSPICIOUS_DEPENDENCY",
|
|
858
1114
|
file: filePath,
|
|
859
1115
|
package: name,
|
|
@@ -864,6 +1120,37 @@ function scanPythonDeps(content, maliciousPackages, filePath) {
|
|
|
864
1120
|
}
|
|
865
1121
|
return findings;
|
|
866
1122
|
}
|
|
1123
|
+
var FONT_MAGIC = ["wOFF", "wOF2", "\0\0\0", "OTTO", "true", "ttcf"];
|
|
1124
|
+
var SCRIPT_TOKENS = /\b(?:require\s*\(|import\s+[\w{*]|function\s*\w*\s*\(|const\s+\w+\s*=|let\s+\w+\s*=|var\s+\w+\s*=|eval\s*\(|new\s+Function|module\.exports|process\.env|child_process)/;
|
|
1125
|
+
function detectMasqueradedScript(content, filePath) {
|
|
1126
|
+
if (FONT_MAGIC.some((magic) => content.startsWith(magic)))
|
|
1127
|
+
return [];
|
|
1128
|
+
if (filePath.toLowerCase().endsWith(".eot") && content.slice(34, 36) === "LP")
|
|
1129
|
+
return [];
|
|
1130
|
+
if (content.startsWith("version https://git-lfs.github.com/spec/"))
|
|
1131
|
+
return [];
|
|
1132
|
+
const head = content.slice(0, 8192);
|
|
1133
|
+
if (head.length === 0)
|
|
1134
|
+
return [];
|
|
1135
|
+
let printable = 0;
|
|
1136
|
+
for (let index = 0; index < head.length; index++) {
|
|
1137
|
+
const code = head.charCodeAt(index);
|
|
1138
|
+
if (code === 9 || code === 10 || code === 13 || code >= 32 && code < 127)
|
|
1139
|
+
printable++;
|
|
1140
|
+
}
|
|
1141
|
+
if (printable / head.length < 0.95 || !SCRIPT_TOKENS.test(content))
|
|
1142
|
+
return [];
|
|
1143
|
+
return [{
|
|
1144
|
+
severity: "critical",
|
|
1145
|
+
confidence: "high",
|
|
1146
|
+
type: "OBFUSCATED_CODE",
|
|
1147
|
+
pattern: "MASQUERADED_SCRIPT_FONT",
|
|
1148
|
+
file: filePath,
|
|
1149
|
+
description: `JavaScript disguised as a font file: ${filePath}`,
|
|
1150
|
+
codeSnippet: content.trimStart().slice(0, 200),
|
|
1151
|
+
codeExplanation: "\u{1F3AD} This file has a font extension but contains readable JavaScript, not font data. Fake font files are run with `node <file>` from VS Code tasks or hooks to hide a loader from code review."
|
|
1152
|
+
}];
|
|
1153
|
+
}
|
|
867
1154
|
var BUILTIN_OBFUSCATION_RULE_IDS = {
|
|
868
1155
|
base64: "OBF_BASE64_HEAVY",
|
|
869
1156
|
hex: "OBF_HEX_STRINGS",
|
|
@@ -947,12 +1234,13 @@ function detectObfuscation(content, filePath, coveredRuleIds = /* @__PURE__ */ n
|
|
|
947
1234
|
const maxLength = Math.max(...suspiciousLines.map((l) => l.length));
|
|
948
1235
|
const linesWithMaliciousCode = suspiciousLines.filter((l) => l.hasMaliciousPattern);
|
|
949
1236
|
const lineDetails = suspiciousLines.slice(0, 3).map((l) => `Line ${l.lineNum} (${l.length.toLocaleString()} chars${l.hasMaliciousPattern ? ", contains suspicious code" : ""})`).join(", ");
|
|
950
|
-
const severity =
|
|
1237
|
+
const severity = "medium";
|
|
951
1238
|
const firstLine = lines[suspiciousLines[0].lineNum - 1];
|
|
952
1239
|
const codeSnippet = extractCodeSnippet(firstLine);
|
|
953
1240
|
const codeExplanation = explainSuspiciousCode(firstLine, "OBFUSCATED_CODE");
|
|
954
1241
|
findings.push({
|
|
955
1242
|
severity,
|
|
1243
|
+
confidence: linesWithMaliciousCode.length > 0 ? "medium" : "low",
|
|
956
1244
|
type: "OBFUSCATED_CODE",
|
|
957
1245
|
file: filePath,
|
|
958
1246
|
line: suspiciousLines[0].lineNum,
|
|
@@ -1186,31 +1474,54 @@ function detectHardcodedSecrets(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1186
1474
|
if (isTestFile(filePath))
|
|
1187
1475
|
return findings;
|
|
1188
1476
|
const secretPatterns = [
|
|
1189
|
-
{ pattern: /(?:api[_-]?key|apikey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "API Key", severity: "
|
|
1190
|
-
{ pattern: /(?:secret[_-]?key|secret)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Secret Key", severity: "
|
|
1191
|
-
{ pattern: /(?:password|passwd|pwd)\s*[:=]\s*['"]([^'"]{8,})['"]/gi, type: "Password", severity: "
|
|
1192
|
-
{ pattern: /(?:token|auth[_-]?token)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Auth Token", severity: "
|
|
1193
|
-
{ pattern: /(?:private[_-]?key|privatekey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Private Key", severity: "
|
|
1477
|
+
{ pattern: /(?:api[_-]?key|apikey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "API Key", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1478
|
+
{ pattern: /(?:secret[_-]?key|secret)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Secret Key", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1479
|
+
{ pattern: /(?:password|passwd|pwd)\s*[:=]\s*['"]([^'"]{8,})['"]/gi, type: "Password", severity: "medium", ruleId: null },
|
|
1480
|
+
{ pattern: /(?:token|auth[_-]?token)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Auth Token", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1481
|
+
{ pattern: /(?:private[_-]?key|privatekey)\s*[:=]\s*['"]([^'"]{20,})['"]/gi, type: "Private Key", severity: "high", ruleId: "HARDCODED_API_KEY" },
|
|
1194
1482
|
{ pattern: /AKIA[0-9A-Z]{16}/g, type: "AWS Access Key", severity: "critical", ruleId: "HARDCODED_AWS_KEY" },
|
|
1195
1483
|
{ pattern: /ghp_[a-zA-Z0-9]{36}/g, type: "GitHub Personal Access Token", severity: "critical", ruleId: "HARDCODED_GITHUB_TOKEN" },
|
|
1196
1484
|
{ pattern: /gho_[a-zA-Z0-9]{36}/g, type: "GitHub OAuth Token", severity: "critical", ruleId: "HARDCODED_GITHUB_TOKEN" },
|
|
1197
1485
|
{ pattern: /sk_live_[a-zA-Z0-9]{24,}/g, type: "Stripe Live Key", severity: "critical", ruleId: "HARDCODED_STRIPE_KEY" },
|
|
1198
|
-
{ pattern: /(?:mongodb|mongo)[+:\/\/]{0,6}[^@\s]+:[^@\s]+@/gi, type: "MongoDB Connection String", severity: "
|
|
1199
|
-
{ pattern: /postgres:\/\/[^@\s]+:[^@\s]+@/gi, type: "PostgreSQL Connection String", severity: "
|
|
1486
|
+
{ pattern: /(?:mongodb|mongo)[+:\/\/]{0,6}[^@\s]+:[^@\s]+@/gi, type: "MongoDB Connection String", severity: "medium", ruleId: "HARDCODED_DB_CONNECTION" },
|
|
1487
|
+
{ pattern: /postgres:\/\/[^@\s]+:[^@\s]+@/gi, type: "PostgreSQL Connection String", severity: "medium", ruleId: "HARDCODED_DB_CONNECTION" }
|
|
1200
1488
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1201
1489
|
const foundSecrets = [];
|
|
1202
1490
|
const matchedRegexes = [];
|
|
1491
|
+
const placeholderRegexes = [];
|
|
1203
1492
|
for (const { pattern, type, severity } of secretPatterns) {
|
|
1204
1493
|
const matches2 = content.match(pattern);
|
|
1205
1494
|
if (matches2 && matches2.length > 0) {
|
|
1206
|
-
|
|
1495
|
+
const genericSecret = ["API Key", "Secret Key", "Auth Token", "Private Key"].includes(type);
|
|
1496
|
+
const actionableMatches = type === "AWS Access Key" ? matches2.filter((match) => !isDocumentedAwsExampleKey(match)) : genericSecret ? matches2.filter((match) => !isObviousPlaceholderSecret(match)) : matches2;
|
|
1497
|
+
if (actionableMatches.length === 0) {
|
|
1498
|
+
placeholderRegexes.push(pattern);
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1501
|
+
foundSecrets.push({
|
|
1502
|
+
type,
|
|
1503
|
+
match: actionableMatches[0].substring(0, 50) + "...",
|
|
1504
|
+
severity
|
|
1505
|
+
});
|
|
1207
1506
|
matchedRegexes.push(pattern);
|
|
1208
1507
|
}
|
|
1209
1508
|
}
|
|
1509
|
+
if (placeholderRegexes.length > 0) {
|
|
1510
|
+
findings.push({
|
|
1511
|
+
severity: "low",
|
|
1512
|
+
confidence: "high",
|
|
1513
|
+
cloneBlocking: false,
|
|
1514
|
+
type: "INSECURE_CONFIGURATION",
|
|
1515
|
+
file: filePath,
|
|
1516
|
+
description: "Predictable placeholder secret must be replaced before deployment",
|
|
1517
|
+
evidence: collectEvidence(content, placeholderRegexes)
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1210
1520
|
if (foundSecrets.length > 0) {
|
|
1211
|
-
const highestSeverity = foundSecrets.some((s) => s.severity === "critical") ? "critical" : "high";
|
|
1521
|
+
const highestSeverity = foundSecrets.some((s) => s.severity === "critical") ? "critical" : foundSecrets.some((s) => s.severity === "high") ? "high" : "medium";
|
|
1212
1522
|
findings.push({
|
|
1213
1523
|
severity: highestSeverity,
|
|
1524
|
+
confidence: highestSeverity === "critical" ? "high" : "medium",
|
|
1214
1525
|
type: "HARDCODED_SECRETS",
|
|
1215
1526
|
file: filePath,
|
|
1216
1527
|
description: `Hardcoded credentials detected: ${foundSecrets.map((s) => s.type).join(", ")}`,
|
|
@@ -1229,7 +1540,7 @@ function detectNetworkPatterns(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1229
1540
|
// Valid public IPv4 only: each octet bounded 0–255, not embedded in a longer
|
|
1230
1541
|
// dotted/number sequence (avoids flagging version strings like "1.2.3.4.5" or
|
|
1231
1542
|
// impossible IPs like "999.999.999.999"), and excluding private/link-local ranges.
|
|
1232
|
-
{ 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: "
|
|
1543
|
+
{ 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" },
|
|
1233
1544
|
{ pattern: /https?:\/\/discord(?:app)?\.com\/api\/webhooks\/\d+\/[a-zA-Z0-9_-]+/gi, type: "Discord Webhook", severity: "critical", ruleId: "NETWORK_DISCORD_WEBHOOK" },
|
|
1234
1545
|
{ pattern: /\d{8,10}:[a-zA-Z0-9_-]{35}/g, type: "Telegram Bot Token", severity: "high", ruleId: "NETWORK_TELEGRAM_TOKEN" },
|
|
1235
1546
|
{ pattern: /(?:pastebin\.com|hastebin\.com|paste\.ee)\/[a-zA-Z0-9]+/gi, type: "Pastebin URL", severity: "medium", ruleId: "NETWORK_PASTEBIN" },
|
|
@@ -1237,7 +1548,7 @@ function detectNetworkPatterns(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1237
1548
|
{ pattern: /https?:\/\/[a-zA-Z0-9-]+\.(?:tk|ml|ga|cf|gq|onion|xyz)(?:\/|$)/gi, type: "Suspicious Domain TLD", severity: "high", ruleId: "NETWORK_SUSPICIOUS_TLD" },
|
|
1238
1549
|
{ pattern: /https?:\/\/[a-zA-Z0-9-]+\.ngrok\.io/gi, type: "Ngrok Tunnel", severity: "medium", ruleId: "NETWORK_NGROK_TUNNEL" }
|
|
1239
1550
|
].filter((p) => !("ruleId" in p) || !coveredRuleIds.has(p.ruleId));
|
|
1240
|
-
for (const { pattern, type, severity } of suspiciousPatterns) {
|
|
1551
|
+
for (const { pattern, type, severity, confidence } of suspiciousPatterns) {
|
|
1241
1552
|
const matches2 = content.match(pattern);
|
|
1242
1553
|
if (matches2 && matches2.length > 0) {
|
|
1243
1554
|
const validMatches = matches2.filter((m) => {
|
|
@@ -1248,6 +1559,7 @@ function detectNetworkPatterns(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1248
1559
|
if (validMatches.length > 0) {
|
|
1249
1560
|
findings.push({
|
|
1250
1561
|
severity,
|
|
1562
|
+
confidence: confidence ?? "high",
|
|
1251
1563
|
type: "NETWORK_COMMUNICATION",
|
|
1252
1564
|
file: filePath,
|
|
1253
1565
|
description: `Suspicious network communication detected: ${type} (${validMatches.length} occurrence${validMatches.length > 1 ? "s" : ""})`,
|
|
@@ -1302,11 +1614,9 @@ function detectDataExfiltration(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1302
1614
|
return findings;
|
|
1303
1615
|
const exfiltrationPatterns = [
|
|
1304
1616
|
{ pattern: /navigator\.clipboard\.read(?:Text)?\s*\(/gi, type: "Clipboard Access", severity: "high", ruleId: "EXFIL_CLIPBOARD" },
|
|
1305
|
-
{ pattern: /localStorage\.getItem|sessionStorage\.getItem/gi, type: "Storage Access", severity: "medium", ruleId: null },
|
|
1306
1617
|
{ pattern: /document\.cookie/gi, type: "Cookie Access", severity: "high", ruleId: "EXFIL_COOKIE" },
|
|
1307
|
-
{ pattern: /(?:addEventListener|on)\s*\(\s*['"](?:keydown|keypress|keyup)['"]/gi, type: "Keylogger Pattern", severity: "critical", ruleId: "EXFIL_KEYLOGGER" },
|
|
1308
1618
|
{ pattern: /(?:input|password|email)[\w-]*\.value/gi, type: "Form Data Access", severity: "medium", ruleId: null },
|
|
1309
|
-
{ pattern: /new\s+FormData\s*\([^)]*\)[\s\S]{0,100}(?:fetch|axios|XMLHttpRequest)/gi, type: "Form Data Transmission", severity: "
|
|
1619
|
+
{ pattern: /new\s+FormData\s*\([^)]*\)[\s\S]{0,100}(?:fetch|axios|XMLHttpRequest)/gi, type: "Form Data Transmission", severity: "medium", ruleId: null }
|
|
1310
1620
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1311
1621
|
const detectedPatterns = [];
|
|
1312
1622
|
const matchedRegexes = [];
|
|
@@ -1315,14 +1625,34 @@ function detectDataExfiltration(content, filePath, coveredRuleIds = /* @__PURE__
|
|
|
1315
1625
|
if (pattern.test(content)) {
|
|
1316
1626
|
detectedPatterns.push(type);
|
|
1317
1627
|
matchedRegexes.push(pattern);
|
|
1318
|
-
if (severity === "
|
|
1319
|
-
highestSeverity =
|
|
1320
|
-
|
|
1628
|
+
if (severity === "high")
|
|
1629
|
+
highestSeverity = "high";
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
const sensitiveStorageRead = /(?:localStorage|sessionStorage)\.getItem\s*\(\s*['"][^'"]*(?:token|secret|password|credential|session|auth|wallet|seed|private)[^'"]*['"]\s*\)/gi;
|
|
1633
|
+
for (const match of content.matchAll(sensitiveStorageRead)) {
|
|
1634
|
+
const start = match.index ?? 0;
|
|
1635
|
+
const region = content.slice(start, start + 2e3);
|
|
1636
|
+
const networkSink = /(?:fetch\s*\(|axios\.(?:post|put|patch)\s*\(|navigator\.sendBeacon\s*\(|XMLHttpRequest|WebSocket)/gi;
|
|
1637
|
+
if (networkSink.test(region)) {
|
|
1638
|
+
detectedPatterns.push("Sensitive Storage Transmission");
|
|
1639
|
+
matchedRegexes.push(sensitiveStorageRead, networkSink);
|
|
1640
|
+
highestSeverity = "high";
|
|
1641
|
+
break;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
if (!coveredRuleIds.has("EXFIL_KEYLOGGER")) {
|
|
1645
|
+
const keyboardCapture = detectKeyboardCapture(content);
|
|
1646
|
+
if (keyboardCapture) {
|
|
1647
|
+
detectedPatterns.push("Keyboard Capture and Transmission");
|
|
1648
|
+
matchedRegexes.push(...keyboardCapture.evidencePatterns);
|
|
1649
|
+
highestSeverity = "critical";
|
|
1321
1650
|
}
|
|
1322
1651
|
}
|
|
1323
1652
|
if (detectedPatterns.length > 0) {
|
|
1324
1653
|
findings.push({
|
|
1325
1654
|
severity: highestSeverity,
|
|
1655
|
+
confidence: highestSeverity === "medium" ? "low" : "high",
|
|
1326
1656
|
type: "DATA_EXFILTRATION",
|
|
1327
1657
|
file: filePath,
|
|
1328
1658
|
description: `Data exfiltration patterns detected: ${detectedPatterns.join(", ")}`,
|
|
@@ -1339,7 +1669,6 @@ function detectBackdoors(content, filePath, coveredRuleIds = /* @__PURE__ */ new
|
|
|
1339
1669
|
{ pattern: /exec\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Command Injection Endpoint", severity: "critical", ruleId: "BACKDOOR_RCE_ENDPOINT" },
|
|
1340
1670
|
{ pattern: /require\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Dynamic Require", severity: "critical", ruleId: "BACKDOOR_DYNAMIC_REQUIRE" },
|
|
1341
1671
|
{ pattern: /new\s+Function\s*\([^)]*(?:request|req)/gi, type: "Dynamic Function from Request", severity: "critical", ruleId: null },
|
|
1342
|
-
{ pattern: /(?:admin|debug|backdoor|shell)[\w]*\s*[:=]\s*(?:true|1|"[^"]*")\s*(?:\/\/|#)?\s*(?:TODO|FIXME|HACK)?/gi, type: "Debug/Admin Flag", severity: "high", ruleId: null },
|
|
1343
1672
|
{ pattern: /(?:password|auth)\s*(?:===?|==)\s*['"][^'"]{0,20}['"]\s*\)/gi, type: "Hardcoded Auth Bypass", severity: "critical", ruleId: "BACKDOOR_HARDCODED_AUTH" }
|
|
1344
1673
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1345
1674
|
for (const { pattern, type, severity } of backdoorPatterns) {
|
|
@@ -1356,6 +1685,21 @@ function detectBackdoors(content, filePath, coveredRuleIds = /* @__PURE__ */ new
|
|
|
1356
1685
|
});
|
|
1357
1686
|
}
|
|
1358
1687
|
}
|
|
1688
|
+
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;
|
|
1689
|
+
const flaskDebugEnabled = /\bdebug\s*=\s*True/gi;
|
|
1690
|
+
const wildcardBind = /\bhost\s*=\s*['"]0\.0\.0\.0['"]/gi;
|
|
1691
|
+
if (exposedFlaskDebugger.test(content)) {
|
|
1692
|
+
findings.push({
|
|
1693
|
+
severity: "low",
|
|
1694
|
+
confidence: "high",
|
|
1695
|
+
cloneBlocking: false,
|
|
1696
|
+
type: "INSECURE_CONFIGURATION",
|
|
1697
|
+
file: filePath,
|
|
1698
|
+
description: "Flask debugger is exposed on all network interfaces; disable debug mode before deployment",
|
|
1699
|
+
evidence: collectEvidence(content, [flaskDebugEnabled, wildcardBind]),
|
|
1700
|
+
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."
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1359
1703
|
return findings;
|
|
1360
1704
|
}
|
|
1361
1705
|
function detectSupplyChainRisks(content, filePath) {
|
|
@@ -1404,14 +1748,14 @@ function detectSuspiciousFileAccess(content, filePath, coveredRuleIds = /* @__PU
|
|
|
1404
1748
|
{ 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" },
|
|
1405
1749
|
{ 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" },
|
|
1406
1750
|
{ 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" },
|
|
1407
|
-
{ pattern: /(?:fs\.write|writeFileSync|writeFile)\s*\([^)]*(?:\/etc|\/sys|\/bin|C:\\\\Windows)/gi, type: "System Directory Write", severity: "
|
|
1408
|
-
{ pattern: /(?:fs\.unlink|unlinkSync|rmSync|rm\s+-rf)/gi, type: "File Deletion", severity: "medium", ruleId: null }
|
|
1751
|
+
{ pattern: /(?:fs\.write|writeFileSync|writeFile)\s*\([^)]*(?:\/etc|\/sys|\/bin|C:\\\\Windows)/gi, type: "System Directory Write", severity: "medium", ruleId: null }
|
|
1409
1752
|
].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
|
|
1410
1753
|
for (const { pattern, type, severity } of fileAccessPatterns) {
|
|
1411
1754
|
const matches2 = content.match(pattern);
|
|
1412
1755
|
if (matches2) {
|
|
1413
1756
|
findings.push({
|
|
1414
1757
|
severity,
|
|
1758
|
+
confidence: severity === "critical" ? "high" : "medium",
|
|
1415
1759
|
type: "SUSPICIOUS_FILE_ACCESS",
|
|
1416
1760
|
file: filePath,
|
|
1417
1761
|
description: `Suspicious file access detected: ${type}`,
|
|
@@ -1421,6 +1765,18 @@ function detectSuspiciousFileAccess(content, filePath, coveredRuleIds = /* @__PU
|
|
|
1421
1765
|
});
|
|
1422
1766
|
}
|
|
1423
1767
|
}
|
|
1768
|
+
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;
|
|
1769
|
+
if (destructiveDeletion.test(content)) {
|
|
1770
|
+
findings.push({
|
|
1771
|
+
severity: "medium",
|
|
1772
|
+
confidence: "medium",
|
|
1773
|
+
type: "SUSPICIOUS_FILE_ACCESS",
|
|
1774
|
+
file: filePath,
|
|
1775
|
+
description: "Suspicious file access detected: Destructive File Deletion",
|
|
1776
|
+
codeExplanation: "\u{1F4C1} Deletes a broad or sensitive user/system path. Verify that the target cannot escape an application-owned directory.",
|
|
1777
|
+
evidence: collectEvidence(content, destructiveDeletion)
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1424
1780
|
return findings;
|
|
1425
1781
|
}
|
|
1426
1782
|
async function detectCodeIntegrityIssues(files, allPaths, _repo) {
|
|
@@ -1437,6 +1793,7 @@ async function detectCodeIntegrityIssues(files, allPaths, _repo) {
|
|
|
1437
1793
|
if (shortVars / totalVars > 0.3) {
|
|
1438
1794
|
findings.push({
|
|
1439
1795
|
severity: "medium",
|
|
1796
|
+
confidence: "low",
|
|
1440
1797
|
type: "CODE_INTEGRITY_ISSUE",
|
|
1441
1798
|
file: file.path,
|
|
1442
1799
|
description: "Minified/obfuscated code detected in source repository",
|