fix(security): use uv run for pip-audit and bandit in python-publish-pypi.yml#49
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Python PyPI publish workflow's security checks step now invokes ChangesCI Security Checks
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing [Slack Agent](https://www.coderabbit.ai/agent): Turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 10 minutes and 9 seconds.Comment |
|
@github-copilot review |
There was a problem hiding this comment.
Pull request overview
Updates the reusable PyPI publishing workflow’s pre-publish security gate to run scanners in the project context (via uv run) instead of an isolated throwaway environment (uvx), so dependency auditing reflects what would actually be published.
Changes:
- Switch
pip-auditinvocation fromuvx pip-audittouv run pip-audit --strict. - Switch
banditinvocation fromuvx bandit ...touv run bandit ...for consistency.
| @@ -95,8 +95,8 @@ jobs: | |||
| SRC_DIR: ${{ inputs.source-directory }} | |||
| run: | | |||
| echo "Running pre-publish security checks..." | |||
There was a problem hiding this comment.
Fixed in ae9c695: switched to uv run --with pip-audit==2.10.0 pip-audit --strict and uv run --with 'bandit[toml]==1.9.4' bandit .... The --with flag installs each tool into a temporary overlay on top of the project venv, preserving correct dependency scope while working for all downstream callers regardless of their dev dependencies.
PR Review9 findings (3 Critical, 3 Important, 2 Suggested, 1 Informational) Critical (must fix before merge)
Important (should fix)
SonarQube: not configured for this repository. Copilot review requested; see Reviewers section for the inline comment at line 97. 🤖 Generated with Claude Code |
uvx pip-audit runs in an isolated throwaway environment with no access to the project venv or uv.lock, so it audits nothing meaningful and will always pass regardless of project dependencies. uv run pip-audit runs inside the project venv and audits the packages that will actually ship. The --strict flag causes pip-audit to fail if any dependency cannot be resolved, rather than silently skipping it -- the correct posture for a pre-publish gate. This is the same fix applied to python-ci.yml in the architecture cleanup (commit 2243166). Closes the same gap in the publish workflow. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ion pins Replace bare `uv run pip-audit --strict` and `uv run bandit` with `uv run --with` invocations that include explicit version pins. The previous form required both tools to be listed as project dev dependencies in every downstream caller's uv.lock; callers without them would hard-fail the publish gate or audit an empty environment. Using `--with pip-audit==2.10.0` and `--with 'bandit[toml]==1.9.4'` installs each tool into a temporary overlay on the project venv, preserving correct dependency scope for all callers and locking tool behavior across cache evictions. Closes Copilot comment on PR #49. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
901c119 to
ae9c695
Compare
PR Fix SummaryAddressed 4 of 9 findings (3 Critical, 1 Important fixed): Workflow fix (
CHANGELOG (
PR body: Updated to remove em-dashes (CLAUDE.md compliance) and align the Static analysis section with the actual Copilot thread: Replied with fix details Remaining (informational, no code change needed):
Pre-commit: not configured in this repo. CI re-run triggered by push. 🤖 Generated with Claude Code |
Summary
Root cause
`uvx` is an alias for `uv tool run --no-project`, which runs the tool in an isolated throwaway environment with no access to the project's virtual environment or `uv.lock`. This means `uvx pip-audit` effectively audits an empty environment and will always pass; the security gate provides false confidence and will never catch a vulnerable project dependency.
`uv run --with` installs the specified tool into a temporary overlay on top of the project's `.venv`, giving pip-audit visibility into all packages that will actually ship to PyPI. The `--with` form is used rather than bare `uv run` so the workflow works for all downstream callers regardless of whether they list pip-audit and bandit as explicit dev dependencies.
Why `--strict`
`pip-audit --strict` fails if dependency collection fails on any single package, rather than silently skipping unresolvable packages. For a publish gate this is the correct posture: an unresolvable dependency is itself a risk signal.
Prior art
The same fix was applied to `python-ci.yml` in commit `2243166` ("fix(ci): migrate pip-audit from uvx to uv run for correct dependency scope"). This PR closes the same gap in the publish workflow, which is a higher-stakes gate.
Static analysis warnings
One SonarQube diagnostic fires on the new lines (S8541). It is a false positive in this context:
S8544 (unlocked versions) is now addressed by explicit version pinning in the `--with` flags (`pip-audit==2.10.0`, `bandit[toml]==1.9.4`).
Test plan
Generated with Claude Code