-
Notifications
You must be signed in to change notification settings - Fork 65
Address recent security reports #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ESultanik
left a comment
There was a problem hiding this 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.
fickling/fickle.py
Outdated
| 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 ( |
There was a problem hiding this comment.
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(".")):There was a problem hiding this comment.
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.
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.