Skip to content

Remove builtins which iterate without calling _getiter_ - #337

Merged
icemac merged 3 commits into
masterfrom
remove-iterating-builtins
Nov 3, 2026
Merged

icemac merged 3 commits into
masterfrom
remove-iterating-builtins

Conversation

@icemac

@icemac icemac commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Remove bytes, sorted, tuple and zip from safe_builtins and document why reversed is not added: all of them iterate their argument in C, so the _getiter_ guard never runs. Confirmed with a refusing _getiter_: the comprehension is blocked while tuple(secret), sorted(secret) and [x for x in zip(secret)] return every element.

Refs #335, supersedes #336.

AccessControl.ZopeGuards already wraps zip. zopefoundation/AccessControl#174 added guarded_sorted and guarded_tuple, zopefoundation/AccessControl#175 lets them accept generators and zopefoundation/AccessControl#176 adds guarded_bytes. All of them should be released before this.

…not added

They iterate their argument in C, bypassing the _getiter_ guard.

Refs #335
@icemac icemac self-assigned this Nov 2, 2026
Comment thread docs/usage/security_considerations.rst Resolved
icemac added a commit to zopefoundation/AccessControl that referenced this pull request Nov 3, 2026
* Add guarded_sorted and guarded_tuple

RestrictedPython 8.6 removes the unguarded sorted and tuple from
safe_builtins, see zopefoundation/RestrictedPython#337.

* Make guarded_tuple a class so isinstance(x, tuple) keeps working
@icemac
icemac requested a review from dataflake November 3, 2026 07:29

@dataflake dataflake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes is important and should get a wrapper in AccessControl

icemac added a commit to zopefoundation/AccessControl that referenced this pull request Nov 3, 2026
RestrictedPython 8.6 removes the unguarded bytes from safe_builtins,
see zopefoundation/RestrictedPython#337.
@icemac
icemac merged commit 2953ef4 into master Nov 3, 2026
26 checks passed
@icemac
icemac deleted the remove-iterating-builtins branch November 3, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants