Skip to content

Add warning to ZipFile.ExtractToDirectory and ExtractToDirectoryAsync docs#12355

Open
Copilot wants to merge 2 commits intomainfrom
copilot/add-security-warning-zipfile-extract
Open

Add warning to ZipFile.ExtractToDirectory and ExtractToDirectoryAsync docs#12355
Copilot wants to merge 2 commits intomainfrom
copilot/add-security-warning-zipfile-extract

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

ZipFile.ExtractToDirectory and its async variants are convenience APIs that don't enforce any limits on total uncompressed size or entry count, making them unsafe for use with untrusted archives.

Changes

  • Added a [!WARNING] callout to the <remarks> of all 16 overloads across ExtractToDirectory and ExtractToDirectoryAsync in xml/System.IO.Compression/ZipFile.xml
  • Warning directs callers to use ZipArchive for manual entry iteration and validate uncompressed size and entry count before extraction

The warning reads:

Warning: This method doesn't limit the total uncompressed size or the number of entries extracted from the archive. When processing archives from untrusted sources, iterate over the entries manually using ZipArchive, and validate that the total uncompressed size and the number of entries are within acceptable limits for your scenario.

The three pre-existing remark formats across the overloads are all handled:

  • Markdown (<format type="text/markdown"><![CDATA[...]]>) — warning inserted inline
  • Para (<para>...</para>) — <format type="text/markdown"> wrapper appended before </remarks>
  • Plain text — same <format type="text/markdown"> wrapper appended before </remarks>
Original prompt

Add a security warning to the documentation for System.IO.Compression.ZipFile.ExtractToDirectory and its async variants.

Repository: dotnet/dotnet-api-docs
File to update:

  • xml/System.IO.Compression/ZipFile.xml

Context:
The ZipFile.ExtractToDirectory methods and their async variants are convenience APIs that can be unsafe when used with untrusted ZIP archives because they can be used for zip-bomb-style attacks (for example, an archive that expands to a very large size or contains an excessive number of entries).

Requirements:

  1. In the XML documentation for the ZipFile.ExtractToDirectory methods and the async variants, add a Warning section in the <remarks>.
  2. The warning must state that when processing zip archives from untrusted sources, code should:
    • Iterate over entries manually.
    • Validate that the total uncompressed size and the number of files are permissible for the scenario.
  3. Follow style constraints:
    • Use present tense.
    • Don’t use the word "may". Use "might" for possibility or "can" for permission.
    • Use a comma before clauses beginning with "which".
    • Keep a conversational tone with contractions.
    • Be concise and break up long sentences.
    • Ensure any code comments end with a period.
  4. Don’t add inline markdown code blocks inside XML remarks. If a code snippet is needed, add it as a separate .cs file under the appropriate snippets folder, and add a .csproj if one doesn’t already exist.

No new code snippets are required unless you think it materially improves the warning.

Target branch: main

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 27, 2026
…toryAsync remarks

Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
Copilot AI changed the title [WIP] Add security warning for ZipFile.ExtractToDirectory methods Add zip-bomb security warning to ZipFile.ExtractToDirectory and ExtractToDirectoryAsync docs Feb 27, 2026
@rzikm rzikm added area-System.IO.Compression and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 27, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-compression

@rzikm
Copy link
Member

rzikm commented Feb 27, 2026

cc @GrabYourPitchforks, @blowdart for wording

@rzikm rzikm requested a review from gewarren February 27, 2026 14:04
@rzikm rzikm marked this pull request as ready for review February 27, 2026 14:04
@rzikm rzikm requested a review from a team as a code owner February 27, 2026 14:04
Copilot AI review requested due to automatic review settings February 27, 2026 14:04
@rzikm rzikm changed the title Add zip-bomb security warning to ZipFile.ExtractToDirectory and ExtractToDirectoryAsync docs Add warning to ZipFile.ExtractToDirectory and ExtractToDirectoryAsync docs Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds security warnings to all ZipFile.ExtractToDirectory and ExtractToDirectoryAsync methods, alerting developers that these convenience APIs don't enforce limits on uncompressed size or entry count, making them vulnerable to zip-bomb attacks when used with untrusted archives.

Changes:

  • Added security warnings to 16 method overloads in ZipFile.xml
  • Warning directs users to manually iterate entries using ZipArchive and validate limits before extraction
  • Applied consistent warning text across three different XML documentation formats (markdown, para, plain text)

If <paramref name="destinationDirectoryName" /> or any of its parent directories is a pre-existing junction or symbolic link, the link is followed and the extraction writes to the final target folder.
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.</remarks>
If a file to be archived has an invalid last modified time, the first date and time representable in the zip timestamp format (midnight on January 1, 1980) will be used.
<format type="text/markdown"><![CDATA[> [!WARNING]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we'll need to convert the entire remarks to Markdown:

image

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants