Skip to content

Conversation

@thomas-chauchefoin-tob
Copy link
Collaborator

This fixes GHSA-wfq2-52f7-7qvj, GHSA-q5qq-mvfm-j35x, GHSA-p523-jq9w-64x9, GHSA-5hvc-6wx8-mvv4, GHSA-h4rm-mm56-xf63.

The changes are mostly additions to the list of unsafe imports, with the exception of GHSA-h4rm-mm56-xf63 that required emitting AST nodes for builtins imports, and GHSA-q5qq-mvfm-j35x for which we now extract top-level package names instead of comparing the full import name to the blocklist of unsafe imports.

Copy link
Collaborator

@ESultanik ESultanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, but I noticed one potential issue that might cause us to miss detections of malicious imports.

def unsafe_imports(self) -> Iterator[ast.Import | ast.ImportFrom]:
for node in self.properties.imports:
if node.module in (
if node.module and node.module.split(".")[0] in (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say you have a module that does something like this:

foo/bar.py

import code  # or any other unsafe module

and that module doesn't set __all__ to explicitly set exports. That allows the pickle to import foo.bar.code and it will work!

Therefore, I think we need to match against all of the components of the module path:

if any(component in EXISTING_LIST_OF_DANGEROUS_MODULES for component in node.module.split(".")):

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented with 595d7bb, thanks! Matching subpackages like os could be too broad, I'll keep an eye on new issues after the release.

@thomas-chauchefoin-tob thomas-chauchefoin-tob merged commit 0a908ed into master Jan 9, 2026
16 checks passed
@thomas-chauchefoin-tob thomas-chauchefoin-tob deleted the recent-reports branch January 9, 2026 17:42
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.

3 participants