Summary
Trestle contains a server-side template injection vulnerability in custom Jinja2 Markdown inclusion tags. When an attacker controls Markdown or lookup-table content that Trestle renders, injected template expressions may execute operating system commands in the Trestle process.
Affected context
The vulnerability occurs in Trestle workflows that render attacker-influenced Markdown or YAML lookup-table values through the MDCleanInclude or MDSectionInclude Jinja2 tags. It is relevant when untrusted workspace content, third-party OSCAL documents, or other externally sourced data reaches these rendering paths and is reinterpreted as Jinja2 template source.
Exploit preconditions
- Attack surface: Trestle document-rendering workflows and custom Markdown inclusion tags
- Required access: Ability to influence Markdown content, an imported SSP document, or a YAML lookup-table value processed by Trestle
- Trigger point: Rendering content through MDCleanInclude or MDSectionInclude
- Why exploitation is possible: Untrusted content is parsed again as Jinja2 template code by a non-sandboxed environment, allowing template expressions to access Python internals and invoke process capabilities
Why this happens
The underlying bug is server-side template injection, mapped to CWE-94: Improper Control of Generation of Code. Trestle re-parses untrusted Markdown content as template source instead of treating it solely as data. Because the Jinja2 environment is not sandboxed, template evaluation can reach unsafe Python objects and operations, converting attacker-controlled content into executable behavior.
Potential impact
- Arbitrary operating system commands may execute with the privileges of the Trestle process
- Local files or compliance documents could be read, modified, or deleted
- Generated OSCAL output may be tampered with
- Credentials, tokens, or environment data could be exposed
- Build, automation, or document-processing systems could be compromised
General mitigation guidance
Mitigation generally focuses on preserving the boundary between document data and executable templates.
Common defensive patterns include:
- Treating included Markdown and lookup-table values strictly as data
- Avoiding second-pass template evaluation of untrusted content
- Using sandboxed or restricted template environments when templating is necessary
- Allowlisting permitted template constructs and accessible objects
- Applying strict schemas and validation to imported documents and lookup data
- Running document-processing jobs with least privilege and minimal filesystem and network access
- Restricting the provenance and mutability of workspace and third-party document inputs
How teams detect issues like this
Detection can focus on:
- Static analysis rules identifying non-sandboxed Jinja2 environments and dynamic template compilation
- Code review checks for template rendering or re-rendering of Markdown and YAML-derived values
- Searches for inclusion tags that pass user-controlled content into template parsers
- Policy enforcement requiring approved sandboxing, object allowlists, and input validation
- Runtime monitoring for unexpected child processes, shell activity, filesystem access, or network connections during document generation
- Automated security review tools that flag server-side template injection patterns

