Uh oh!
There was an error while loading. Please reload this page.
Use importlib instead of exec - #12
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
oliver408i
commented
Jul 9, 2025
This will also make #11 obsolete (in my mind its a better solution than compile() ) |
oliver408i
commented
Jul 9, 2025
Additionally, since we are using importlib already, we should consider limiting scopes passed to the module loaded. This includes blocking most modules such as |
mkrnr
commented
Jul 9, 2025
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? |
oliver408i
commented
Jul 9, 2025
I understand what you mean but there is zero reason why any python dictionary will need to access |
mkrnr
commented
Jul 9, 2025
I can see examples like:
|
oliver408i
commented
Jul 9, 2025
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 |
oliver408i
commented
Jul 9, 2025
All changes have been done. Please review |
mkrnr
left a comment
There was a problem hiding this comment.
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 🙂
oliver408i
commented
Jul 9, 2025
No problem! Thanks for the review and merge |
it's questionable how more serious issues:
|
mkrnr
commented
Jul 14, 2025
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.