# GHSA-rpj2-4hq8-938g: VCR.py: Arbitrary code execution via unsafe YAML deserialization of cassette files

> Attackers can execute arbitrary code by supplying malicious YAML cassette files to vcrpy, which uses unsafe deserialization loaders.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 19 Jun 2026

## What is GHSA-rpj2-4hq8-938g?

GHSA-rpj2-4hq8-938g is an unsafe deserialization vulnerability in vcrpy, published on 19 Jun 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

### Summary

vcrpy deserializes YAML cassette files with PyYAML's object-constructing loader (`yaml.CLoader` / `yaml.Loader`) instead of the safe loader (`yaml.CSafeLoader` / `yaml.SafeLoader`). A cassette containing a `!!python/object/apply:` (or similar) tag therefore executes arbitrary Python code the moment the cassette is loaded — including through the normal `VCR().use_cassette()` path, before any HTTP interaction is replayed.

This is **not** limited to environments lacking the libYAML C extension. `CLoader` uses the C parser but PyYAML's full Python *constructor*, so Python
object tags execute under `CLoader` exactly as under the pure-Python `Loader`. Confirmed against vcrpy 8.1.1 + PyYAML 6.0.3 with `CLoader` active.

### Affected component

- `vcr/serializers/yamlserializer.py` — `deserialize()` → `yaml.load(cassette_string, Loader=Loader)` where `Loader` is `CLoader`/`Loader`. Reached on **every** cassette load.
- `vcr/migration.py` (~line 107) — `yaml.load(preprocess_yaml(...), Loader=Loader)`. A second sink reached when the migration tool is run on a `.yaml` file. `preprocess_yaml()` only strips three known legacy tags, so other tags still execute.

Present in all releases inspected, 1.0.0 through 8.1.1.

### Proof of concept

```python
import vcr, requests

# Attacker-supplied cassette. The payload sits in an ignored top-level key
# so the rest of the cassette stays valid; it fires during load.
open("evil.yaml", "w").write("""interactions:
- request:
    body: null
    headers: {Accept: ['*/*']}
    method: GET
    uri: http://example.com/
  response:
    body: {string: ok}
    headers: {Content-Type: ['text/plain']}
    status: {code: 200, message: OK}
_x: !!python/object/apply:os.system ['touch /tmp/VCRPY_YAML_RCE']
version: 1
""")

with vcr.use_cassette("evil.yaml"):      # <-- /tmp/VCRPY_YAML_RCE created here
    requests.get("http://example.com/")
```

Loading the cassette creates `/tmp/VCRPY_YAML_RCE`, demonstrating arbitrary command execution. Any Python callable can be invoked this way.

### Impact

Arbitrary code execution in the process that loads the cassette, with that process's full privileges. Realistic delivery paths:

- A malicious cassette added in a pull request and loaded when CI runs the tests.
- A poisoned shared test-fixture repository or cassette artifact store.
- "Updated recorded HTTP fixtures" social-engineering.

Because cassettes are typically loaded by test suites in CI/CD and on developer machines, the exposed secrets are exactly the high-value ones in those environments: CI deployment credentials, cloud IAM roles, registry/publishing tokens, and source access.

### Patch

Use the safe loader in `vcr/serializers/yamlserializer.py`:

```python
try:
    from yaml import CDumper as Dumper
    from yaml import CSafeLoader as Loader
except ImportError:
    from yaml import Dumper
    from yaml import SafeLoader as Loader

def deserialize(cassette_string):
    return yaml.load(cassette_string, Loader=Loader)
```

Apply the same `SafeLoader` change in `vcr/migration.py`.

This is backwards compatible: vcrpy cassettes only contain standard YAML (scalars/lists/maps plus `!!binary`, all supported by `SafeLoader`/`CSafeLoader`), so existing cassettes load unchanged. vcrpy's `serialize.deserialize()` already catches `yaml.constructor.ConstructorError`, so a Python-tagged cassette now surfaces as the existing "old cassette format" `ValueError` instead of executing.

Recommended hardening: add a regression test that loads a cassette containing `!!python/object/apply:os.system` and asserts a `ConstructorError`/`ValueError` and that no side effect occurs.

## Which versions are affected by GHSA-rpj2-4hq8-938g?

2 open source packages ship an affected version, including vcrpy.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `vcrpy` | PyPI | All versions | 8.2.1 |
| `vcrpy` | PyPI | All versions | 8.2.1 |

## How do I fix GHSA-rpj2-4hq8-938g?

Upgrade vcrpy to 8.2.1 or later.

## Is GHSA-rpj2-4hq8-938g being exploited?

There is no known exploitation of GHSA-rpj2-4hq8-938g in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-rpj2-4hq8-938g and fix it if it is affected.

What it is: GHSA-rpj2-4hq8-938g is an unsafe deserialization vulnerability in vcrpy, published on 19 Jun 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-rpj2-4hq8-938g in the wild and no public exploit code.

Affected packages and fixed versions:
- vcrpy (PyPI): affected all versions; fixed in 8.2.1
- vcrpy (PyPI): affected all versions; fixed in 8.2.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-rpj2-4hq8-938g/ (Markdown: https://insights.sbomify.com/GHSA-rpj2-4hq8-938g/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-rpj2-4hq8-938g

---
From sbomify Insights: https://insights.sbomify.com/GHSA-rpj2-4hq8-938g/
Summaries are generated and may contain mistakes; the official description above is the record.
