Skip to content

fix: .pth false positives on known-safe Python ecosystem files#41

Merged
garagon merged 1 commit intomainfrom
hotfix/pth-false-positives
Mar 25, 2026
Merged

fix: .pth false positives on known-safe Python ecosystem files#41
garagon merged 1 commit intomainfrom
hotfix/pth-false-positives

Conversation

@garagon
Copy link
Copy Markdown
Owner

@garagon garagon commented Mar 25, 2026

Problem

aguara check flags _virtualenv.pth as CRITICAL because it contains import _virtualenv. This is a legitimate file installed by virtualenv in every Python environment. Users running aguara check get dozens of false positive CRITICAL findings from their uv cache.

Fix

Allowlist of known-safe .pth filenames that use import statements for legitimate site customization:

  • _virtualenv.pth (virtualenv activation)
  • distutils-precedence.pth (setuptools distutils override)
  • easy-install.pth (legacy easy_install)
  • setuptools.pth (setuptools shim)
  • coverage.pth (coverage.py startup)
  • zope-nspkg.pth (zope namespace packages)

Changes

  • aguara check: allowlist in checker.go skips known-safe filenames before scanning
  • SC-EX-004: removed bare ^import\s pattern (too broad), replaced with import\s+\w+\s*;\s*\w for compound statements. Added exclude patterns for known-safe imports.
  • SC-EX-010: added exclude patterns for known-safe imports

Malicious .pth files (with subprocess, exec, eval, etc.) are still detected as CRITICAL.

Test plan

  • TestCheckSkipsKnownSafePth - known-safe skipped, evil.pth still flagged
  • All rule self-tests pass (SC-EX-004 TPs still match, new FP import _virtualenv excluded)
  • Real virtualenv site-packages: clean scan
  • Full CI: all tests pass, 0 lint

_virtualenv.pth, distutils-precedence.pth, setuptools.pth, coverage.pth,
easy-install.pth, and zope-nspkg.pth are legitimate ecosystem files that
use import statements for site customization.

- aguara check: allowlist skips known-safe filenames before scanning
- SC-EX-004: removed bare "import" pattern, added "import X; Y" pattern
  for compound statements. Exclude patterns for known-safe imports.
- SC-EX-010: exclude patterns for known-safe imports

Fixes false positives reported on _virtualenv.pth in uv cache.
@garagon garagon merged commit 2be2824 into main Mar 25, 2026
1 check passed
@garagon garagon deleted the hotfix/pth-false-positives branch March 25, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant