fix(build): refuse a symlink as an archive member - #91
Merged
Conversation
Collecting archive members used stat, which follows links, so a directory link inside a plugin pulled whatever it pointed at into the zip. A `ui` link to a sibling directory put that directory's files into the archive, contents and all, and the build reported success — the entry string itself is perfectly ordinary, so validating it could never have caught this. Members are now collected with lstat and a link is refused wherever it appears, whether it is the entry itself or nested inside a directory being packaged. Refusing rather than resolving is both simpler and more correct: the archive stores file contents, so a link would be flattened into a copy regardless, and an absolute one names a path that exists only on the machine that built it. Collection moved next to the entry validation it belongs with, so both halves of "what goes into the package" are covered by the same tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Collecting archive members used
statSync, which follows symlinks. A directory link inside a plugin therefore pulled whatever it pointed at into the zip: auilink to a sibling directory put that directory's files into the archive, contents and all, and the build reported success.The entry string itself is perfectly ordinary in that case —
ui/index.htmlnames a relative path inside the plugin — so validating the entry could never have caught it. The escape happens on the filesystem, not in the manifest.Members are now collected with
lstatSync, and a link is refused wherever it appears: as the entry itself, or nested inside a directory being packaged. The message names the offending path.Refusing rather than resolving is both simpler and more correct here. The archive stores file contents, so a link would be flattened into a copy regardless of where it pointed, and an absolute link names a path that exists only on the machine that built the package.
Collection also moved next to the entry validation it belongs with, so both halves of "what goes into the package" are covered by the same tests rather than one being untestable inside the packaging script.
Verification
uilink to a sibling directory produced a 5-member archive whose contents included a file from outside the plugin entirely. After the change both that case and a link nested one level deeper are refused, with no zip left on disk.chat-flow,after-hoursandgsheets-loggerrebuild byte-identical tomain.