T09 · Insecure Skill Coding Practices
- Location
scripts/form_engine.py:236- Finding
Unrestricted Jinja2 Template Rendering Enables Server-Side Template Injection
- Content
View full analysis
str: """Use a Jinja2 template to render the form.""" if template_str is None: template_str = self._default_template() template = Template(template_str) return template.render( form=self, fields=self.fields, name=self.name, description=self.description ) ``` ### Technical Analysis The `render` method compiles `template_str` directly with the unrestricted Jinja2 `Template` class. No sandbox, template allowlist, or trust-boundary enforcement is applied. The template context also exposes rich Python objects: - `form` references the complete `Form` instance. - `fields` contains `Field` instances. - Object attributes and methods are available to the template engine. Jinja2 templates are executable expressions rather than inert presentation data. If an untrusted party can influence `template_str`, the party may use object traversal to reach Python internals. In an unrestricted environment, this can potentially lead to local file access, disclosure of process data, or arbitrary command execution. The current examples use a hardcoded custom template, but the public method accepts any string and does not document or enforce that the template must be trusted. ### Attack Path 1. An application accepts a custom form template from a user, tenant, uploaded file, database record, or other untrusted source. 2. The application passes that content to `Form.render(template_str)`. 3. The method compiles the attacker-controlled content using unrestricted `jinja2.Template`. 4. The malicious template traverses exposed Python objects or their classes to reach sensitive runtime functionality. 5. The payload executes with the permissions and environment of the Pytho ...[truncated 890 chars]- Remediation
View remediation
