/

CVE-2025-51427

Severity:

HIGH RISK

(7.3)

Code Injection in ModelScope

CVE-2025-51427

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-502

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(7.3)

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

ModelScope 1.25.0 contains a code injection vulnerability where a crafted module value in the configuration file (dey_mini.yaml) under ['nnet']['module'] can be used to execute arbitrary code.

When untrusted configuration files are loaded and used to dynamically import or construct modules, an attacker may gain code execution in the context of the application process.

Affected context

This issue arises in ModelScope deployments that load and trust the dey_mini.yaml configuration file and use the ['nnet']['module'] field to determine which module or component to load.

The vulnerability is relevant when configuration files can be influenced by users, external services, or deployment automation, and when the module value is used to drive dynamic imports, execution, or reflection without strict validation or whitelisting.

Exploit preconditions

  • Attack surface: Configuration-driven module loading within ModelScope-based applications.
  • Required access: Ability to modify or supply the dey_mini.yaml configuration file or equivalent configuration input that controls ['nnet']['module'].
  • Trigger point: Application startup or model initialization phase where the configuration is parsed and the specified module is loaded or executed.
  • Why exploitation is possible: The module name or path from ['nnet']['module'] is treated as trusted and used for dynamic code loading or execution logic without sufficiently restricting or validating the allowed values.

Why this happens

The root cause aligns with CWE-94: Improper Control of Generation of Code ('Code Injection').

ModelScope appears to rely on configuration-driven module selection, likely using dynamic imports or reflection to load the module specified in ['nnet']['module'].

When such configuration is not tightly constrained to a known-safe set of modules or patterns, and is instead treated as arbitrary executable input, attackers can craft a configuration that causes the application to load or execute unintended code paths.

This insecure pattern results from mixing configuration data with execution control without imposing strict boundaries on what code can be referenced or run.

Potential impact

  • Execution of arbitrary code with the privileges of the ModelScope application process.
  • Access to sensitive data processed or stored by the application.
  • Modification or corruption of model parameters, training data, or inference results.
  • Use of the compromised process as a pivot point for further lateral movement inside the environment.
  • Deployment of backdoors or malicious logic into ML pipelines and downstream consumers.

General mitigation guidance

Effective mitigation emphasizes constraining configuration-driven execution and hardening module loading patterns:

  • Restrict ['nnet']['module'] to a fixed whitelist of known-safe modules or components rather than accepting arbitrary identifiers.
  • Use explicit, static mappings from configuration keys to implementation classes or functions instead of constructing import paths or code dynamically.
  • Validate configuration values against strict schemas and reject or ignore unknown or unexpected module names.
  • Separate configuration data from execution logic, avoiding patterns that transform configuration fields directly into import or execution statements.
  • Run ModelScope workloads with least-privilege OS accounts and process-level isolation to contain potential impact if misconfiguration occurs.

How teams detect issues like this

Organizations can detect and monitor this class of issue by:

  • Reviewing code paths where configuration values (especially module, class, or handler fields) are used to perform dynamic imports, eval-like behavior, or reflection.
  • Applying static analysis rules that flag use of dynamic import mechanisms or code execution APIs (e.g., importlib, __import__, eval, exec) that are fed by configuration or other external inputs.
  • Incorporating configuration schema validation and policy checks into CI/CD pipelines to ensure only approved module names are allowed.
  • Using automated code review and security scanning tools to highlight CWE-94 patterns and configuration-driven execution flows.

Sources

SourceLink
github.comgithub.com/JIRUWOZHI/vulnerability-disclosure/blob/main/CVE-2025-51427/CVE_2025_51427.md
github.comgithub.com/modelscope/modelscope/issues/1331
github.comgithub.com/modelscope/modelscope/pull/1333
access.redhat.comaccess.redhat.com/security/cve/CVE-2025-51427
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2479894
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2025/cve-2025-51427.json

Frequently asked

questions

It can be, if an attacker has a way to supply or modify the configuration file (dey_mini.yaml) or any upstream source that populates it over a network boundary, such as through an API, configuration management system, or file upload mechanism.

The attacker needs the ability to influence the ['nnet']['module'] value, typically by writing or replacing the configuration file or by controlling configuration data that the application ingests and persists.

The most robust approach is to replace arbitrary module loading with an explicit whitelist or registry of approved modules, where configuration only selects among predefined options and cannot introduce new import paths or executable code.

Avoid turning configuration values directly into executable logic, enforce strict schema validation and whitelisting for any configuration that affects code paths, and include automated checks for configuration-driven dynamic imports or code execution in development and deployment pipelines.

Find out what's already
exploitable in your codebase.