MalTotal: Low-Cost, Language-Agnostic Malicious Code Poisoning Detection for Millions of RepositoriesMalTotal: Cost-Effective and Language-Agnostic Malicious Code Poisoning Detection for Millions of Repositories
The authors propose MalTotal, which uses LLM semantic analysis plus hybrid slicing to detect multilingual malicious code repositories; the authors claim an average F1 of 93.1% across 5 languages and the discovery of 564 unknown malicious repositories across 120K GitHub repositories.
Defender's perspective: detecting malicious code poisoning planted in public package registry platforms and GitHub repositories (such as typosquatting, dependency confusion, repo confusion). Attackers can hide sensitive operations in multilingual source code and third-party libraries; the defense system performs static analysis on repository source code, does not analyze the malicious dependency itself, and does not track across language boundaries.
- Malicious code poisoning attacks are spreading from package registry platforms to GitHub repositories; the authors argue that existing heuristic, learning, and LLM detection methods are limited by language-specific design, insufficient generalization, and high analysis costs, making it difficult to support million-scale multilingual repository analysis.
- MalTotal first uses LLM semantic summarization to identify sensitive APIs in built-in and third-party libraries, then performs backward hybrid slicing (call chain, control dependence, data dependence) from sensitive call sites on the code property graph, and after aggregation hands the result to an LLM-as-a-Judge to determine malicious intent.
- The authors report: on Multi-Lang-Bench, MalTotal outperforms 8 baselines, with an average F1 of 93.1% across 5 languages; hybrid slicing reduces tokens by 94.0% on 2,168 repositories; and across 120K GitHub repositories it discovers 564 unknown malicious repositories at a cost of $338.
- Limitations noted by the authors: dependence on the maturity of the static analysis toolchain, no support for cross-language attack tracing, omission of alias resolution in pre-filtering, and the LLM analyzer possibly being affected by prompt injection. The evaluation covers 5 languages, and the Java/PHP/Go subsets have only 150–286 samples per language.
- Evaluated models
- DeepSeek-V3GPT-4oGPT-3.5 TurboClaude 4 SonnetGemini 3 Pro
- Benchmarks
- Multi-Lang-BenchMalwareBenchSourceFinderGitHub-120KStarScoutDataDog malicious-software-packages-dataset
- Metrics
- PrecisionRecallF1-scoreFNROOCFDRtoken 消耗与成本
MalTotal uses LLM-assisted semantic reasoning to achieve low-cost, language-agnostic malicious code poisoning detection, discovering 564 previously unknown malicious repositories among 120K GitHub repositories at a total cost of $338. It achieves an average F1 of 93.1% across 5 mainstream languages, outperforming 8 state-of-the-art baselines. Hybrid slicing reduces LLM token consumption by 94.0%, lowering the analysis cost of 2,168 repositories from $86.25 to $5.19.
Paper analysis
What problem does this paper attempt to solve?
How to detect malicious code poisoning across millions of multilingual repositories at an affordable cost; the authors argue that existing methods fall short in language coverage, generalization, and cost.
Core problem: how to detect malicious code poisoning in millions of linguistically heterogeneous open-source repositories in a scalable, low-cost, and language-agnostic manner.
- Scenario and importance: The authors point out that malicious poisoning has expanded from NPM and PyPI to VSCode extensions, MCP servers, agent skills, and GitHub repositories; GitHub hosts more than 518 million repositories, and more than 100,000 repositories have been involved in repo confusion activity (§1).
- Shortcomings of existing methods (L1–L3): The authors summarize three points—most methods are language-specific and rely on manually crafted sensitive API specifications (L1); abstracting code into predefined patterns or statistical features makes it difficult to cope with 0-day patterns and lacks interpretability (L2); using LLMs directly as judges suffers from hallucination, context window limits, and high token costs (L3) (§1).
- Core observation: The authors' preliminary experiments (§2) show that as long as sufficiently streamlined code context is provided, LLMs can reason about malicious semantics across languages; slice-level context has the lowest FNR across 5 languages (0.0%–2.0%, Table 1), and token consumption is 97.6% lower than repository-level.
- Proposed in the paper: The MalTotal framework—LLM-assisted identification of sensitive APIs, hybrid semantic slicing to reconstruct malicious behavior context, LLM-as-a-Judge for intent determination, along with the Multi-Lang-Bench dataset and a real-world study on 120K repositories.
- Threat model:
- Attacker's goal: Plant malicious code in public package registry platforms or GitHub repositories to harm downstream users.
- Attack techniques: The paper lists typosquatting, dependency confusion, repo confusion, fork bombs, etc. (§1).
- Defender's capabilities: Perform static analysis on repository source code, using LLMs for semantic judgment; does not analyze the malicious dependency itself, and does not track data flow across language boundaries (§4.2, §5).
What related research exists?
Related work falls into three groups: research on supply chain attack vectors, PyPI/NPM malicious package detection, and GitHub malicious repository detection; the authors position this paper as cross-language, fine-grained semantic detection.
Software supply chain attack vectors
- Gu et al. (2023) systematically surveyed the ecosystems of six software registry platforms and identified 12 attack vectors; Ladisa et al. (2023) proposed a taxonomy of 107 attack vectors covering all stages of the supply chain.
- Zahan et al. (2022) analyzed metadata of 1.63 million npm packages and proposed six security weakness signals; Neupane et al. (2023) summarized 13 package obfuscation mechanisms.
PyPI/NPM malicious package detection
- Rule-based: based on static analysis (e.g., CodeQL semantic signature matching) or sandbox dynamic analysis; the paper notes that such tools have high false positive rates in real deployment (relaying the conclusion of Vu et al. 2023).
- Learning-based: SAP (Ladisa et al. 2023), Amalfi (Sejfia & Schäfer 2022), etc. learn patterns from metadata or source code features; the paper argues that their performance is limited by handcrafted features and struggles to capture the semantics of novel attacks.
- LLM-based: MalGuard, SpiderScan, and MalPacDetector use LLMs only for auxiliary tasks such as sensitive API identification or feature generation; SocketAI (Zahan et al. 2025) and others let the LLM act directly as a judge, which the paper notes is costly and limited by the context window.
GitHub malicious repository detection
- SourceFinder (Rokon et al. 2020) discovers malicious source code from public GitHub repositories; Repo2Vec (2021) performs repository similarity clustering based on metadata and file structure; StarScout (He et al. 2026) uses anomalous social signals such as fake stars to identify suspicious repositories.
- The paper notes that these methods remain at a coarse-grained, non-code level, bypass semantic inspection of source code, and have blind spots for novel or stealthy malicious code.
Baselines and benchmarks: the experiments compare 8 baselines—rule-based ApplicationInspector, OSSGadget, Guarddog, Bandit4mal (Python only), and learning-based SAP, Amalfi (JavaScript only), MalTracker (JavaScript only), MalGuard (Python only); the evaluation benchmarks are the self-built Multi-Lang-Bench (Python/JavaScript from MalwareBench, Java/PHP/Go from SourceFinder) and GitHub-120K based on StarScout data (§4.1).
Positioning of this paper: the authors claim that MalTotal differs from the above work in supporting multilingual generalization, using an LLM for fine-grained source code semantic analysis, and addressing context window and cost limitations through slicing (§6).
How does the paper address this problem?
MalTotal has three stages: LLM-assisted sensitive API extraction, hybrid reverse slicing based on code property graphs, and LLM-as-a-Judge semantic determination.
Overall approach: first use an LLM to extend "sensitive API identification" to multiple languages and third-party libraries, then backward-slice from sensitive call sites to extract logically complete contexts of suspicious behavior, and finally have the LLM determine malicious intent on the reduced context. Framework name MalTotal (Figure 1).
Sensitive API extraction (§3.1)
- Taxonomy: sensitive APIs fall into five categories—payload execution, network access, file operation, sensitive data access, cryptography (Table 2).
- Built-in APIs (offline): merging MalOSS's 1,257 APIs, MalTracker's 293 JavaScript APIs, and 597 APIs manually compiled from official documentation yields, after deduplication, a knowledge base of 2,147 built-in sensitive APIs (Table 3).
- Third-party library APIs (online): parse the project's dependency files, locate the implementations of imported third-party functions (taking only the function body itself, without recursively tracing callees), and have the LLM produce a semantic summary per a prompt template and output structured JSON; results are cached and reused by (library, version, function). In evaluation, 27,746 third-party APIs were analyzed in total, of which 694 were judged sensitive (§3.1.1).
- Parsing and filtering: use Semgrep to scan direct calls and indirect calls in alias/import form; projects containing no sensitive APIs are skipped directly without subsequent slicing (§3.1.2).
Hybrid code slicing (§3.2)
- CPG construction: use Joern to convert source code into a code property graph (CPG, combining AST, CFG, PDG); for direct calls, backward-slice from their CPG nodes, and for alias references, first perform forward data-flow analysis to find the real call site and then backward-slice.
- Backward hybrid slicing: with sensitive operations as sinks, perform backward slicing combining three dependencies: call chain, control dependence, and data dependence; the authors claim that sink-driven slicing can mitigate the path explosion of forward slicing. Call-chain expansion has a maximum depth of k = 3, and callees are kept whole rather than only the executed lines, with the rationale of giving the LLM complete structural context (verified in §4.3).
- Context refinement and aggregation: first apply maximal-content filtering (discarding slices fully contained in other slices), then iteratively merge by line-level Jaccard similarity with threshold τ = 0.3 until no slices can be merged (§3.2).
LLM semantic analysis (§3.3)
- Prompt design: integrates four techniques—role setting (security expert), four-step CoT reasoning (identify sensitive operations → trace data flow → assess intent → synthesize conclusion), few-shot examples (benign/suspicious/malicious), and standardized JSON output (including fields such as is_malicious and severity). Figure 4 shows part of the prompt template.
- Judgment output: the LLM outputs whether it is malicious, the severity level (Low/Medium/High), and the category (e.g., Backdoor), along with the analysis rationale, which the authors claim provides interpretability.
Implementation and default configuration
- The prototype is about 5K lines of Python plus 3K lines of Scala; Semgrep v1.102.0 is used for initial screening, Joern v4.0.303 generates CPGs, and the default LLM is DeepSeek-V3 (§4.1).
- Supports five languages: Python, JavaScript, Java, Go, and PHP.
What experiments did the paper conduct?
Compared with 8 baselines on the self-built Multi-Lang-Bench, MalTotal's F1 across five languages is 91.0%–96.3%; additionally, ablation, LLM replacement, data contamination analysis, and a real-world test on 120K repositories were conducted.
Experimental setup
- Systems under test: MalTotal (default LLM is DeepSeek-V3) and 8 baseline tools; the LLM influence experiment additionally tests GPT-4o, GPT-3.5 Turbo, Claude 4 Sonnet, and Gemini 3 Pro (Table 9).
- Dataset: Multi-Lang-Bench—Python 6,444 packages (3,188 malicious), JavaScript 9,545 packages (3,438 malicious) taken from MalwareBench and deduplicated; Java 150, PHP 286, and Go 160 samples taken from SourceFinder and independently manually reviewed by three people, with benign samples being an equal number of high-star GitHub repositories (Table 4).
- Large-scale dataset: GitHub-120K, 120K repositories downloaded from the 186K repositories with abnormal popularity signals provided by StarScout, totaling 7.3 million files (§4.1).
- Metrics and decision criteria: Precision, Recall, F1; baseline decision criteria—Guarddog/OSSGadget flag as malicious if either raises an alert, ApplicationInspector/Bandit4mal require both severity and confidence to be High (§4.1).
- Manual review: The SourceFinder subset was independently cross-validated by three reviewers; the initial results of GitHub-120K were independently reviewed by two security researchers with over 5 years of experience, with disagreements adjudicated by an expert with 7 years of experience (§4.5).
- Number of repetitions: The paper does not report the number of experimental repetitions.
Main results
According to Table 5 (Multi-Lang-Bench, values are percentages):
Swipe horizontally to read the table
Tool Python F1 JavaScript F1 Go F1 Java F1 PHP F1 AppInspector 21.4 55.6 38.6 48.0 56.4 OSSGadget 15.2 67.8 27.5 27.5 36.0 Guarddog 92.6 79.9 Not reported Not reported Not reported Bandit4mal 25.1 Not reported Not reported Not reported Not reported SAP 65.8 63.3 Not reported Not reported Not reported Amalfi Not reported 85.4 Not reported Not reported Not reported MalTracker Not reported 71.3 Not reported Not reported Not reported MalGuard 95.5 Not reported Not reported Not reported Not reported MalTotal 96.3 91.0 91.5 92.3 94.2 - The authors state that MalTotal's F1 exceeds 85% across all 5 languages, averaging 93.1% (abstract); on JavaScript, precision (93.3) is lower than SAP (98.5), which the authors explain as SAP trading recall (46.6) for precision.
- False positive analysis: The authors state that false positives mainly come from corner cases where benign code such as system administration and automated testing resembles malicious behavior patterns (§4.2).
- False negative analysis: The authors point out two types—inability to detect attacks via malicious dependencies (the source code itself is benign); difficulty identifying threats executed through indirect execution chains such as powershell.exe with payloads outside the source code (§4.2).
Ablation and slicing sensitivity (RQ2)
- Component ablation (Table 6): Removing third-party API identification decreases recall across all 5 languages (e.g., Python from 96.9 to 94.5); removing slicing (whole-file input) decreases recall further (Python to 91.2), and the authors state that slicing is not only a cost-saving measure but also a noise-reduction means.
- Call depth (Table 7, 500 samples): F1 is highest at k = 3 (94.18), 91.04 at k = 1, and drops to 91.98 at k = 5 with average tokens rising to 11,157.6.
- Dependency combination and granularity (Table 8, k = 3): The full combination (CC+DD+CD, whole function) has F1 of 94.18; keeping only execution lines (V2) reduces tokens to 4,031.7 but F1 to 86.49; removing call chains (V5) gives F1 of 89.41.
LLM influence and data contamination (RQ3)
- Different LLMs (Table 9): GPT-4o is highest on Python (F1 97.8), JavaScript (93.1), and Go (93.3); DeepSeek-V3 is highest on PHP (94.2); the authors state that no single model dominates across the board, and DeepSeek-V3 was chosen for overall cost.
- Data contamination (Table 10): Comparing Multi-Lang-Bench samples released before May 2024 with 260 DataDog malicious packages released after January 2025; DeepSeek-V3's F1 on the Python after subset is 94.1 (before is 96.3), and GPT-4o's on Python after is 93.1 (before is 97.8); the authors believe contamination may bring a slight advantage but the impact is acceptable.
- TPL identification reliability: Manual spot-checking of 50% of third-party APIs judged sensitive by the LLM (347 out of 694) found only 4 false positives (§4.4).
Cost and large-scale real-world test (RQ4)
- Cost (Table 11, 2,168 repositories): Pre-filtering filters out 83.5% of files (118,200 → 19,477); after slicing, LLM analysis tokens drop from 319 million to 19.2 million, and cost from $86.25 to $5.19 (a 94.0% reduction); parsing takes 40.6 seconds and slicing 53.3 seconds per repository.
- Real-world test: Full analysis of GitHub-120K consumes 1.255 billion tokens, about $338; 1,553 suspicious repositories were initially reported, and manual review excluded 502 false positives (FDR 32.2%) and 487 repositories self-described as penetration testing/security research/malicious code collection, confirming 564 unknown malicious repositories (C/C++ 200, Python 174, JavaScript 56, Java 31, Go 21), which have been reported to the GitHub security team (§4.5).
Other ablations and analyses
- Preliminary experiments (Table 1): Slice-level context FNR 0.0%–2.0%, repository-level OOC failure rate up to 46.0% (PHP).
- Slicing reduces tokens by 97.6% relative to repository-level context (Table 1, 250 samples).
- The authors estimate the cost of analyzing one million repositories: about $26K at repository level and about $625 at slice level; the authors note that this estimate is approximate (§2.2).
What are some points that can be further explored?
The authors list four limitations (toolchain dependence, no cross-language support, omitted alias resolution, prompt injection surface) and several future directions; the evaluation covers 5 languages.
Limitations and future directions noted by the authors
- Dependence on static analysis toolchain (§5 Limitations): The slicing stage requires language-aware static analysis support; extending to new languages requires integrating a suitable parsing/slicing backend and organizing the initial built-in sensitive APIs; the authors mention that frameworks such as CodeQL and YASA could be substituted.
- No support for cross-language attacks (§5 Limitations): Cannot track data or control flow across language boundaries (e.g., Python calling a C library); the authors state this creates a blind spot for payloads hidden in native extensions.
- Pre-filtering omits alias resolution (§5 Limitations): For scalability, complex alias resolution is omitted; the authors state this creates a blind spot for attacks that hide sensitive operations behind multi-hop alias chains, but believe that an average recall exceeding 90% indicates this trade-off is acceptable for current real-world threats.
- New attack surface introduced by LLMs (§5 Limitations): The authors state that the LLM analyzer may be subject to prompt injection; attackers can embed deceptive comments or misleading strings in code to induce the model to judge malicious code as benign.
- Future directions (§5 Future Work): Extend to ecosystems such as VSCode extensions, MCP servers, and agent skills; support more languages such as C/C++ and Ruby; perform incremental analysis on PRs or commits; the authors state they are collaborating with the VirusTotal team and plan to integrate MalTotal into its platform.
Experimental coverage
- The languages tested are Python, JavaScript, Java, Go, and PHP, 5 in total; the Java/PHP/Go subsets have 150–286 samples per language, and the Python/JavaScript subsets have 6,444/9,545 packages respectively (Table 4).
- The comparison baselines are 8 tools, of which only ApplicationInspector and OSSGadget are compared on Go/Java/PHP (§4.1).
- The LLM replacement experiment covers 5 models: GPT-4o, GPT-3.5 Turbo, Claude 4 Sonnet, Gemini 3 Pro, and DeepSeek-V3 (Table 9).
- The repositories in the large-scale real-world test come from the subset of abnormally popular repositories filtered by StarScout (120K downloaded out of 186K); the paper notes that due to storage and processing costs, the full StarScout dataset was not covered (§4.1 footnote 3).
- The paper does not report the number of repetitions or statistical significance tests for the main experiments; the manual spot-check sample for TPL identification reliability is 347 (§4.4).
Summarize the main content of the paper
MalTotal uses LLM sensitive API identification plus hybrid slicing for language-agnostic malicious code detection; the authors report an average F1 of 93.1% across 5 languages, a 94.0% token reduction, and 564 unknown malicious repositories discovered among 120K repositories.
A paper on a detection system for software supply chain security, proposing MalTotal: low-cost detection of malicious code poisoning across millions of multilingual GitHub repositories and package registry platforms.
- Problem: The authors argue that existing heuristic, learning, and LLM detection methods are respectively limited by language-specific design, insufficient generalization to novel malicious semantics, and context window and token costs, making it difficult to scale to millions of repositories.
- Method: A three-stage pipeline—LLM semantic summarization to identify built-in and third-party library sensitive APIs (2,147 built-in + 694 third-party); reverse hybrid slicing from sensitive call sites on code property graphs generated by Joern (call chain depth k = 3, Jaccard threshold τ = 0.3 for aggregation); LLM-as-a-Judge with CoT prompting to determine malicious intent and output structured conclusions.
- Main results: On the self-built Multi-Lang-Bench, MalTotal achieves F1 of 91.0%–96.3% across 5 languages against 8 baselines, averaging 93.1% (Table 5); on JavaScript, precision is lower than SAP, which the authors state is because SAP trades recall for it.
- Cost: On 2,168 repositories, pre-filtering plus slicing reduces LLM analysis tokens from 319 million to 19.2 million (a 94.0% reduction), and cost from $86.25 to $5.19 (Table 11).
- Real-world test: On 120K repositories (7.3 million files) derived from StarScout, at a cost of about $338, 564 previously unknown malicious repositories were discovered; after manual review, the FDR is 32.2%, and all have been reported to GitHub (§4.5).
- Authors' conclusions and implications: The authors state that LLMs combined with streamlined slicing context can achieve language-agnostic malicious semantics detection; they also acknowledge that the system does not support cross-language tracking, omits alias resolution, and that the LLM analyzer itself may become a target of prompt injection; they plan to extend ecosystem support and integrate into VirusTotal.