Skip to content

Chromium: unzip writes nothing outside its folder, even through chained links - #556

Open
MopigamesYT wants to merge 2 commits into
devfrom
fix/524-chromium-unzip-links
Open

MopigamesYT wants to merge 2 commits into
devfrom
fix/524-chromium-unzip-links

Conversation

@MopigamesYT

Copy link
Copy Markdown
Member

Part of #524

What changed

unzip (Chromium's archive) created each link as it came and checked its target from its name in the archive. Each link in a chain such as p/q/r -> .., p/q/r/s -> ../.., p/q/r/s/t -> ../../../x really points one folder higher than its name says. With the old code, the test's archive leaves a link outside dest (one/two/t was written outside dest).

Now:

  • a name must be local (filepath.IsLocal: no .., not absolute, while ..env.example is fine);
  • files and folders are written first, while no link exists;
  • links come after, each resolved against the folder it really is in, then all of them against the real filesystem;
  • special files are refused.

Tests: TestUnzipRefusesHostileArchives (chained links, .., absolute names and links, a file under a link: nothing may exist outside dest), TestUnzipKeepsLegitimateLinks (a macOS framework's Versions/Current links, ..env.example).

Why "Part of"

The other four extractors (extensions, updates, the phone's Debian root, project sync) are not merged into one internal/core extractor yet. That is the rest of #524.

Nothing visible: no screenshots. Checked here: go test ./internal/browser (the old code fails the chained-links case).

Assisted-by: Claude Opus 5.5 medium

🤖 Generated with Claude Code

…ed links (#524)

unzip created each link as it came and checked its target from its name
in the archive. Each link in a chain such as p/q/r -> .., p/q/r/s ->
../.., p/q/r/s/t -> ../../../x really points one folder higher than its
name says, so the last one, and anything written through it, landed
outside the folder (the test shows the link ending above dest).

Now a name must be local (filepath.IsLocal: no "..", not absolute,
while "..env.example" is fine); files and folders are written first,
while no link exists; links come after, each resolved against the
folder it really is in, then all of them against the real filesystem.
Special files are refused.

Part of #524: the other four extractors are not merged into one yet.

Tests: TestUnzipRefusesHostileArchives (chained links, "..", absolute
names and links, a file under a link), TestUnzipKeepsLegitimateLinks (a
macOS framework's links, "..env.example").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants