/

CVE-2026-58474

Severity:

HIGH RISK

(8.8)

Code Injection (CWE-94) in whichllm CLI Command Handler

CVE-2026-58474

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A code injection vulnerability in whichllm's run and snippet commands allows malicious HuggingFace repository owners to execute arbitrary code on a user's machine. The issue occurs when a crafted GGUF filename is inserted into generated Python source without escaping, before the model is downloaded.

Affected context

The vulnerability affects whichllm deployments before 0.5.16 when the run or snippet commands process model metadata from a HuggingFace repository. It becomes risky when repository-controlled GGUF filenames are obtained from the Hub API and interpolated into generated Python code without treating the values as untrusted data.

Exploit preconditions

  • Attack surface: HuggingFace repository metadata consumed by the whichllm CLI
  • Required access: Control of, or the ability to publish or modify, a repository referenced by the victim
  • Trigger point: Execution of the run or snippet command against the malicious repository
  • Why exploitation is possible: A specially crafted rfilename value can escape the generated string literal and introduce executable Python statements before model download or subsequent validation

Why this happens

The underlying bug is direct interpolation of externally controlled filenames into Python source code. Special characters such as double quotes are not escaped or represented through a safe code-generation mechanism, allowing data to alter the structure of the generated program.

This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because repository metadata is treated as trusted source-code content rather than as a value that must remain inert.

Potential impact

  • Arbitrary code execution on the user's machine
  • Theft or modification of local files and credentials
  • Installation of persistent malware or additional tooling
  • Compromise of downstream development or model-serving environments
  • Unauthorized network access from the affected host

General mitigation guidance

Mitigation generally focuses on preventing untrusted metadata from becoming executable source code.

Common defensive patterns include:

  • Passing filenames and model metadata as runtime data rather than interpolating them into source text
  • Using structured code-generation or serialization APIs that handle escaping automatically
  • Applying strict validation and allowlisting for filenames and repository metadata
  • Treating all remote repository fields as untrusted, even when they come from a reputable hosting service
  • Separating metadata processing from command execution and model loading
  • Running CLI operations with least-privilege accounts, restricted filesystem access, and limited network permissions
  • Requiring explicit trust decisions before executing repository-provided artifacts or generated code

How teams detect issues like this

Detection can include static analysis for string interpolation, concatenation, or template construction that places external values into Python source code. Code review should flag generated-language constructs, use of exec-like execution paths, and repository metadata incorporated into scripts without escaping or structured parameterization.

CI policies can require safe code-generation patterns, prohibit dynamic execution of untrusted content, and test filenames containing quotes, backslashes, delimiters, and other syntax-significant characters. Automated security review tools may help identify these patterns, but findings should be validated against the data flow from remote metadata to code execution.

Sources

SourceLink
github.comgithub.com/Andyyyy64/whichllm/commit/77e8dc9e8b45212c694d631d758623e17a00859e
github.comgithub.com/Andyyyy64/whichllm/pull/147
github.comgithub.com/Andyyyy64/whichllm/releases/tag/v0.5.16
vulncheck.comvulncheck.com/advisories/whichllm-code-injection-via-run-and-snippet-commands

Frequently asked

questions

Yes, in the practical sense that a remote HuggingFace repository can provide the malicious filename. However, exploitation requires a user to run an affected command against that repository.

No prior local access is necessarily required. The attacker needs control of, or the ability to publish metadata in, a repository that the victim processes, while the victim must execute the affected CLI workflow.

Keep repository-derived values as data and pass them through structured APIs or safely escaped parameters. Do not interpolate them into executable Python source.

Treat all remote metadata as untrusted, test code-generation boundaries with syntax-special characters, enforce static-analysis policies for dynamic execution, and operate model tooling with minimal privileges.

Find out what's already
exploitable in your codebase.