flagrix 0.5.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "2026.11.10.001",
3
- "lastUpdated": "2026-11-10T16:39:28.787Z",
2
+ "version": "2026.11.18.001",
3
+ "lastUpdated": "2026-11-18T14:13:43.540Z",
4
4
  "maliciousPackages": [
5
5
  {
6
6
  "name": "beavertail",
@@ -1738,6 +1738,181 @@
1738
1738
  ".yaml"
1739
1739
  ]
1740
1740
  },
1741
+ {
1742
+ "id": "DOWNLOAD_FROM_IP_EXEC",
1743
+ "name": "Download From a Bare IP Address Executed",
1744
+ "pattern": "\\b(?:curl|wget|iwr|Invoke-WebRequest|Invoke-RestMethod)\\b[^\\n|]{0,200}https?:\\/\\/(?!127\\.|10\\.|0\\.|192\\.168\\.|172\\.(?:1[6-9]|2[0-9]|3[01])\\.)\\d{1,3}(?:\\.\\d{1,3}){3}[^\\n|]{0,200}\\|\\s*(?:sudo\\s+)?(?:(?:ba|z)?sh|dash|python3?|perl|node|iex)\\b|\\b(?:curl|wget)\\b[^\\n]{0,200}https?:\\/\\/(?!127\\.|10\\.|0\\.|192\\.168\\.|172\\.(?:1[6-9]|2[0-9]|3[01])\\.)\\d{1,3}(?:\\.\\d{1,3}){3}[^\\n]{0,200}(?:&&|;|\\n)[ \\t]*(?:sudo[ \\t]+)?(?:(?:ba|z)?sh|python3?|node)[ \\t]",
1745
+ "description": "Fetches a script from a hard-coded public IP and runs it. Release tooling uses names, not addresses; loopback and RFC1918 ranges are excluded so local dev scripts don't match.\n",
1746
+ "tags": [
1747
+ "download-exec",
1748
+ "clickfix",
1749
+ "loader"
1750
+ ],
1751
+ "severity": "high",
1752
+ "confidence": "high"
1753
+ },
1754
+ {
1755
+ "id": "DOCKERFILE_RUNS_ASSET_FILE",
1756
+ "name": "Container Build Runs a Font/Image/Text File",
1757
+ "pattern": "(?:^|\\n)[ \\t]*RUN\\b[^\\n]{0,300}\\b(?:node|bun|deno run|python3?)[ \\t]+[^\\n \\t\\\"']{0,120}\\.(?:woff2?|ttf|otf|eot|svg|png|jpe?g|gif|ico|webp|css|scss|dict|txt|md|dat|log)\\b",
1758
+ "description": "`RUN node app/fonts/fa-solid-900.woff2` — the Contagious Interview masquerade moved into the image build, where review attention is lowest.\n",
1759
+ "tags": [
1760
+ "docker",
1761
+ "masquerade",
1762
+ "contagious-interview"
1763
+ ],
1764
+ "severity": "critical",
1765
+ "confidence": "high",
1766
+ "fileExtensions": [
1767
+ ".dockerfile.sh"
1768
+ ]
1769
+ },
1770
+ {
1771
+ "id": "COMPOSE_DOCKER_SOCKET_MOUNT",
1772
+ "name": "Compose Service Mounts the Docker Socket",
1773
+ "pattern": "(?:^|\\n)[ \\t]*(?:-[ \\t]+[\\\"']?|source:[ \\t]*[\\\"']?)(?:\\/var)?\\/run\\/docker\\.sock",
1774
+ "description": "A service with /var/run/docker.sock controls the host daemon — container escape by design. Traefik, Portainer and Watchtower do this legitimately, so it is a review signal, not a verdict.\n",
1775
+ "tags": [
1776
+ "docker",
1777
+ "compose",
1778
+ "privilege-escalation"
1779
+ ],
1780
+ "severity": "high",
1781
+ "confidence": "medium",
1782
+ "fileExtensions": [
1783
+ ".compose.yml"
1784
+ ]
1785
+ },
1786
+ {
1787
+ "id": "COMPOSE_HOST_FILESYSTEM_MOUNT",
1788
+ "name": "Compose Service Mounts the Host Filesystem",
1789
+ "pattern": "(?:^|\\n)[ \\t]*-[ \\t]+[\\\"']?(?:\\/(?:etc|root|home|Users)(?:\\/[^\\n:]{0,60})?|\\/|\\$\\{?HOME\\}?(?:\\/[^\\n:]{0,60})?|~(?:\\/[^\\n:]{0,60})?):",
1790
+ "description": "Binds /, /etc, /root, /home or the host home directory into a container — everything in it, credentials included, becomes readable and writable by the image. Project-relative mounts (./data:/data) do not match.\n",
1791
+ "tags": [
1792
+ "docker",
1793
+ "compose",
1794
+ "credential-access"
1795
+ ],
1796
+ "severity": "high",
1797
+ "confidence": "medium",
1798
+ "fileExtensions": [
1799
+ ".compose.yml"
1800
+ ]
1801
+ },
1802
+ {
1803
+ "id": "COMPOSE_PRIVILEGED_CONTAINER",
1804
+ "name": "Compose Service Drops Container Isolation",
1805
+ "pattern": "(?:^|\\n)[ \\t]*(?:privileged[ \\t]*:[ \\t]*(?:true|yes)\\b|pid[ \\t]*:[ \\t]*[\\\"']?host\\b|cap_add[ \\t]*:[\\s\\S]{0,120}?\\bSYS_(?:ADMIN|PTRACE)\\b)",
1806
+ "description": "privileged: true, pid: host or CAP_SYS_ADMIN / CAP_SYS_PTRACE give a service the host's devices and process table. Some dev setups need it (dind, hardware access), so treat it as context for the rest of the scan.\n",
1807
+ "tags": [
1808
+ "docker",
1809
+ "compose",
1810
+ "privilege-escalation"
1811
+ ],
1812
+ "severity": "medium",
1813
+ "confidence": "medium",
1814
+ "fileExtensions": [
1815
+ ".compose.yml"
1816
+ ]
1817
+ },
1818
+ {
1819
+ "id": "COMPOSE_COMMAND_DOWNLOAD_EXEC",
1820
+ "name": "Compose Service Command Pipes a Download into a Shell",
1821
+ "pattern": "(?:^|\\n)[ \\t]*(?:command|entrypoint)[ \\t]*:[\\s\\S]{0,300}?\\b(?:curl|wget)\\b[^\\n]{0,200}\\|[ \\t]*(?:sudo[ \\t]+)?(?:(?:ba|z)?sh|python3?|node|perl)\\b",
1822
+ "description": "`command: curl ... | sh` in a compose service: the image's own build is not doing the install, a remote script is, every time the stack comes up.\n",
1823
+ "tags": [
1824
+ "docker",
1825
+ "compose",
1826
+ "download-exec"
1827
+ ],
1828
+ "severity": "high",
1829
+ "confidence": "medium",
1830
+ "fileExtensions": [
1831
+ ".compose.yml"
1832
+ ]
1833
+ },
1834
+ {
1835
+ "id": "DEVCONTAINER_COMMAND_DOWNLOAD_EXEC",
1836
+ "name": "Devcontainer Lifecycle Command Pipes a Download into a Shell",
1837
+ "pattern": "\\\"(?:initialize|onCreate|updateContent|postCreate|postStart|postAttach)Command\\\"[ \\t]*:[\\s\\S]{0,300}?(?:\\bcurl\\b|\\bwget\\b|\\biwr\\b|Invoke-WebRequest|Invoke-RestMethod)[\\s\\S]{0,300}?\\|[ \\t]*(?:sudo[ \\t]+)?(?:(?:ba|z)?sh|cmd|iex|powershell|pwsh|python3?|node)\\b",
1838
+ "description": "initializeCommand runs on the host and onCreate/postCreateCommand run as soon as the editor opens the folder — the devcontainer form of the Contagious Interview task file. CONFIG_COMMAND_DOWNLOAD_EXEC only covers the \"command\" key, which these configs do not use.\n",
1839
+ "tags": [
1840
+ "devcontainer",
1841
+ "auto-exec",
1842
+ "download",
1843
+ "contagious-interview"
1844
+ ],
1845
+ "severity": "critical",
1846
+ "confidence": "high",
1847
+ "fileExtensions": [
1848
+ ".json"
1849
+ ],
1850
+ "fileNames": [
1851
+ "devcontainer.json",
1852
+ ".devcontainer.json"
1853
+ ]
1854
+ },
1855
+ {
1856
+ "id": "DEVCONTAINER_RUNS_ASSET_FILE",
1857
+ "name": "Devcontainer Lifecycle Command Runs a Font/Image/Text File",
1858
+ "pattern": "\\\"(?:initialize|onCreate|updateContent|postCreate|postStart|postAttach)Command\\\"[ \\t]*:[\\s\\S]{0,200}?\\b(?:node|bun|deno|python3?)\\b[^\\\"\\n]{0,120}\\.(?:woff2?|ttf|otf|eot|svg|png|jpe?g|gif|ico|webp|css|scss|dict|txt|md|dat|log)\\b",
1859
+ "description": "`postCreateCommand: node .devcontainer/card4.jpeg` — JS disguised as an asset, started by opening the folder.\n",
1860
+ "tags": [
1861
+ "devcontainer",
1862
+ "auto-exec",
1863
+ "masquerade",
1864
+ "contagious-interview"
1865
+ ],
1866
+ "severity": "critical",
1867
+ "confidence": "high",
1868
+ "fileExtensions": [
1869
+ ".json"
1870
+ ],
1871
+ "fileNames": [
1872
+ "devcontainer.json",
1873
+ ".devcontainer.json"
1874
+ ]
1875
+ },
1876
+ {
1877
+ "id": "DEVCONTAINER_PRIVILEGED_HOST_MOUNT",
1878
+ "name": "Devcontainer Runs Privileged or Mounts the Host Home",
1879
+ "pattern": "\\\"privileged\\\"[ \\t]*:[ \\t]*true|\\\"runArgs\\\"[ \\t]*:[\\s\\S]{0,200}?--privileged|\\\"(?:mounts|workspaceMount)\\\"[ \\t]*:[\\s\\S]{0,200}?source=(?:\\/[,\\\"]|\\$\\{localEnv:HOME\\}[,\\\"]|\\/(?:etc|root|home|Users)[,\\\"\\/])",
1880
+ "description": "privileged: true, --privileged in runArgs, or a mount whose source is / or the whole host home directory. Mounting single dotfiles (~/.ssh, ~/.gitconfig) is ordinary and does not match.\n",
1881
+ "tags": [
1882
+ "devcontainer",
1883
+ "privilege-escalation",
1884
+ "credential-access"
1885
+ ],
1886
+ "severity": "medium",
1887
+ "confidence": "medium",
1888
+ "fileExtensions": [
1889
+ ".json"
1890
+ ],
1891
+ "fileNames": [
1892
+ "devcontainer.json",
1893
+ ".devcontainer.json"
1894
+ ]
1895
+ },
1896
+ {
1897
+ "id": "PASTE_RUN_UNTRUSTED_HOST",
1898
+ "name": "Docs Tell You to Pipe a Paste Site into a Shell",
1899
+ "pattern": "\\b(?:curl|wget|iwr|irm|Invoke-WebRequest|Invoke-RestMethod)\\b[^\\n|]{0,200}(?:pastebin\\.com|paste\\.ee|paste\\.rs|rentry\\.(?:co|org)|hastebin\\.com|bit\\.ly|tinyurl\\.com|is\\.gd|cutt\\.ly|rebrand\\.ly|shorturl\\.at|tiny\\.cc|rb\\.gy|t\\.ly|short\\.gy|transfer\\.sh|0x0\\.st|file\\.io|gist\\.githubusercontent\\.com)\\/[^\\n|]{0,200}\\|[ \\t]*(?:sudo[ \\t]+)?(?:(?:ba|z)?sh|iex|powershell|pwsh|python3?|node)\\b",
1900
+ "description": "Install instructions that run a script from a paste site, a URL shortener or a raw gist. Vendor one-liners (brew, rustup, bun) are left out — the host is what makes this a lure.\n",
1901
+ "tags": [
1902
+ "clickfix",
1903
+ "download-exec",
1904
+ "social-engineering",
1905
+ "prompt-injection"
1906
+ ],
1907
+ "severity": "high",
1908
+ "confidence": "medium",
1909
+ "fileExtensions": [
1910
+ ".md",
1911
+ ".mdc",
1912
+ ".txt",
1913
+ ".rst"
1914
+ ]
1915
+ },
1741
1916
  {
1742
1917
  "id": "OBF_BASE64_HEAVY",
1743
1918
  "name": "Heavy Base64 Encoding",
@@ -789,6 +789,15 @@ var TEST_FILE_PATTERNS = [
789
789
  /\.test\.[jt]sx?$/i,
790
790
  /\.spec\.[jt]sx?$/i,
791
791
  /_test\.[jt]sx?$/i,
792
+ // A suite named by its basename rather than by a `tests/` folder or a
793
+ // `.test.` infix: `js-api-tests.js`, `end-to-end-tests.js`, `parser-test.ts`.
794
+ // esbuild keeps its suite in `scripts/*-tests.js`, which every pattern above
795
+ // misses, so those files were read as build scripts with their string
796
+ // literals unmasked — and the `eval`, `new Function` and `fromCharCode`
797
+ // cases a bundler's own tests must contain matched as malware at critical
798
+ // severity. The separator class is what keeps this narrow: `latest.js` and
799
+ // `contest.js` have no separator before `test`, so they are untouched.
800
+ /(?:^|[/\-_.])tests?\.[cm]?[jt]sx?$/i,
792
801
  /\.mock\.[jt]sx?$/i,
793
802
  /fixtures?\//i,
794
803
  /cypress\.config\.[jt]sx?$/i,
@@ -859,7 +868,7 @@ function applyYaraRules(content, rules, filePath, scopePath = filePath) {
859
868
  if (rule.fileExtensions && rule.fileExtensions.length > 0 && !rule.fileExtensions.some((ext) => scopePath.endsWith(ext))) {
860
869
  continue;
861
870
  }
862
- if (rule.fileNames && rule.fileNames.length > 0 && !rule.fileNames.includes(scopePath.split("/").pop() ?? scopePath)) {
871
+ if (rule.fileNames && rule.fileNames.length > 0 && !rule.fileNames.includes(filePath.split("/").pop() ?? filePath)) {
863
872
  continue;
864
873
  }
865
874
  const regex = new RegExp(rule.pattern, CASE_SENSITIVE_RULE_IDS.has(rule.id) ? "g" : "gi");
@@ -933,18 +942,53 @@ var SCANNABLE_EXTENSIONS = [
933
942
  ".html",
934
943
  ".htm"
935
944
  ];
945
+ var CONTAINER_BUILD_FILE = /(?:^|\/)(?:[\w.-]+[-.])?(?:Dockerfile|Containerfile)(?:[-.][\w.-]+)?$/i;
946
+ var COMPOSE_FILE = /(?:^|\/)(?:[\w-]+-)?compose(?:\.[\w-]+)*\.ya?ml$/i;
936
947
  var CONFIG_FILE_PATTERNS = [
937
948
  /(?:^|\/)\.vscode\/(?:tasks|settings|launch|mcp)\.json$/,
938
949
  /(?:^|\/)\.claude\/settings(?:\.local)?\.json$/,
939
950
  /(?:^|\/)\.(?:cursor|amazonq|gemini|windsurf|roo|kiro)\/(?:mcp|settings)\.json$/,
940
951
  /(?:^|\/)\.mcp\.json$/,
952
+ // devcontainer: initializeCommand runs on the host, and
953
+ // onCreate/postCreateCommand the moment an editor opens the folder.
954
+ /(?:^|\/)\.devcontainer\.json$/,
955
+ /(?:^|\/)\.devcontainer\/(?:[^/]+\/)?devcontainer\.json$/,
956
+ // `docker build` / `docker compose up` is a one-command execution path:
957
+ // RUN steps, `command:`, privileged containers, docker-socket mounts.
958
+ CONTAINER_BUILD_FILE,
959
+ COMPOSE_FILE,
941
960
  /^\.github\/workflows\/[^/]+\.ya?ml$/,
942
- /^README(?:\.md|\.txt|\.rst)?$/i,
961
+ /(?:^|\/)README(?:\.md|\.txt|\.rst)?$/i,
943
962
  /(?:^|\/)(?:AGENTS|CLAUDE|GEMINI)\.md$/,
944
963
  /(?:^|\/)\.(?:cursorrules|windsurfrules|clinerules)$/,
945
- /(?:^|\/)\.cursor\/rules\/[^/]+\.mdc?$/,
946
- /^\.github\/copilot-instructions\.md$/
964
+ /(?:^|\/)\.cursor\/rules\/.*\.mdc?$/,
965
+ // Prompts, slash commands, subagents and skills: markdown a coding agent
966
+ // executes on request, with the same reach as a hook.
967
+ /(?:^|\/)\.claude\/(?:commands|agents)\/.*\.md$/,
968
+ /(?:^|\/)\.claude\/skills\/[^/]+\/SKILL\.md$/,
969
+ /^\.github\/copilot-instructions\.md$/,
970
+ /^\.github\/(?:instructions|prompts)\/[^/]+\.md$/
947
971
  ];
972
+ function configRuleScope(path) {
973
+ if (CONTAINER_BUILD_FILE.test(path))
974
+ return `${path}.dockerfile.sh`;
975
+ if (COMPOSE_FILE.test(path))
976
+ return `${path}.compose.yml`;
977
+ return path;
978
+ }
979
+ var INSTRUCTION_CONFIG = /(?:^|\/)(?:AGENTS|CLAUDE|GEMINI)\.md$|(?:^|\/)\.(?:cursorrules|windsurfrules|clinerules)$|(?:^|\/)\.cursor\/rules\/|(?:^|\/)\.claude\/(?:commands|agents|skills)\/|^\.github\/(?:copilot-instructions\.md$|(?:instructions|prompts)\/)/;
980
+ var README_CONFIG = /(?:^|\/)README(?:\.md|\.txt|\.rst)?$/i;
981
+ function sortByPriority(items, priority) {
982
+ const rank = new Map(items.map((item, index) => [item, index]));
983
+ items.sort((a, b) => priority(a.path) - priority(b.path) || rank.get(a) - rank.get(b));
984
+ }
985
+ function configPriority(path) {
986
+ if (README_CONFIG.test(path))
987
+ return 2;
988
+ if (INSTRUCTION_CONFIG.test(path))
989
+ return 1;
990
+ return 0;
991
+ }
948
992
  var UTF8 = new TextDecoder("utf-8");
949
993
  function decodeUtf8(binary) {
950
994
  const bytes = new Uint8Array(binary.length);
@@ -964,11 +1008,14 @@ function isFontFile(path) {
964
1008
  var MAX_CONFIG_FILES = 25;
965
1009
  var MAX_COMMAND_TARGETS = 10;
966
1010
  var CI_WORKFLOW = /^\.github\/workflows\//;
1011
+ function runsOffHost(path) {
1012
+ return CI_WORKFLOW.test(path) || CONTAINER_BUILD_FILE.test(path) || COMPOSE_FILE.test(path);
1013
+ }
967
1014
  var RUNTIME_INVOCATION = /\b(?:node|nodejs|bun|deno\s+run|tsx|ts-node)((?:\s+-{1,2}[\w-]+(?:=[^\s"'`]*)?)*)\s+\\?["']?([^\s"'`&|;<>()]+)/g;
968
1015
  var INLINE_CODE_FLAG = /(?:^|\s)(?:-[ep]|--eval|--print)(?:\s|=|$)/;
969
1016
  var RUNTIME_ARGS_FORM = /"command"\s*:\s*"(?:node|nodejs|bun|deno|tsx|ts-node)"\s*,\s*"args"\s*:\s*\[\s*"([^"]+)"/g;
970
- var PROJECT_DIR_VARIABLE = /\\?["']?\$\{?(?:CLAUDE_PROJECT_DIR|workspaceFolder|workspaceRoot)\}?\\?["']?(?=\/)/g;
971
- var DOT_DIR_CONFIG = /^(?:(.*)\/)?\.(?:vscode|claude|cursor|amazonq|gemini|windsurf|roo|kiro|github)\//;
1017
+ var PROJECT_DIR_VARIABLE = /\\?["']?\$\{?(?:CLAUDE_PROJECT_DIR|workspaceFolder|workspaceRoot|localWorkspaceFolder|containerWorkspaceFolder)\}?\\?["']?(?=\/)/g;
1018
+ var DOT_DIR_CONFIG = /^(?:(.*)\/)?\.(?:vscode|claude|cursor|amazonq|gemini|windsurf|roo|kiro|github|devcontainer)\//;
972
1019
  function extractCommandTargets(content, configPath) {
973
1020
  const dotDir = configPath.match(DOT_DIR_CONFIG);
974
1021
  const base = dotDir ? dotDir[1] ?? "" : configPath.includes("/") ? configPath.slice(0, configPath.lastIndexOf("/")) : "";
@@ -1006,7 +1053,34 @@ function resolveRepoPath(base, raw) {
1006
1053
  }
1007
1054
  return segments.length > 0 ? segments.join("/") : null;
1008
1055
  }
1056
+ var FETCH_CONCURRENCY = 12;
1057
+ async function mapPool(items, limit, work) {
1058
+ const results = new Array(items.length);
1059
+ let next = 0;
1060
+ const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
1061
+ while (true) {
1062
+ const index = next++;
1063
+ if (index >= items.length)
1064
+ return;
1065
+ results[index] = await work(items[index]);
1066
+ }
1067
+ });
1068
+ await Promise.all(workers);
1069
+ return results;
1070
+ }
1009
1071
  var MAX_FILES_TO_SCAN = 200;
1072
+ var RUNS_ON_INSTALL_OR_BUILD = /^(?:scripts?|bin|tools?)\/|(?:^|\/)(?:pre|post)?install\.(?:[cm]?js|ts)$|(?:^|\/)setup\.(?:[cm]?js|ts|py)$|(?:^|\/)[\w.-]*\.config\.(?:[cm]?js|ts)$|^\.(?:husky|github|vscode|claude|cursor|devcontainer)\//;
1073
+ var GENERATED_OR_VENDORED = /(?:^|\/)(?:dist|build|out|vendor|third_party|node_modules|coverage)\/|\.min\.[cm]?js$|\.bundle\.[cm]?js$|(?:^|\/)[\w.-]*\.generated\.[cm]?[jt]sx?$/;
1074
+ var SUPPORTING_SOURCE = /(?:^|\/)(?:__mocks__|mocks?|examples?|samples?|demos?)\//i;
1075
+ function sourcePriority(path) {
1076
+ if (GENERATED_OR_VENDORED.test(path))
1077
+ return 3;
1078
+ if (isTestFile(path) || SUPPORTING_SOURCE.test(path))
1079
+ return 2;
1080
+ if (RUNS_ON_INSTALL_OR_BUILD.test(path))
1081
+ return 0;
1082
+ return 1;
1083
+ }
1010
1084
  var MAX_FILE_SIZE_BYTES = 1024 * 1024;
1011
1085
  var MAX_SKIPPED_FILES_LISTED = 500;
1012
1086
  var NPM_DOWNLOAD_CACHE = /* @__PURE__ */ new Map();
@@ -1074,27 +1148,25 @@ async function scanGitHubRepo(repo, options) {
1074
1148
  skippedFiles.push({ path, reason });
1075
1149
  }
1076
1150
  };
1077
- const extraFiles = [];
1078
- let configSelected = 0;
1079
- let fontsSelected = 0;
1151
+ const configCandidates = [];
1152
+ const fontFiles = [];
1080
1153
  const sourceBlobs = [];
1081
1154
  for (const item of tree.tree) {
1082
1155
  if (item.type !== "blob")
1083
1156
  continue;
1084
- const config = isConfigFile(item.path);
1157
+ const config = isConfigFile(item.path) && !SCANNABLE_EXTENSIONS.some((ext) => item.path.endsWith(ext));
1085
1158
  const font = !config && isFontFile(item.path);
1086
1159
  if (config || font) {
1087
1160
  const sizeLimit = font ? MAX_FONT_BYTES : MAX_FILE_SIZE_BYTES;
1088
1161
  if (item.size !== void 0 && item.size > sizeLimit) {
1089
1162
  skip(item.path, "too-large");
1090
- } else if (config ? configSelected >= MAX_CONFIG_FILES : fontsSelected >= MAX_FONT_FILES) {
1091
- skip(item.path, "over-file-limit");
1092
- } else {
1093
- if (config)
1094
- configSelected++;
1163
+ } else if (font) {
1164
+ if (fontFiles.length >= MAX_FONT_FILES)
1165
+ skip(item.path, "over-file-limit");
1095
1166
  else
1096
- fontsSelected++;
1097
- extraFiles.push(item);
1167
+ fontFiles.push(item);
1168
+ } else {
1169
+ configCandidates.push(item);
1098
1170
  }
1099
1171
  continue;
1100
1172
  }
@@ -1103,13 +1175,20 @@ async function scanGitHubRepo(repo, options) {
1103
1175
  skip(item.path, "unsupported-type");
1104
1176
  } else if (item.size !== void 0 && item.size > MAX_FILE_SIZE_BYTES) {
1105
1177
  skip(item.path, "too-large");
1106
- } else if (sourceBlobs.length >= MAX_FILES_TO_SCAN) {
1107
- skip(item.path, "over-file-limit");
1108
1178
  } else {
1109
1179
  sourceBlobs.push(item);
1110
1180
  }
1111
1181
  }
1112
- const filesToScan = [...extraFiles, ...sourceBlobs];
1182
+ sortByPriority(sourceBlobs, sourcePriority);
1183
+ for (const item of sourceBlobs.splice(MAX_FILES_TO_SCAN)) {
1184
+ skip(item.path, "over-file-limit");
1185
+ }
1186
+ const configFiles = configCandidates;
1187
+ sortByPriority(configFiles, configPriority);
1188
+ for (const item of configFiles.splice(MAX_CONFIG_FILES)) {
1189
+ skip(item.path, "over-file-limit");
1190
+ }
1191
+ const filesToScan = [...configFiles, ...fontFiles, ...sourceBlobs];
1113
1192
  const blobsByPath = new Map(tree.tree.filter((item) => item.type === "blob").map((item) => [item.path, item]));
1114
1193
  const queued = new Set(filesToScan.map((item) => item.path));
1115
1194
  const commandTargets = /* @__PURE__ */ new Set();
@@ -1141,29 +1220,40 @@ async function scanGitHubRepo(repo, options) {
1141
1220
  let fetchFailures = 0;
1142
1221
  const declaredDependencies = [];
1143
1222
  const localPackageNames = /* @__PURE__ */ new Set();
1144
- for (const file of filesToScan) {
1145
- if (rateLimited) {
1146
- skip(file.path, "rate-limited");
1147
- continue;
1148
- }
1223
+ const historySignals = fetchHistorySignals(`${repo.owner}/${repo.repo}`, branch, commitSha, headers);
1224
+ const readFile3 = async (file) => {
1225
+ if (rateLimited)
1226
+ return { state: "rate-limited" };
1149
1227
  const contentUrl = `https://api.github.com/repos/${repo.owner}/${repo.repo}/contents/${file.path}?ref=${commitSha}`;
1150
1228
  const contentResponse = await fetch(contentUrl, { headers });
1151
1229
  if (!contentResponse.ok) {
1152
1230
  if (isRateLimitResponse(contentResponse)) {
1153
1231
  rateLimited = true;
1154
- skip(file.path, "rate-limited");
1155
- continue;
1232
+ return { state: "rate-limited" };
1156
1233
  }
1234
+ return { state: "failed" };
1235
+ }
1236
+ const fileData = await contentResponse.json();
1237
+ const binary = atob(fileData.content || "");
1238
+ return {
1239
+ state: "read",
1240
+ content: isFontFile(file.path) ? binary : decodeUtf8(binary)
1241
+ };
1242
+ };
1243
+ const analyzeFile = async (file, read) => {
1244
+ if (read.state === "rate-limited") {
1245
+ skip(file.path, "rate-limited");
1246
+ return;
1247
+ }
1248
+ if (read.state === "failed") {
1157
1249
  fetchFailures++;
1158
1250
  skip(file.path, "fetch-failed");
1159
- continue;
1251
+ return;
1160
1252
  }
1161
1253
  filesScanned++;
1162
1254
  scannedFiles.push(file.path);
1163
- const fileData = await contentResponse.json();
1164
- const binary = atob(fileData.content || "");
1165
- const content = isFontFile(file.path) ? binary : decodeUtf8(binary);
1166
- if (isConfigFile(file.path) && !CI_WORKFLOW.test(file.path) || file.path.endsWith("package.json")) {
1255
+ const content = read.content;
1256
+ if (isConfigFile(file.path) && !runsOffHost(file.path) || file.path.endsWith("package.json")) {
1167
1257
  for (const target of extractCommandTargets(content, file.path)) {
1168
1258
  if (commandTargets.size >= MAX_COMMAND_TARGETS)
1169
1259
  break;
@@ -1210,13 +1300,13 @@ async function scanGitHubRepo(repo, options) {
1210
1300
  const masquerade = detectMasqueradedScript(content, file.path);
1211
1301
  findings.push(...masquerade);
1212
1302
  patternsMatched += masquerade.length;
1213
- continue;
1303
+ return;
1214
1304
  }
1215
1305
  if (!isSource && (isConfigFile(file.path) || file.path.endsWith("package.json"))) {
1216
- const configFindings = applyYaraRules(content, yaraRules, file.path);
1306
+ const configFindings = applyYaraRules(content, yaraRules, file.path, configRuleScope(file.path));
1217
1307
  findings.push(...configFindings);
1218
1308
  patternsMatched += configFindings.length;
1219
- if (/^README/i.test(file.path)) {
1309
+ if (/^README/i.test(file.path.split("/").pop() ?? file.path)) {
1220
1310
  const socialFindings = detectSocialEngineering(content, file.path);
1221
1311
  findings.push(...socialFindings);
1222
1312
  patternsMatched += socialFindings.length;
@@ -1237,6 +1327,14 @@ async function scanGitHubRepo(repo, options) {
1237
1327
  findings.push(...obfuscationFindings);
1238
1328
  patternsMatched += obfuscationFindings.length;
1239
1329
  }
1330
+ };
1331
+ for (let cursor = 0; cursor < filesToScan.length; ) {
1332
+ const generation = filesToScan.slice(cursor);
1333
+ cursor = filesToScan.length;
1334
+ const reads = await mapPool(generation, FETCH_CONCURRENCY, readFile3);
1335
+ for (let index = 0; index < generation.length; index++) {
1336
+ await analyzeFile(generation[index], reads[index]);
1337
+ }
1240
1338
  }
1241
1339
  if (options.osvFeed) {
1242
1340
  const alreadyFlagged = new Set(findings.filter((finding) => finding.type === "SUSPICIOUS_DEPENDENCY" && finding.package).map((finding) => finding.package));
@@ -1285,7 +1383,7 @@ async function scanGitHubRepo(repo, options) {
1285
1383
  const integrityFindings = await detectCodeIntegrityIssues(fileContents, allPaths, repo);
1286
1384
  findings.push(...integrityFindings);
1287
1385
  patternsMatched += integrityFindings.length;
1288
- const historyFindings = await fetchHistorySignals(`${repo.owner}/${repo.repo}`, branch, commitSha, headers);
1386
+ const historyFindings = await historySignals;
1289
1387
  findings.push(...historyFindings);
1290
1388
  patternsMatched += historyFindings.length;
1291
1389
  const rawRiskScore = calculateRawRiskScore(findings);
@@ -1333,6 +1431,9 @@ async function scanPackageJson(content, maliciousPackages, filePath) {
1333
1431
  try {
1334
1432
  const pkg = JSON.parse(content);
1335
1433
  const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
1434
+ const typosquatCandidates = Object.keys(allDeps).filter((name) => !name.startsWith("@")).map((name) => ({ name, typosquat: checkTyposquat(name) })).filter((candidate) => candidate.typosquat !== null);
1435
+ const downloadsByName = new Map(await Promise.all(typosquatCandidates.map(async ({ name }) => [name, await getNpmWeeklyDownloads(name)])));
1436
+ const typosquatOf = new Map(typosquatCandidates.map(({ name, typosquat }) => [name, typosquat]));
1336
1437
  for (const [name, declaredVersion] of Object.entries(allDeps)) {
1337
1438
  const malicious = maliciousPackages.find((m) => m.name === name);
1338
1439
  if (malicious && isAffectedPackageVersion(malicious, declaredVersion)) {
@@ -1345,20 +1446,18 @@ async function scanPackageJson(content, maliciousPackages, filePath) {
1345
1446
  description: `Known malicious package: ${name}`
1346
1447
  });
1347
1448
  }
1348
- if (!name.startsWith("@")) {
1349
- const typosquat = checkTyposquat(name);
1350
- if (typosquat) {
1351
- const weeklyDownloads = await getNpmWeeklyDownloads(name);
1352
- const shouldFlag = weeklyDownloads === null || weeklyDownloads < NPM_HIGH_DOWNLOAD_THRESHOLD;
1353
- if (shouldFlag) {
1354
- findings.push({
1355
- severity: "medium",
1356
- type: "TYPOSQUAT_PACKAGE",
1357
- file: filePath,
1358
- package: name,
1359
- description: `Possible typosquat of "${typosquat}": ${name}`
1360
- });
1361
- }
1449
+ const typosquat = typosquatOf.get(name);
1450
+ if (typosquat) {
1451
+ const weeklyDownloads = downloadsByName.get(name) ?? null;
1452
+ const shouldFlag = weeklyDownloads === null || weeklyDownloads < NPM_HIGH_DOWNLOAD_THRESHOLD;
1453
+ if (shouldFlag) {
1454
+ findings.push({
1455
+ severity: "medium",
1456
+ type: "TYPOSQUAT_PACKAGE",
1457
+ file: filePath,
1458
+ package: name,
1459
+ description: `Possible typosquat of "${typosquat}": ${name}`
1460
+ });
1362
1461
  }
1363
1462
  }
1364
1463
  }
@@ -2005,7 +2104,13 @@ function detectBackdoors(content, filePath, coveredRuleIds = /* @__PURE__ */ new
2005
2104
  { pattern: /eval\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Remote Code Execution Endpoint", severity: "critical", ruleId: "BACKDOOR_RCE_ENDPOINT" },
2006
2105
  { pattern: /exec\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Command Injection Endpoint", severity: "critical", ruleId: "BACKDOOR_RCE_ENDPOINT" },
2007
2106
  { pattern: /require\s*\(\s*(?:request|req)(?:\.|\.body|\.query)/gi, type: "Dynamic Require", severity: "critical", ruleId: "BACKDOOR_DYNAMIC_REQUIRE" },
2008
- { pattern: /new\s+Function\s*\([^)]*(?:request|req)/gi, type: "Dynamic Function from Request", severity: "critical", ruleId: null },
2107
+ // The request has to be read as data (`req.body`, `req["x"]`), the way
2108
+ // the three patterns above all require. Matching a bare `req` flagged
2109
+ // `new Function('module', 'exports', 'require', src)` — the CommonJS
2110
+ // module wrapper every bundler and module loader writes — as a critical
2111
+ // backdoor, because `require` begins with `req`. esbuild's own build
2112
+ // script tripped it.
2113
+ { pattern: /new\s+Function\s*\([^)]*\b(?:request|req)\s*(?:\.|\[)/gi, type: "Dynamic Function from Request", severity: "critical", ruleId: null },
2009
2114
  { pattern: /(?:password|auth)\s*(?:===?|==)\s*['"][^'"]{0,20}['"]\s*\)/gi, type: "Hardcoded Auth Bypass", severity: "critical", ruleId: "BACKDOOR_HARDCODED_AUTH" }
2010
2115
  ].filter(({ ruleId }) => !ruleId || !coveredRuleIds.has(ruleId));
2011
2116
  for (const { pattern, type, severity } of backdoorPatterns) {
@@ -2414,21 +2519,21 @@ async function fetchUserFeatures(username, githubToken) {
2414
2519
  if (githubToken) {
2415
2520
  headers["Authorization"] = `Bearer ${githubToken}`;
2416
2521
  }
2417
- const userResponse = await fetch(`https://api.github.com/users/${username}`, { headers });
2522
+ const [userResponse, reposResponse, eventsResponse] = await Promise.all([
2523
+ fetch(`https://api.github.com/users/${username}`, { headers }),
2524
+ fetch(`https://api.github.com/users/${username}/repos?per_page=100&sort=updated`, { headers }),
2525
+ fetch(`https://api.github.com/users/${username}/events/public?per_page=30`, { headers })
2526
+ ]);
2418
2527
  if (!userResponse.ok) {
2419
2528
  if (userResponse.status === 404)
2420
2529
  throw new Error(`User "${username}" not found`);
2421
2530
  throw await githubApiError(userResponse);
2422
2531
  }
2423
- const user = await userResponse.json();
2424
- const reposResponse = await fetch(`https://api.github.com/users/${username}/repos?per_page=100&sort=updated`, { headers });
2425
2532
  if (!reposResponse.ok)
2426
2533
  throw await githubApiError(reposResponse, "Failed to fetch repositories");
2427
- const repos = await reposResponse.json();
2428
- const eventsResponse = await fetch(`https://api.github.com/users/${username}/events/public?per_page=30`, { headers });
2429
2534
  if (!eventsResponse.ok)
2430
2535
  throw await githubApiError(eventsResponse, "Failed to fetch events");
2431
- const events = await eventsResponse.json();
2536
+ const [user, repos, events] = await Promise.all([userResponse.json(), reposResponse.json(), eventsResponse.json()]);
2432
2537
  const now = Date.now();
2433
2538
  const accountAgeDays = Math.floor((now - new Date(user.created_at).getTime()) / 864e5);
2434
2539
  const followerFollowingRatio = user.followers === 0 ? user.following > 0 ? Infinity : 0 : user.following / user.followers;
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  scanGitHubUser,
15
15
  scanReport,
16
16
  wantJson
17
- } from "./chunk-HL53V2DT.js";
17
+ } from "./chunk-NLLRSST4.js";
18
18
 
19
19
  // src/cli.ts
20
20
  import { parseArgs } from "util";
@@ -78,7 +78,7 @@ async function runScanUser(login, options) {
78
78
  }
79
79
 
80
80
  // src/cli.ts
81
- var VERSION = "0.5.1";
81
+ var VERSION = "0.6.1";
82
82
  var HELP = `flagrix \u2014 scan GitHub repos and profiles for malware before you clone
83
83
 
84
84
  Usage:
@@ -142,7 +142,7 @@ async function main() {
142
142
  }
143
143
  return runScanUser(target, { json: values.json, token: values.token });
144
144
  case "mcp": {
145
- const { runMcp } = await import("./mcp-KMJZQ5JQ.js");
145
+ const { runMcp } = await import("./mcp-X3BOXV2Z.js");
146
146
  return runMcp();
147
147
  }
148
148
  default:
@@ -11,7 +11,7 @@ import {
11
11
  scanGitHubUser,
12
12
  scanReport,
13
13
  securityScore
14
- } from "./chunk-HL53V2DT.js";
14
+ } from "./chunk-NLLRSST4.js";
15
15
 
16
16
  // src/commands/mcp.ts
17
17
  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.5.1",
3
+ "version": "0.6.1",
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.6.0",
56
+ "@flagrix/scanner-core": "^0.7.1",
57
57
  "@types/node": "^20.0.0",
58
58
  "tsup": "^8.0.0",
59
59
  "typescript": "^5.0.0",