fix: Emit warnings when files cannot be read instead of failing silently#3
Merged
Desperado merged 1 commit intoQuality-Max:mainfrom Mar 26, 2026
Merged
Conversation
Replace all silent `except (OSError, PermissionError): continue` blocks with `warnings.warn()` calls so that skipped files are visible in test output. Silent failures allow attackers to evade the scanner by restricting file permissions on malicious code.
Contributor
|
Good catch — permission-based evasion is a real attack pattern. Visibility > silence. |
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
Replace all silent
except (OSError, PermissionError): continueblocks withwarnings.warn()calls so that unreadable files are surfaced in test output.Problem
The scanner silently skips files it cannot read — in 8 separate locations:
Why this is a security concern
An attacker who understands this scanner's behavior could restrict file permissions on malicious files to evade detection:
# Attacker's malicious post-install script chmod 000 /path/to/site-packages/evil_package/__init__.py chmod 000 /path/to/site-packages/malicious.pthWith the current code, the scanner would:
PermissionErrorThe operator would have no indication that files were skipped, creating a false sense of security.
Affected scan areas
This silent-skip pattern exists in every major scanning function:
test_no_suspicious_pth_files.pthfiles with suspicious patternstest_pth_files_are_path_only.pthfiles with executable importstest_no_encoded_exfiltration_payloads__init__.pyfilestest_no_string_concat_obfuscation__init__.pyfilestest_no_suspicious_egg_info_scriptstest_no_setup_py_with_network_callssetup.pyfilestest_no_unexpected_pth_files.pthfilestest_no_credential_exfiltration_in_startup.pthfilesFix
Every
except (OSError, PermissionError)block now emits a warning viawarnings.warn():Why
warnings.warn()instead ofprint()orloggingwarnings.warn()integrates natively with pytest — warnings are collected and displayed in the test summary, making them impossible to miss.loggingdependency or configuration burden.-Wpytest flags (e.g.,-W errorto treat skipped files as failures).OWASP Reference