-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Move check_module_authorized out of import_module for use in get_safe_module #507
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
Merged
albertvillanova
merged 4 commits into
huggingface:main
from
CalOmnie:all_authorized_in_safe_module
Feb 11, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ce8d2d3
Move check_module_authorized out of import_module for use in get_safe…
CalOmnie bf74285
Add tests
CalOmnie 21328f7
Add test to check '*' behaves as expected now
CalOmnie ec27ba9
Merge branch 'main' into all_authorized_in_safe_module
aymeric-roucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I am actually not sure it's a good thing. If understand correctly, for example, given
itertools.*
instead of allowing all sub-packages of itertools, it will allow everything.Uh oh!
There was an error while loading. Please reload this page.
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.
I think you might misunderstand. Basically the current issue is that
get_safe_module
does not recognize the special additional import*
whileimport_module
does. The main effect of that is that when you use "*", you can execute otherwise forbidden import statements e.g.import os
, but those modules will be gutted of all their attributes becauseget_safe_module
will consider them all "dangerous".See this example:
This is the output:
As you can see the "os" that was import in the code run by the agent does not have any function.
If you run the same code from my branch, you will see that the two dirs are equal, which I believe should be the case.
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.
Mhm, probably I have misread the code. I.e. for some reason I have treated
authorized_imports
as a string. My worry was that if it is, thenif "*" in authrorized_imports
would have worked equally forauthrozed_imports='*'
and'authorized_imports='foo.bar.*'
. My bad.