Skip to content
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

Avoid using eval to parse id_charset #54

Open
jvkersch opened this issue Jun 18, 2024 · 1 comment
Open

Avoid using eval to parse id_charset #54

jvkersch opened this issue Jun 18, 2024 · 1 comment

Comments

@jvkersch
Copy link
Contributor

The register objects code uses the builtin eval function twice to assemble a set of valid characters for object IDs, for example:

id_charset = eval(id_charset)

The idea is that the user can specify the list of admissible ID characters using a Python expression in the configuration file:

id_charset: 'string.ascii_letters + string.digits + ".-_~"'

This is unsafe since it allows executing arbitrary code (try specifying id_charset: 'import os; os.system("rm -rf /")' in the config file), and also somewhat unnecessary in my opinion. I would recommend just specifying the list of admissible characters directly:

id_charset: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_~'
@uniqueg
Copy link
Member

uniqueg commented Jun 20, 2024

Good point. Did you try and see what happens if you do id_charset: 'import os; os.system("rm -rf /")'? 🙃

My reasoning was that this config is only accessible to admins who are setting up apps. But you are right, why even create a possible attach vector if it's unnecessary. I guess we could use ast.literal_eval(), but I think your suggestion is actually more user-friendly (nobody knows/remembers the string sets in Python).

In any case, please note that the function is now part of FOCA and could/should be imported from there. I will fix it in FOCA - and then we can just import it here.

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

No branches or pull requests

2 participants