From 77e73d70a9b81a7bbd8e49be52612fc62a9f9502 Mon Sep 17 00:00:00 2001 From: Qrius Date: Tue, 6 May 2025 14:22:33 +0200 Subject: Disable unsafe code execution by default --- src/smp/macro_processor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/smp/macro_processor.py') diff --git a/src/smp/macro_processor.py b/src/smp/macro_processor.py index a473db4..d5f4e8e 100644 --- a/src/smp/macro_processor.py +++ b/src/smp/macro_processor.py @@ -76,6 +76,8 @@ class MacroProcessor: expansion_stack: list[Any] + unsafe_code_execution: bool = False + def __init__(self, prefix=""): self.macros = dict() self.macro_invocations = list() @@ -140,7 +142,7 @@ class MacroProcessor: return self.macros.get(f"{sub_prefix}{macro_name}", default) def _define_metadata(self, macro_name, macro_value): - sub_prefix = (self._get_macro_builtin("metadata_prefix")) + sub_prefix = self._get_macro_builtin("metadata_prefix") self.define_macro(f"{sub_prefix}{macro_name}", macro_value) def log_warning(self, message): @@ -351,7 +353,7 @@ class MacroProcessor: i += 1 continue - if c == "%" and peek == "(": + if self.unsafe_code_execution and c == "%" and peek == "(": state = ParserState.IN_CODE i += 2 state_start = i @@ -499,6 +501,8 @@ class MacroProcessor: elif state == ParserState.IN_CODE: if c == ")" and peek == "%": try: + if not self.unsafe_code_execution: + raise Exception("unsafe code execution now allowed!") self._enter_frame("inline_code", file, linenr, input) f = StringIO() with redirect_stdout(f): -- cgit v1.2.3