package fetching: detect and fail when symlinks point outside the package root #17461
Labels
bug
Observed behavior contradicts documented or intended behavior
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
zig build system
std.Build, the build runner, `zig build` subcommand, package management
Milestone
Extracted from #17392.
This issue is to eliminate this TODO comment:
zig/src/Package/Fetch.zig
Lines 1195 to 1207 in f7bc55c
I was thinking about this more, and one strategy regarding symbolic links would be to not police what goes in them, since it could be an arbitrary string. These arbitrary strings do not necessarily reach outside of the package contents; they could be interpreted in any way. It could be considered the responsibility of other software, such as the compiler or build system - which would include user logic - to make sure that files within a package don't reach outside themselves into the file system.
However, I think that it may be better to look for relative paths inside symbolic links that reach outside their containing package and treat those as file system paths, and make those become errors, for these reasons:
So I think the TODO comment is correct. Package fetching code should detect when a symlink would point to outside the package, and make the fetch fail with an error.
The linked code points to tarball unpacking, but in order to close this issue, the same protection needs to be implemented in the other kinds of unpacking as well:
All future kinds of unpacking, such as #17408, will need the same logic.
Finally, this needs to integrate with #17460. Any bad symlinks that get excluded by the inclusion rules should not trigger a fetch failure, since they are not included in the package after all.
The text was updated successfully, but these errors were encountered: