3 ms·
It's taking advantage of the presence of a "cycler" object in the template context which has an __init__ method that can be used to access globals, then builtin
by simonw 3mo ago
It's taking advantage of the presence of a "cycler" object in the template context which has an __init__ method that can be used to access globals, then builtins, then call the exec() function against a string of code.
Jinja doesn't promise to be secure out of the box (the text on their homepage is misleading: "Jinja doesn’t allow arbitrary Python code in templates" - what it means is that there isn't a documented way to drop code into a template like you might have with PHP) - there's a sandbox mode but it's not guaranteed either: https://jinja.palletsprojects.com/en/stable/sandbox/ https://jinja.palletsprojects.com/en/stable/sandbox/
Sandboxing in Python code is hard!
- codedokode 3mo agoJinja probably was not initially made with sandboxing in mind, and stuffing it after is complicated, so I would not rely on it.