-
Notifications
You must be signed in to change notification settings - Fork 3
Use importlib instead of exec #12
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
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.
That's a huge improvement, thanks a lot! And sorry for not responding earlier, I wasn't watching this repo.
Some small suggestions below.
Edit: I tested it locally with the latest Plover and it works great for my Python dictionary files.
|
This will also make #11 obsolete (in my mind its a better solution than compile() ) |
|
Additionally, since we are using importlib already, we should consider limiting scopes passed to the module loaded. This includes blocking most modules such as |
That's a tricky one. I see the benefits from a security standpoint but it would restrict the possibilities of what a python dictionary can do. I would like there to be something like a "safe mode" config for this plugin that is set to true by default but that "power users" could set to false. If "safe mode" is enabled, such modules would be blocked. Certainly something for another PR though. What do you think? |
I understand what you mean but there is zero reason why any python dictionary will need to access |
I can see examples like:
|
|
Yea I see, it's not going to be a perfect solution. Anyway this would be for further discussion. This PR should stay as is for now |
|
All changes have been done. Please review |
mkrnr
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 great! Thanks again for the contribution and for the security discussion; it's great to see people care about small open-source projects like this one 🙂
|
No problem! Thanks for the review and merge |
|
it's questionable how more serious issues:
|
Thanks for your input! Initially, the module name was just the file name but then I suggested that there could be issues when having two python files with the same file name, see this discussion. We could change it back to file name only or find another way to make the name unique. |
|
There should be no need to inject it into Unless the user wants to |
The sys.modules was there in the original version before I changed how modules were named. It doesn't make sense with the current naming change to the full path, so unless that is changed, yes, it can be removed. As for the current module naming system, using just And yes, while importlib is not inherently safer than exec it is just generally better practice. Nowhere should |
This PR removed the old use of exec for loading python dictionaries to instead using importlib. No changes are required to any dictionaries nor Plover.
Why
Overall this makes the code safer, helps dictionary developers, and makes it generally easier to maintain, with zero loss in functionality and no required changes to any other code including dictionaries and Plover.