{"id":2296,"cve":"CVE-2026-57170","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-57170\/","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":7.8,"published":"2026-08-26","owasp":"A03 Injection","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Insecure Parsing or Deserialization","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Server\u2011side template injection via non\u2011sandboxed Jinja2 include tags in Trestle.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-57170\/","description":"Compliance-trestle (Trestle) is a Python SDK and command-line tool for managing OSCAL compliance documents. In versions prior to 3.12.4 and 4.0.0 through 4.0.3, the custom Jinja2 include tags mdsection_include and md_clean_include re-parse the content of an included Markdown file as Jinja2 template code in a non-sandboxed environment, allowing server-side template injection that can lead to arbitrary code execution. The MDSectionInclude and MDCleanInclude tags in Trestle\/core\/jinja\/tags.py pass included file content to Parser(self.environment, ...).parse(), splicing it into the host template's compilation, and the environment is a plain jinja2.Environment rather than a SandboxedEnvironment, so any expressions in the file are evaluated with full access to the usual SSTI gadget chain. Because Trestle's Markdown writers emit OSCAL prose and component-description fields verbatim, applying delimiter neutralization only to parameter tables, attacker-controlled OSCAL data such as a control statement, part prose, or component description containing Jinja2 syntax flows into an included Markdown file and is executed when the include tag re-parses it. This issue is fixed in version 4.1.0.","solution":"Upgrade Trestle to version\u202f4.1.0 (or later).","affected_component":"Python","fixed_by_upgrading":true,"vulnerable_code":"import os\nfrom jinja2 import Environment, FileSystemLoader, nodes\nfrom jinja2.ext import Extension\n\nclass MDSectionInclude(Extension):\n    tags = {'mdsection_include'}\n\n    def parse(self, parser):\n        lineno = next(parser.stream).lineno\n        # VULNERABLE: parsing included markdown as full Jinja2 template\n        filename = parser.parse_expression()\n        with open(os.path.join(self.environment.loader.searchpath[0], filename), 'r') as f:\n            source = f.read()\n        # Re\u2011parse the included content as a template\n        return parser.parse_statement(source, lineno=lineno)\n\ndef render_template(template_name, context):\n    env = Environment(loader=FileSystemLoader('templates'))\n    env.add_extension(MDSectionInclude)\n    tmpl = env.get_template(template_name)\n    return tmpl.render(context)\n","patched_code":"import os\nfrom jinja2 import Environment, FileSystemLoader, nodes, sandbox\nfrom jinja2.ext import Extension\n\nclass MDSectionInclude(Extension):\n    tags = {'mdsection_include'}\n\n    def parse(self, parser):\n        lineno = next(parser.stream).lineno\n        # FIX: parse included markdown in sandboxed environment\n        filename = parser.parse_expression()\n        with open(os.path.join(self.environment.loader.searchpath[0], filename), 'r') as f:\n            source = f.read()\n        # Use SandboxedEnvironment to safely render the included content\n        sandbox_env = sandbox.SandboxedEnvironment(loader=self.environment.loader)\n        ast = sandbox_env.parse(source)\n        return nodes.Output([nodes.TemplateData(source)], lineno=lineno)\n\ndef render_template(template_name, context):\n    env = Environment(loader=FileSystemLoader('templates'))\n    env.add_extension(MDSectionInclude)\n    tmpl = env.get_template(template_name)\n    return tmpl.render(context)\n","payload_needed":true,"payload":null,"payload_status":"model_refused","published_fix":[{"repository":"oscal-compass\/compliance-trestle","commit_url":"https:\/\/github.com\/oscal-compass\/compliance-trestle\/commit\/0f82d19bd42f9cc0f1b3acd7fc3f6dafe3b6ae10","commit_subject":"Merge commit from fork","units":[{"file":"trestle\/core\/docs_control_writer.py","function":null},{"file":"trestle\/core\/docs_control_writer.py","function":"DocsControlWriter._add_one_section"},{"file":"trestle\/core\/docs_control_writer.py","function":"DocsControlWriter._write_part_info"},{"file":"trestle\/core\/jinja\/tags.py","function":null},{"file":"trestle\/core\/jinja\/tags.py","function":"MDCleanInclude.parse"},{"file":"trestle\/core\/jinja\/tags.py","function":"MDDatestamp.parse"},{"file":"trestle\/core\/jinja\/tags.py","function":"MDSectionInclude.parse"},{"file":"trestle\/core\/ssp_io.py","function":null},{"file":"trestle\/core\/ssp_io.py","function":"SSPMarkdownWriter._get_responses_by_components"},{"file":"trestle\/core\/ssp_io.py","function":"SSPMarkdownWriter._write_component_prompt"},{"file":"trestle\/core\/ssp_io.py","function":"SSPMarkdownWriter._write_str_with_header"}]},{"repository":"oscal-compass\/compliance-trestle","commit_url":"https:\/\/github.com\/oscal-compass\/compliance-trestle\/commit\/5335ff873a2a68eb7de43df029bea09cadff22fd","commit_subject":"fix: backport security and dependency fixes to v3","units":[{"file":"trestle\/common\/file_utils.py","function":"is_directory_name_allowed"},{"file":"trestle\/core\/commands\/author\/catalog.py","function":null},{"file":"trestle\/core\/commands\/author\/catalog.py","function":"CatalogGenerate._run"},{"file":"trestle\/core\/commands\/author\/headers.py","function":"Headers.validate"},{"file":"trestle\/core\/commands\/author\/jinja.py","function":null},{"file":"trestle\/core\/commands\/author\/jinja.py","function":"JinjaCmd._create_jinja_environment"},{"file":"trestle\/core\/commands\/author\/prof.py","function":null},{"file":"trestle\/core\/commands\/author\/prof.py","function":"ProfileGenerate._run"},{"file":"trestle\/core\/commands\/author\/ssp.py","function":null},{"file":"trestle\/core\/commands\/author\/ssp.py","function":"SSPGenerate._run"},{"file":"trestle\/core\/commands\/create.py","function":null},{"file":"trestle\/core\/commands\/create.py","function":"CreateCmd.create_object"},{"file":"trestle\/core\/commands\/replicate.py","function":null},{"file":"trestle\/core\/commands\/replicate.py","function":"ReplicateCmd.replicate_object"},{"file":"trestle\/core\/remote\/security.py","function":null},{"file":"trestle\/core\/remote\/security.py","function":"URLSecurityValidator.validate_url"},{"file":"trestle\/core\/remote\/security.py","function":"URLSecurityValidator._block_private_ip"},{"file":"trestle\/core\/remote\/security.py","function":"URLSecurityValidator._check_blocked_networks"},{"file":"trestle\/core\/remote\/security.py","function":"URLSecurityValidator._check_metadata_endpoints"},{"file":"trestle\/core\/remote\/security.py","function":"URLSecurityValidator._warn_private_ip"},{"file":"trestle\/transforms\/transformer_factory.py","function":null},{"file":"trestle\/transforms\/transformer_factory.py","function":"TransformerBase.get_timestamp"}]}],"references":null}