Skip to content

[xabt] Validate extracted zip entry paths in ExtractJarsFromAar#11212

Merged
simonrozsival merged 1 commit intomainfrom
dev/peppers/unzip-validation
Apr 28, 2026
Merged

[xabt] Validate extracted zip entry paths in ExtractJarsFromAar#11212
simonrozsival merged 1 commit intomainfrom
dev/peppers/unzip-validation

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

This is just for correctness; there's no security enforcement here.

Add IsUnderDirectory check at both extraction points (jars and annotations) to silently skip zip entries whose resolved path escapes the target directory. Logs a debug message when an entry is skipped.

Add ExtractJarsFromAarTests with cases for jar traversal, annotations traversal, and a valid jar entry.

This is just for correctness; there's no security enforcement here.

Add `IsUnderDirectory` check at both extraction points (jars and
annotations) to silently skip zip entries whose resolved path escapes
the target directory. Logs a debug message when an entry is skipped.

Add `ExtractJarsFromAarTests` with cases for jar traversal, annotations
traversal, and a valid jar entry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 27, 2026 13:51
Copilot AI review requested due to automatic review settings April 27, 2026 13:51
Copy link
Copy Markdown
Member Author

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

New tests are running:

Image

I reran some flaky test lanes.

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Apr 27, 2026
Copy link
Copy Markdown
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 path validation when extracting jar and annotations entries from .aar archives to avoid writing files outside the intended output directories, and introduces tests covering traversal and non-traversal cases.

Changes:

  • Added an IsUnderDirectory check before extracting annotations.zip and *.jar entries to skip entries whose resolved path escapes the target directory.
  • Logged a debug message when an entry is skipped due to escaping the target directory.
  • Added ExtractJarsFromAarTests for jar traversal, annotations traversal, and a valid jar entry scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Xamarin.Android.Build.Tasks/Tasks/ExtractJarsFromAar.cs Adds a helper to validate resolved extraction paths are under the intended output directories and skips invalid entries.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ExtractJarsFromAarTests.cs Introduces tests intended to validate traversal skipping and successful extraction behavior.

Comment thread src/Xamarin.Android.Build.Tasks/Tasks/ExtractJarsFromAar.cs
@simonrozsival simonrozsival merged commit 9b5d3a1 into main Apr 28, 2026
7 checks passed
@simonrozsival simonrozsival deleted the dev/peppers/unzip-validation branch April 28, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants