Vulnerabilities in pkg:pypi/vcrpy

PACKAGE
Advisory Summary

GHSA-rpj2-4hq8-938g is a HIGH (CVSS 7.8) arbitrary code execution vulnerability (CWE-502: Deserialization of Untrusted Data) affecting Vcrpy libraries in the PyPI ecosystem. The issue involves arbitrary code execution via unsafe yaml deserialization of cassette files. Remediation is available by upgrading affected packages to version 8.2.1.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/vcrpy

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/vcrpy. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-rpj2-4hq8-938g - HIGH VCR.py: Arbitrary code execution via unsafe YAML deserialization of cassette files

GHSA-rpj2-4hq8-938g at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-rpj2-4hq8-938g
Severity HIGH
CVSS v3.1 Base Score 7.8
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product Vcrpy
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-rpj2-4hq8-938g

To remediate this vulnerability, upgrade all affected Vcrpy dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

vcrpy fixed: 8.2.1
pip install vcrpy>=8.2.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show vcrpy

How to Check if You Are Affected

To determine whether your Python environment is affected by GHSA-rpj2-4hq8-938g, inspect your installed packages using pip:

pip show vcrpy

Analyze the terminal output to locate any version of Vcrpy in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.2.1), your application is affected.

Note: The pip show vcrpy command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In Vcrpy, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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.

GHSA-rpj2-4hq8-938g Affected Vcrpy Versions

1 component(s)
Fixed Versions:
8.2.1
Product / Package Ecosystem Affected Versions Fixed Version
vcrpy
PyPI
< 8.2.1
8.2.1

References

Frequently Asked Questions

What is GHSA-rpj2-4hq8-938g?
GHSA-rpj2-4hq8-938g is a security vulnerability in Vcrpy involving Arbitrary code execution via unsafe YAML deserialization of cassette files under CWE-502: Deserialization of Untrusted Data.
Which Vcrpy versions are affected?
Affected versions include releases prior to 8.2.1 across affected packages: vcrpy.
What version fixes GHSA-rpj2-4hq8-938g?
Upgrading to 8.2.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is vcrpy affected?
Yes, vcrpy is affected in releases prior to 8.2.1. Upgrade your dependency to 8.2.1 or later.
What is the CVSS score of GHSA-rpj2-4hq8-938g?
GHSA-rpj2-4hq8-938g has a CVSS v3.1 base score of 7.8 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with GHSA-rpj2-4hq8-938g?
GHSA-rpj2-4hq8-938g is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check PyPI dependencies for GHSA-rpj2-4hq8-938g?
Run the dependency tree command: 'pip show vcrpy'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-rpj2-4hq8-938g",
  "modified" : "2026-06-19T21:15:47Z",
  "published" : "2026-06-19T21:15:47Z",
  "aliases" : [ ],
  "summary" : "VCR.py: Arbitrary code execution via unsafe YAML deserialization of cassette files",
  "details" : "### Summary\n\nvcrpy 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.\n\nThis is **not** limited to environments lacking the libYAML C extension. `CLoader` uses the C parser but PyYAML's full Python *constructor*, so Python\nobject tags execute under `CLoader` exactly as under the pure-Python `Loader`. Confirmed against vcrpy 8.1.1 + PyYAML 6.0.3 with `CLoader` active.\n\n### Affected component\n\n- `vcr/serializers/yamlserializer.py` — `deserialize()` → `yaml.load(cassette_string, Loader=Loader)` where `Loader` is `CLoader`/`Loader`. Reached on **every** cassette load.\n- `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.\n\nPresent in all releases inspected, 1.0.0 through 8.1.1.\n\n### Proof of concept\n\n```python\nimport vcr, requests\n\n# Attacker-supplied cassette. The payload sits in an ignored top-level key\n# so the rest of the cassette stays valid; it fires during load.\nopen(\"evil.yaml\", \"w\").write(\"\"\"interactions:\n- request:\n    body: null\n    headers: {Accept: ['*/*']}\n    method: GET\n    uri: http://example.com/\n  response:\n    body: {string: ok}\n    headers: {Content-Type: ['text/plain']}\n    status: {code: 200, message: OK}\n_x: !!python/object/apply:os.system ['touch /tmp/VCRPY_YAML_RCE']\nversion: 1\n\"\"\")\n\nwith vcr.use_cassette(\"evil.yaml\"):      # <-- /tmp/VCRPY_YAML_RCE created here\n    requests.get(\"http://example.com/\")\n```\n\nLoading the cassette creates `/tmp/VCRPY_YAML_RCE`, demonstrating arbitrary command execution. Any Python callable can be invoked this way.\n\n### Impact\n\nArbitrary code execution in the process that loads the cassette, with that process's full privileges. Realistic delivery paths:\n\n- A malicious cassette added in a pull request and loaded when CI runs the tests.\n- A poisoned shared test-fixture repository or cassette artifact store.\n- \"Updated recorded HTTP fixtures\" social-engineering.\n\nBecause 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.\n\n### Patch\n\nUse the safe loader in `vcr/serializers/yamlserializer.py`:\n\n```python\ntry:\n    from yaml import CDumper as Dumper\n    from yaml import CSafeLoader as Loader\nexcept ImportError:\n    from yaml import Dumper\n    from yaml import SafeLoader as Loader\n\ndef deserialize(cassette_string):\n    return yaml.load(cassette_string, Loader=Loader)\n```\n\nApply the same `SafeLoader` change in `vcr/migration.py`.\n\nThis 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.\n\nRecommended 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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "vcrpy"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "8.2.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/kevin1024/vcrpy/security/advisories/GHSA-rpj2-4hq8-938g"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/kevin1024/vcrpy"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-19T21:15:47Z",
    "nvd_published_at" : null
  }
}