Skip to content

uv python pin and uv lock write through repo-shipped .python-version / uv.lock symlinks #23319

Open

Description

@developingchet

A repository can ship .python-version or uv.lock as a symlink, and uv writes through the link to its target, outside the project.

Verified on uv 0.13.9:

  1. .python-version as a symlink (the stronger case): uv python pin 3.13 clobbers the symlink's target with no content gate. A victim file elsewhere on the machine is truncated to 3.13; if the symlink dangles into an existing parent directory, the file is created at that chosen path. Either way the symlink itself is preserved. Root: write_atomic_preserve (crates/uv-fs/src/lib.rs:501-566, documented as "preserving symlinks... a missing symlink target is created when its parent directory exists"), reached ungated from crates/uv-python-discovery/src/version_files.rs:289-304.

  2. uv.lock as a symlink: uv lock and uv sync write through to the target as well, with one mitigating gate — uv parses the existing lock before committing, so a target holding arbitrary content fails the TOML parse and nothing is written; a target holding a valid lock is rewritten, and dangling targets are created at the chosen path. Reached from crates/uv-lock-operations/src/lock_target.rs:405.

Reproduction: in a scratch project, ln -s /tmp/victim.txt .python-version, put known content in the victim, run uv python pin 3.13; the victim now contains 3.13. Control: with a regular .python-version, the write stays in the project.

The write-through is deliberate (the doc comment on write_atomic_preserve states symlink preservation as the design, and #22399/#22402 describe preserving symlink targets and modes as publication policy), but here the victim never chose the target — the repository did by shipping the link, and the write lands on a file outside the repository the pin command was never authorized to touch. #21857/#21891 (a repo-tracked symlink redirecting a write outside the checkout, labeled bug and fixed) looks like the same class.

Suggested direction: for these project-state files, either write to the literal path (replacing the symlink) rather than its target, or refuse to follow a symlink unless the target is inside the project directory.

A self-verifying PoC script with canary files and clean controls is available on request. All testing was local.

Activity

  1. zanieb commented on Nov 20, 2026

    @zanieb
    Member

    Note you MUST trust projects that you run commands in, they can always perform arbitrary code execution during operations like uv lock.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions