flagrix 0.1.4 → 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,28 @@ function getSeverityWeight(severity) {
530
530
  };
531
531
  return weights[severity];
532
532
  }
533
- function calculateRawRiskScore(findings) {
534
- const strongestBySignal = /* @__PURE__ */ new Map();
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 contribution = getSeverityWeight(finding.severity) * confidenceMultiplier;
537
+ const weight = getSeverityWeight(finding.severity) * confidenceMultiplier;
538
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
539
  const signal = obfuscationHeuristic ? "OBFUSCATION_HEURISTIC" : finding.pattern ?? finding.type;
540
- strongestBySignal.set(signal, Math.max(strongestBySignal.get(signal) ?? 0, contribution));
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
+ }
541
550
  }
542
- return [...strongestBySignal.values()].reduce((sum, contribution) => sum + contribution, 0);
551
+ return [...bySignal.values()];
552
+ }
553
+ function calculateRawRiskScore(findings) {
554
+ return calculateSignalContributions(findings).reduce((sum, contribution) => sum + contribution.weight, 0);
543
555
  }
544
556
  function calculateRiskScore(findings) {
545
557
  return Math.min(1, calculateRawRiskScore(findings));
@@ -708,6 +720,35 @@ var SCANNABLE_EXTENSIONS = [
708
720
  ".html",
709
721
  ".htm"
710
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;
711
752
  var MAX_FILES_TO_SCAN = 200;
712
753
  var MAX_FILE_SIZE_BYTES = 1024 * 1024;
713
754
  var MAX_SKIPPED_FILES_LISTED = 500;
@@ -776,21 +817,42 @@ async function scanGitHubRepo(repo, options) {
776
817
  skippedFiles.push({ path, reason });
777
818
  }
778
819
  };
779
- const filesToScan = [];
820
+ const extraFiles = [];
821
+ let configSelected = 0;
822
+ let fontsSelected = 0;
823
+ const sourceBlobs = [];
780
824
  for (const item of tree.tree) {
781
825
  if (item.type !== "blob")
782
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
+ }
783
844
  const eligible = PRIORITY_FILES.some((pf) => item.path.endsWith(pf)) || SCANNABLE_EXTENSIONS.some((ext) => item.path.endsWith(ext));
784
845
  if (!eligible) {
785
846
  skip(item.path, "unsupported-type");
786
847
  } else if (item.size !== void 0 && item.size > MAX_FILE_SIZE_BYTES) {
787
848
  skip(item.path, "too-large");
788
- } else if (filesToScan.length >= MAX_FILES_TO_SCAN) {
849
+ } else if (sourceBlobs.length >= MAX_FILES_TO_SCAN) {
789
850
  skip(item.path, "over-file-limit");
790
851
  } else {
791
- filesToScan.push(item);
852
+ sourceBlobs.push(item);
792
853
  }
793
854
  }
855
+ const filesToScan = [...extraFiles, ...sourceBlobs];
794
856
  const hiddenFiles = tree.tree.filter((item) => item.path.startsWith(".") && !item.path.startsWith(".github") && !item.path.startsWith(".git") && item.type === "blob");
795
857
  for (const hidden of hiddenFiles) {
796
858
  const basename = hidden.path.split("/").pop() ?? hidden.path;
@@ -819,7 +881,8 @@ async function scanGitHubRepo(repo, options) {
819
881
  filesScanned++;
820
882
  scannedFiles.push(file.path);
821
883
  const fileData = await contentResponse.json();
822
- const content = atob(fileData.content || "");
884
+ const binary = atob(fileData.content || "");
885
+ const content = isFontFile(file.path) ? binary : decodeUtf8(binary);
823
886
  const isHtml = /\.html?$/i.test(file.path);
824
887
  const isJsTs = /\.(?:[cm]?js|ts|[jt]sx)$/i.test(file.path);
825
888
  const scriptContent = isHtml ? maskExceptInlineScripts(content) : content;
@@ -839,6 +902,22 @@ async function scanGitHubRepo(repo, options) {
839
902
  findings.push(...postinstallFindings);
840
903
  patternsMatched += postinstallFindings.length;
841
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
+ }
842
921
  if (file.path.endsWith("requirements.txt") || file.path.endsWith("setup.py")) {
843
922
  const pyFindings = scanPythonDeps(content, maliciousPackages, file.path);
844
923
  findings.push(...pyFindings);
@@ -905,10 +984,13 @@ async function scanGitHubRepo(repo, options) {
905
984
  riskScore,
906
985
  rawRiskScore,
907
986
  riskLevel,
908
- factors: findings.map((f) => ({
909
- factor: f.type,
910
- weight: getSeverityWeight(f.severity),
911
- description: f.description
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
912
994
  })),
913
995
  disclaimer: DEFAULT_DISCLAIMER,
914
996
  repo,
@@ -1038,6 +1120,37 @@ function scanPythonDeps(content, maliciousPackages, filePath) {
1038
1120
  }
1039
1121
  return findings;
1040
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
+ }
1041
1154
  var BUILTIN_OBFUSCATION_RULE_IDS = {
1042
1155
  base64: "OBF_BASE64_HEAVY",
1043
1156
  hex: "OBF_HEX_STRINGS",
package/dist/cli.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  scanGitHubRepo,
12
12
  scanGitHubUser,
13
13
  wantJson
14
- } from "./chunk-YU3IO4GZ.js";
14
+ } from "./chunk-EBYRT2M7.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-A3JZBGAA.js");
135
+ const { runMcp } = await import("./mcp-7DWCHBWC.js");
136
136
  return runMcp();
137
137
  }
138
138
  default:
@@ -7,7 +7,7 @@ import {
7
7
  scanGitHubRepo,
8
8
  scanGitHubUser,
9
9
  securityScore
10
- } from "./chunk-YU3IO4GZ.js";
10
+ } from "./chunk-EBYRT2M7.js";
11
11
 
12
12
  // src/commands/mcp.ts
13
13
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagrix",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Scan GitHub repos and profiles for malware before you clone — CLI and MCP server for the Flagrix scanner",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -53,7 +53,7 @@
53
53
  "zod": "^3.24.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@flagrix/scanner-core": "^0.3.0",
56
+ "@flagrix/scanner-core": "^0.4.0",
57
57
  "@types/node": "^20.0.0",
58
58
  "tsup": "^8.0.0",
59
59
  "typescript": "^5.0.0",