Skip to content

Commit af2eb64

Browse files
authored
Restrict shell escape (!) when sandboxed (#108)
1 parent 6e42cb4 commit af2eb64

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

mathicsscript/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def fmt_fun(query: Any) -> Any:
233233

234234
except ShellEscapeException as e:
235235
source_code = e.line
236+
if not settings.ENABLE_SYSTEM_COMMANDS:
237+
shell.errmsg("System commands are disabled in sandboxed mode.")
238+
continue
236239
if len(source_code) and source_code[1] == "!":
237240
try:
238241
print(open(source_code[2:], "r").read())

mathicsscript/interrupt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def inspect_eval_loop(evaluation: Evaluation):
5454
query, source_code = evaluation.parse_feeder_returning_code(shell)
5555
# show_echo(source_code, evaluation)
5656
if len(source_code) and source_code[0] == "!" and shell is not None:
57+
if not settings.ENABLE_SYSTEM_COMMANDS:
58+
print("System commands are disabled in sandboxed mode.")
59+
continue
5760
subprocess.run(source_code[1:], shell=True)
5861
if shell.definitions is not None:
5962
shell.definitions.increment_line_no(1)

0 commit comments

Comments
 (0)