CVE-2026-54757: Trestle has Server-Side Template Injection (SSTI) via Recursive Template Re-evaluation of Untrusted Data
A Server-Side Template Injection (SSTI) vulnerability exists in multiple locations of trestle’s Jinja2 rendering pipeline due to a systemic pattern: untrusted data is re-parsed as Jinja2 template source code without sandboxing. This advisory tracks the root cause across all affected code paths.
The core anti-pattern is: treating runtime data (rendered output, included Markdown content, LUT values) as Jinja2 template source code and passing it to Parser.parse() or an equivalent rendering cycle, without using SandboxedEnvironment or escaping Jinja2 syntax delimiters. Because jinja2.Environment (not SandboxedEnvironment) is used, injected expressions can traverse Python object chains (__class__.__mro__, __globals__, __subclasses__()) to achieve arbitrary command execution via os.system() or subprocess.
Previously fixed instance (historical context):
An earlier version of render_template() in trestle/core/commands/author/jinja.py implemented a recursive while loop: rendered output was loaded via DictLoader into a new Environment and re-rendered until convergence. This allowed an attacker to inject {{ namespace.__init__.__globals__.os.system('command') }} into SSP data fields or LUT YAML values. When a trusted template rendered these data fields (e.g., Title: {{ ssp.metadata.title }}), the injected payload was written into the output, then re-evaluated as executable Jinja2 code in the next loop iteration. **This specific code path was fixed — render_template() now performs a single template.render(**lut) call.
Still-vulnerable code paths (this advisory):
MDCleanInclude.parse()—trestle/core/jinja/tags.py:148-151: Markdown file content is loaded viaFileSystemLoader.get_source(), then re-parsed as Jinja2 source viaParser(self.environment, content).parse().MDSectionInclude.parse()—trestle/core/jinja/tags.py:100-103: Extracted Markdown section text (md_section.content.raw_text) is re-parsed as Jinja2 source viaParser(self.environment, raw_text).parse().MDDatestamp.parse()—trestle/core/jinja/tags.py:198-201: Date string is re-parsed; lower risk because the date string is internally generated fromstrftime()rather than user input.
All three paths share the identical root cause: data that should be treated as plain text is passed to Parser.parse() and executed as Jinja2 code in an un-sandboxed Environment.
Attack vectors:
- Path A (Markdown include): Attacker places a malicious
.mdfile with embedded Jinja2 payload in the trestle workspace. When{% md_clean_include "malicious.md" %}or{% mdsection_include %}is processed, the payload executes. - Path B (Data field injection — SSP/LUT): Attacker crafts an SSP document or YAML LUT where a data field value (e.g.,
metadata.title) contains{{ namespace.__init__.__globals__.os.system('id') }}. When rendered into a trusted template, if the output subsequently flows through any re-parsing code path, the payload executes.
The same __globals__.os.system() RCE technique demonstrated in the previously-fixed render_template vulnerability applies to the remaining re-parsing paths.
References
- github.com/advisories/GHSA-jw39-3688-r4rx
- github.com/oscal-compass/compliance-trestle/commit/0f82d19bd42f9cc0f1b3acd7fc3f6dafe3b6ae10
- github.com/oscal-compass/compliance-trestle/commit/5335ff873a2a68eb7de43df029bea09cadff22fd
- github.com/oscal-compass/compliance-trestle/pull/2257
- github.com/oscal-compass/compliance-trestle/releases/tag/v3.12.4
- github.com/oscal-compass/compliance-trestle/releases/tag/v4.1.0
- github.com/oscal-compass/compliance-trestle/security/advisories/GHSA-jw39-3688-r4rx
- nvd.nist.gov/vuln/detail/CVE-2026-54757
Code Behaviors & Features
Detect and mitigate CVE-2026-54757 with GitLab Dependency Scanning
Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →