fix: Add pytest-cov.pth to known-safe allowlists (false positive)#7
Merged
Desperado merged 1 commit intoQuality-Max:mainfrom Mar 26, 2026
Merged
Conversation
pytest-cov installs a .pth file that uses exec() and references os.environ at interpreter startup to enable subprocess coverage tracking. This is legitimate behavior but triggers false positives in the .pth file injection and credential exfiltration tests.
Contributor
|
Good catch — pytest-cov uses the same .pth startup hook pattern as coverage.py for subprocess coverage collection. Legitimate allowlist entry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
pytest-cov.pthto the known-safe allowlists in bothtest_no_suspicious_pth_filesandtest_no_credential_exfiltration_in_startup, fixing two false-positive test failures.Problem
When
pytest-covis installed (which is very common — it's one of the most popular pytest plugins), two tests fail with false positives:Failure 1:
test_no_suspicious_pth_filesFailure 2:
test_no_credential_exfiltration_in_startupWhy pytest-cov uses a
.pthfilepytest-cov needs to measure coverage in subprocesses spawned during test runs. Since pytest plugins don't propagate into child processes, pytest-cov installs a
.pthfile that hooks into Python interpreter startup:This checks the
COV_CORE_SOURCEenvironment variable and, if present, initializes coverage tracking. The.envfalse positive comes from the substringos.environmatching the.envexfiltration target pattern.This is the same mechanism used by other already-allowlisted packages:
_virtualenv.pth— virtualenv startup hooka1_coverage.pth/coverage.pth— coverage.py startup hookdistutils-precedence.pth— setuptools path configurationImpact on users
Any user who has
pytest-covinstalled (directly or transitively) will see these two tests fail on every run, which:Fix
Add
pytest-cov.pthto both allowlists:test_no_suspicious_pth_files(line 326):test_no_credential_exfiltration_in_startup(line 648):Verification
With this fix applied, all 17 tests pass (14 pass, 3 skip due to no requirements.txt):