Skip to content

Commit 1ff1bda

Browse files
danthedeckiedecorator-factory
and
decorator-factory
committed
Fix escape via generators etc.
Yes - we need to do allow-lists not deny-lists... 2.0 Co-authored-by: decorator-factory <decorator-factory@protonmail.com>
1 parent 9c90b10 commit 1ff1bda

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: simpleeval.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
- kurtmckee (Kurt McKee) Infrastructure updates
6262
- edgarrmondragon (Edgar Ramírez-Mondragón) Address Python 3.12+ deprecation warnings
6363
- cedk (Cédric Krier) <ced@b2ck.com> Allow running tests with Werror
64+
- decorator-factory <decorator-factory@protonmail.com> More security fixes
6465
6566
-------------------------------------
6667
Basic Usage:
@@ -115,7 +116,16 @@
115116
MAX_SHIFT = 10000 # highest << or >> (lshift / rshift)
116117
MAX_SHIFT_BASE = int(sys.float_info.max) # highest on left side of << or >>
117118
DISALLOW_PREFIXES = ["_", "func_"]
118-
DISALLOW_METHODS = ["format", "format_map", "mro"]
119+
DISALLOW_METHODS = [
120+
"format",
121+
"format_map",
122+
"mro",
123+
"tb_frame",
124+
"gi_frame",
125+
"ag_frame",
126+
"cr_frame",
127+
"exec",
128+
]
119129

120130
# Disallow functions:
121131
# This, strictly speaking, is not necessary. These /should/ never be accessable anyway,

Diff for: test_simpleeval.py

+11
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,17 @@ def test_functions_are_disallowed_in_expressions(self):
12301230

12311231
simpleeval.DEFAULT_FUNCTIONS = DF.copy()
12321232

1233+
def test_breakout_via_generator(self):
1234+
# Thanks decorator-factory
1235+
class Foo:
1236+
def bar(self):
1237+
yield "Hello, world!"
1238+
1239+
evil = "foo.bar().gi_frame.f_globals['__builtins__'].exec('raise RuntimeError(\"Oh no\")')"
1240+
1241+
with self.assertRaises(FeatureNotAvailable):
1242+
simple_eval(evil, names={"foo": Foo()})
1243+
12331244

12341245
@unittest.skipIf(platform.python_implementation() == "PyPy", "GC set_debug not available in PyPy")
12351246
class TestReferenceCleanup(DRYTest):

0 commit comments

Comments
 (0)