Skip to content

fix(ai): Refuse uv audit when project is outside workspace #2440

Closed

Description

@dan-petty

Problem Description

The agent tool scan_uv_audit and its MCP tool check that their directory is inside the workspace (_run_adapter_scan in src/devops_cli/ai/tools/builtin_tools.py). uv audit finds the project from that directory and then from each parent directory. The workspace check does not apply to the project that uv finds. When no directory from the named directory up to the workspace root holds a project, uv finds a project in a parent directory of the workspace and audits its uv.lock.

The reply gives each finding at uv.lock:<package> and does not name the lockfile. Thus an agent reads the package names and versions of a lockfile outside the workspace, and takes them as the audit of the workspace.

Before the uv audit adapter (#2106), the tool ran uv audit in the directory of the process, with the same gap. A review of #2106 found it. #2106 does not change how uv finds the project, so this issue holds the gap.

Reproduction Steps

  1. Make a uv project at /tmp/example/proj (a pyproject.toml and its uv.lock), and an empty directory /tmp/example/proj/sub.
  2. Start the agent tools with /tmp/example/proj/sub as the workspace (the working directory of the process).
  3. Call scan_uv_audit(".").
  4. Run uv workspace dir --project /tmp/example/proj/sub. uv 0.12.23 writes /tmp/example/proj: the audit used the uv.lock of that directory, which is outside the workspace.

Expected vs Actual Behavior

Expected: the tool audits only a uv.lock inside the workspace. When the project that uv finds is outside the workspace, the reply gives no result (not_applicable or failed), with a reason that names the directory of that project.

Actual: scan_uv_audit(".") replies uv audit scan status: ok with the findings of /tmp/example/proj/uv.lock, and scan_uv_audit("..") replies Access Denied: .. is outside workspace.

A possible fix: before the audit, ask uv for the root of the project with uv workspace dir --project <directory> (uv 0.12.23 writes no preview warning for it), and refuse a root outside the workspace. Another possible fix: give the root that uv finds in the reply, and in the location of each finding.

Environment Diagnostics

Logs, Traces, or Terminal Output

$ uv workspace dir --project /tmp/example/proj/sub
/tmp/example/proj

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Source: #2106

Proposed design

Problem statement

The scan_uv_audit tool checks that its target directory is inside the workspace, but uv resolves the project by walking up parent directories. When no directory from the target to the workspace root holds a project, uv finds a project in a parent of the workspace and audits its uv.lock. The reply does not name the lockfile, so an agent reads findings from the wrong project and treats them as the audit of the workspace.

Acceptance criteria

Requirement: Project root boundary check

The tool SHALL resolve the project root via uv workspace dir --project and verify it is inside the workspace before running the audit.

Scenario: Project root outside workspace

  • WHEN scan_uv_audit(".") is called with the workspace at /tmp/example/proj/sub and the project at /tmp/example/proj
  • THEN the reply has status not_applicable and the reason names /tmp/example/proj

Requirement: Audit proceeds for in-workspace project

When the project root is inside the workspace, the tool SHALL run the audit and return its findings.

Scenario: Project root inside workspace

  • WHEN scan_uv_audit(".") is called with the workspace at /tmp/example/proj and the project at /tmp/example/proj
  • THEN the reply has status ok and findings from /tmp/example/proj/uv.lock

Requirement: Refusal reason names the project directory

When the project root is outside the workspace, the reply SHALL name the directory of that project in the reason field.

Scenario: Reason contains project path

  • WHEN the project root resolved by uv workspace dir is outside the workspace
  • THEN the reason in the reply contains the absolute path of the project root

Existing Tool Considered

uv workspace dir (uv 0.12.23+) resolves the project root from a directory and writes it to stdout. It covers the need to identify which project a target belongs to. The project calls it and checks the result against the workspace boundary. No new library is needed.

Key questions

  • Which fix approach prevents the wrong audit?: Call uv workspace dir --project before the audit and refuse if the project root is outside the workspace. This prevents the incorrect audit from running at all. (best practice) [sources: src/devops_cli/ai/tools/builtin_tools.py]
    • Chosen: Pre-audit boundary check via uv workspace dir. Prevents the wrong audit from running. The expected behavior states the tool audits only a uv.lock inside the workspace.
    • Rejected: Report the project root in the reply only. Adds transparency but still runs the audit on the wrong project. Does not meet the expected behavior.
  • Where in the code is the boundary check implemented?: In run_uv_audit_scan in devops_cli/security/uv_audit.py, because that adapter knows about uv project resolution and can call uv workspace dir with the target path it receives. (best practice) [sources: src/devops_cli/ai/tools/builtin_tools.py]
    • Chosen: In run_uv_audit_scan (the uv adapter). The adapter knows about uv project resolution. It receives the target path and can call uv workspace dir and check the result against Path.cwd().
    • Rejected: In scan_uv_audit in builtin_tools.py. Also works, but duplicates uv-specific logic in the generic tool layer. The adapter is the right place for uv-specific checks.
  • What status does the reply carry when the project is outside the workspace?: not_applicable, because the audit is not applicable to a project outside the workspace. The body lists not_applicable as the first option. (best practice) [sources: src/devops_cli/ai/tools/builtin_tools.py]
    • Chosen: not_applicable. The audit is not applicable to a project outside the workspace. The body lists it first. It is in CONST_SCAN_NO_RESULT_STATUSES so the reply adds the no-result line.
    • Rejected: failed. Implies the audit ran and errored, which is not the case. The audit was correctly refused before running.

Open questions

  • Does uv workspace dir --project work without a preview warning on uv 0.12.23? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-06: in-use.
The item already names this tool.
Tool: astral-sh/uv (https://github.com/astral-sh/uv), Apache-2.0, last activity 2026-11-06, maintained.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The tool audits a uv.lock outside the workspace, which is incorrect behaviour in a delivered feature.
    • Priority: P2-Medium. A security scan tool reports findings from the wrong file, but the scenario needs a specific directory layout.
    • Value: Medium. An agent could act on audit results from the wrong project, but the trigger is a narrow setup.
    • Effort: Low. The fix is one extra call to uv workspace dir and a boundary check before the audit runs.
    • Related: fix(security): scan_uv_audit runs a uv audit adapter, and the uv pip audit command that uv does not have goes #2106, which asks for a different change. Both work on scan_uv_audit in the same tool file; #2106 delivers the adapter, this candidate fixes a gap the adapter left in project resolution.
  3. added
    priority/p2-medium
    on Oct 28, 2026
  4. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 4a3242e until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Does uv workspace dir --project work without a preview warning on uv 0.12.23? (missing verified source)
  5. added
    scope/ai
    on Oct 30, 2026
  6. changed the title [-]fix(ai): scan_uv_audit audits the uv.lock of a project outside the workspace when the workspace holds no project[/-] [+]fix(ai): Refuse uv audit when project is outside workspace[/+] on Nov 6, 2026
  7. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 103 characters, and the limit is 60. The type and the scope stay.

    • Before: fix(ai): scan_uv_audit audits the uv.lock of a project outside the workspace when the workspace holds no project
    • After: fix(ai): Refuse uv audit when project is outside workspace
    • Source of the summary: the background model
  8. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    The item already names this tool.

    Tool: astral-sh/uv (https://github.com/astral-sh/uv)

    • License: Apache-2.0
    • Last activity: 2026-11-06
    • Maintained: yes

    Covers:

    • uv workspace dir --project <directory> resolves which project a directory belongs to and writes the project root to stdout, which is exactly the fact the tool needs before auditing
    • It is already the binary the adapter shells out to (uv audit), so no new library, dependency or install path is added
    • The printed root is an absolute path, so the tool can compare it with the workspace and refuse an outside project with a reason that names that directory

    Lacks:

    • uv performs no workspace-boundary check itself; the tool must still compare the printed root with the workspace and skip the audit
    • uv audit still discovers the project by walking up parent directories, so without the pre-check the wrong uv.lock is still audited
    • The issue's open question (whether the command is warning-free on uv 0.12.23) is not something uv's own packaging facts settle

    Searches run:

    • uv workspace dir command resolve project root
    • "uv workspace dir" --project
    • uv python package manager workspace
    • uv documentation workspaces

    Sources:

    Checked on 2026-11-06. A person decides what this means for the item. The check changes no label and closes no issue.

  9. added
    status/in-progress
    and removed
    status/new
    on Nov 9, 2026
  10. added a commit that references this issue on Nov 9, 2026
    1700648
  11. removed
    status/in-progress
    on Nov 9, 2026
  12. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor
  13. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-09 15:38 UTC

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

    effort/lowpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions