Skip to content

Commit

Permalink
add MutableSequence.{clear,pop} to modifies_known_mutable check
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanscott authored and davidism committed Dec 19, 2024
1 parent 1dc04bc commit e421793
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Unreleased
objects. :issue:`2025`
- Fix `copy`/`pickle` support for the internal ``missing`` object.
:issue:`2027`
- Sandbox does not allow ``clear`` and ``pop`` on known mutable sequence
types. :issue:`2032`


Version 3.1.4
Expand Down
4 changes: 3 additions & 1 deletion src/jinja2/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
),
(
abc.MutableSequence,
frozenset(["append", "reverse", "insert", "sort", "extend", "remove"]),
frozenset(
["append", "clear", "pop", "reverse", "insert", "sort", "extend", "remove"]
),
),
(
deque,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def test_unsafe(self, env):
def test_immutable_environment(self, env):
env = ImmutableSandboxedEnvironment()
pytest.raises(SecurityError, env.from_string("{{ [].append(23) }}").render)
pytest.raises(SecurityError, env.from_string("{{ [].clear() }}").render)
pytest.raises(SecurityError, env.from_string("{{ [1].pop() }}").render)
pytest.raises(SecurityError, env.from_string("{{ {1:2}.clear() }}").render)

def test_restricted(self, env):
Expand Down

0 comments on commit e421793

Please sign in to comment.