fix: reject path traversal in python entrypoints#2445
Merged
baszalmstra merged 1 commit intoMay 19, 2026
Conversation
…points `EntryPoint::FromStr` in `rattler_conda_types` previously only trimmed whitespace before the linker joined `command` onto the install prefix and wrote an executable Python script at `<prefix>/<bin_dir>/<command>` (with `-script.py` / `.exe` siblings on Windows). A malicious `noarch:python` package could ship `info/link.json` with an entry-point name containing `..`, `/`, `\`, or an absolute path, causing the resulting file to be written outside the prefix or clobber an in-prefix entry-point such as `bin/pip`. The renderer also interpolated `module` and `function` verbatim into the generated script body, giving a second code-injection surface. This change adds validation at two layers: * `EntryPoint::FromStr` now validates `command` as a simple file name (rejecting empty strings, `/`, `\`, `\0`, `.`, `..`, leading `.`, and absolute paths) and `module` / `function` as Python dotted identifiers. Errors are returned via a typed `ParseEntryPointError` enum (with a companion `EntryPointDottedField`) instead of bare strings. Both are re-exported from `rattler_conda_types::package`. * The install crate gains a `ValidatedRelativePath` newtype whose only constructor is `ensure_entry_point_relative_path`, which performs component-wise normalization and verifies that the resolved path stays under the install prefix. All filesystem-write helpers in `install::entry_point` (`write_validated_entry_point_file`, `write_validated_entry_point_bytes` for the Windows launcher, and `set_validated_entry_point_executable` for the Unix +x bit) take `&ValidatedRelativePath`, so the compiler rejects any call site that would reach a write without having run validation first. Tested via new unit tests covering the traversal vectors from the report (`../bin/pip`, absolute `/tmp/PWN`, Windows `..\..\..\`, hidden names, NUL byte), code-injection attempts in `module`/`function`, and realistic legitimate names (`jupyter-lab`, `pip3.11`, `pkg:Class.method`, `_private`). https://claude.ai/code/session_01RhMEEcinYyVNw9YtZTHqwR
pavelzw
approved these changes
May 19, 2026
Merged
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.
Fixes GHSA-q53q-5r4j-5729