Skip to content

Commit

Permalink
Merge pull request #149 from danthedeckie/more-restrictions
Browse files Browse the repository at this point in the history
Fix escape via generators etc.
danthedeckie authored Oct 4, 2024
2 parents 7d89e0e + 1ff1bda commit ccb584e
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion simpleeval.py
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@
- kurtmckee (Kurt McKee) Infrastructure updates
- edgarrmondragon (Edgar Ramírez-Mondragón) Address Python 3.12+ deprecation warnings
- cedk (Cédric Krier) <ced@b2ck.com> Allow running tests with Werror
- decorator-factory <decorator-factory@protonmail.com> More security fixes
-------------------------------------
Basic Usage:
@@ -115,7 +116,16 @@
MAX_SHIFT = 10000 # highest << or >> (lshift / rshift)
MAX_SHIFT_BASE = int(sys.float_info.max) # highest on left side of << or >>
DISALLOW_PREFIXES = ["_", "func_"]
DISALLOW_METHODS = ["format", "format_map", "mro"]
DISALLOW_METHODS = [
"format",
"format_map",
"mro",
"tb_frame",
"gi_frame",
"ag_frame",
"cr_frame",
"exec",
]

# Disallow functions:
# This, strictly speaking, is not necessary. These /should/ never be accessable anyway,
11 changes: 11 additions & 0 deletions test_simpleeval.py
Original file line number Diff line number Diff line change
@@ -1230,6 +1230,17 @@ def test_functions_are_disallowed_in_expressions(self):

simpleeval.DEFAULT_FUNCTIONS = DF.copy()

def test_breakout_via_generator(self):
# Thanks decorator-factory
class Foo:
def bar(self):
yield "Hello, world!"

Check warning on line 1237 in test_simpleeval.py

Codecov / codecov/patch

test_simpleeval.py#L1237

Added line #L1237 was not covered by tests

evil = "foo.bar().gi_frame.f_globals['__builtins__'].exec('raise RuntimeError(\"Oh no\")')"

with self.assertRaises(FeatureNotAvailable):
simple_eval(evil, names={"foo": Foo()})


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

0 comments on commit ccb584e

Please sign in to comment.