fix(weblate): Server Side Template Injection on render_template `jinja2.sandbox`
https://github.com/WeblateOrg/weblate/blob/10ca938b5fe85a5fb9ada89483c84c5db8feb7a3/weblate/utils/render.py#L99-L99
Fix the issue render_template function should use a sandboxed environment for template rendering. Django's template system does not provide a built-in sandbox, but switching to Jinja2's SandboxedEnvironment can address this issue. The SandboxedEnvironment restricts access to unsafe methods and attributes, preventing remote code execution.
Steps to implement the fix:
- Import
SandboxedEnvironmentfromjinja2.sandbox. - Replace the
Templateconstructor withSandboxedEnvironment().from_string(template)in therender_templatefunction. - Ensure that the
kwargspassed to the template rendering are properly escaped to prevent cross-site scripting (XSS).
That's the purpose of the RestrictedEngine, did you spot any issue in its implementation? Furthermore, jinja2 is currently not a runtime dependency of Weblate.
This pull request has been automatically marked as stale because there wasn’t any recent activity.
It will be closed soon if no further action occurs.
Thank you for your contributions!