Skip to content

Implement Secure ZIP Extraction for Remote Datasets #1879

Closed

Description

Is your feature request related to a problem? Please describe.

Several remote dataset loaders download ZIP archives and extract them directly using zipfile.ZipFile.extractall() without validating archive entries before extraction.

Examples include:

  • pyrit/datasets/seed_datasets/remote/figstep_dataset.py
  • pyrit/datasets/seed_datasets/remote/vlguard_dataset.py

Current extraction logic relies entirely on Python's built-in ZIP handling and does not explicitly validate extracted paths, file counts, or archive metadata.

Since PyRIT supports Python versions 3.10 through 3.14, adding application-level validation would provide consistent security guarantees across all supported runtimes.

Describe the solution you'd like

Introduce a shared helper for secure ZIP extraction that:

  • Validates archive member paths before extraction.

  • Prevents path traversal attempts.

  • Ensures extracted files remain inside the intended destination directory.

  • Optionally enforces limits on:

    • file count,
    • individual file size,
    • total extracted size.

This helper could then be reused by all dataset downloaders that process remote ZIP archives.

Describe alternatives you've considered, if relevant

The current implementation relies on the protections provided by Python's zipfile module. While modern Python versions include safeguards, explicit validation would provide defense-in-depth and reduce reliance on interpreter-specific behavior.

Additional context

PyRIT currently supports:

requires-python = ">=3.10, <3.15"

The same extraction pattern appears in multiple dataset loaders, suggesting that a centralized safe extraction utility would improve maintainability and security across the project.

Activity

  1. romanlutz commented on Jun 1, 2026

    @romanlutz
    Contributor

    Do you want to handle it yourself Ruslan (@RuslanSemchenko) ?

  2. RuslanSemchenko commented on Jun 2, 2026

    @RuslanSemchenko
    Author

    Do you want to handle it yourself @RuslanSemchenko ?

    Well, the issue here isn't even about writing improved logic; as far as I'm concerned, we should move away from Python versions 3.10 and 3. 11, since they’ll be EOL very soon, and the best option would be to at least upgrade to 3.12 and, if possible, switch from ZIP to Tar, because if I’m not mistaken, starting with version 3.12, Python added data filtering during the unpacking of Tar archives, and this generally protects against tar slip issues
    PEP 706
    p.s Just using a ZIP file would require writing a lot of extra code—path checks and so on.

  3. romanlutz commented on Jun 2, 2026

    @romanlutz
    Contributor

    3.10 will be EOL sometime this year but 3.11 has quite a bit more left. I don't see us dropping it until then.

    We don't really have a choice about zip files. They're not provided by us.

  4. francose commented on Jun 5, 2026

    @francose
    Contributor

    can take this if no one else is on it.

    shape i'm thinking:

    • new safe-extract helper in pyrit/common (realpath check per member, total size cap, file count cap, per-file size cap, reject symlinks/devices)
    • swap in at the 3 call sites (figstep, vlguard, jailbreakv_28k)
    • tests for path traversal + zip bomb

    does that match what you had in mind?

  5. romanlutz commented on Jun 8, 2026

    @romanlutz
    Contributor

    I didn't open the issue but yes this matches my mental model 🙂 I'll assign it to you _| Y |\| X _84999 (@francose)

  6. marklicata commented on Aug 27, 2026

    @marklicata

    Hi Ruslan (@RuslanSemchenko) — Microsoft PM here researching AI red-teaming tool adoption (not on the PyRIT team). You flagged the secure ZIP extraction issue for remote datasets that was accepted by the team. When you came across this gap, were you evaluating PyRIT for use somewhere, and did you end up adopting it or not?

  7. RuslanSemchenko commented on Sep 3, 2026

    @RuslanSemchenko
    Author

    Hi Ruslan (@RuslanSemchenko) — Microsoft PM here researching AI red-teaming tool adoption (not on the PyRIT team). You flagged the secure ZIP extraction issue for remote datasets that was accepted by the team. When you came across this gap, were you evaluating PyRIT for use somewhere, and did you end up adopting it or not?

    To be honest, as far as I can tell, the code was written using AI and outdated syntax—and on top of that, it runs on an old version of Python, which makes adapting it a real pain. Well, most systems have now switched to Python 3.14, and these kinds of problems—exactly the ones that can arise—are ones I believe always need to be addressed. There are many risks and considerations here, such as the “supply chain” and execution risks, as well as the quality and maintainability of the codebase, and, in my opinion, all tools should be, so to speak, rigorous, and I’d rather spend 1–3 days of my own time writing everything by hand, so I’ll know exactly what’s going on and how it works, and the code will be safe in every sense; it may be written a bit unevenly, but I know for sure that this will be better, so I won’t use it right now. For instance, built-in archive extraction filtering (PEP 706) was only introduced in Python 3.12. Running on Python 3.10 without explicit application-level path validation leaves loaders vulnerable to Path Traversal by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions