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

Remote Code Execution over Server-Side Template Injection #549

Open
StevenMapes opened this issue Jun 28, 2024 · 0 comments
Open

Remote Code Execution over Server-Side Template Injection #549

StevenMapes opened this issue Jun 28, 2024 · 0 comments
Labels

Comments

@StevenMapes
Copy link

Describe the bug

The use of from jinja2 import Environment over from jinja2.sandbox import SandboxedEnvironment by default means that this package suffers from a Remote Code Execution (RCE) vulnerability through Server-Side Template Injection (SSTI) allowing an attacker to execute arbitrary code on the server by exploiting the template system used to render dynamic content. This vulnerability arises when a server allows untrusted data input into a template without proper validation or sanitization.

To Reproduce

Create a docx template file and add the following entry
{{ ''.__class__.__mro__[1].__subclasses__()[389](['id'], stdout=-1).communicate()[0].decode('utf-8') }}

{ get_flashed_messages.__class__.__mro__[1].__subclasses__()[90] }}

Expected behavior

A SecurityError should be raised.

Additional context

You can resolve this by passing the SandboxedEnvironment into the render method of the DocxTemplate class. By doing this Jinja2 will then raise a SecurityError but please consider swapping the default use of Environment over to use the Sandboxed one or add instructions and warnings to the project relating to this,

Jinja2 reference: https://jinja.palletsprojects.com/en/3.1.x/sandbox/#security-considerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant