Skip to content

fix(citry-core): check functions passed to other functions in the sandbox; release citry-core 2.1.2 and citry 1.0.3 - #797

Merged
JuroOravec merged 6 commits into
mainfrom
fix/sandbox-callable-arguments
Nov 19, 2026
Merged

JuroOravec merged 6 commits into
mainfrom
fix/sandbox-callable-arguments

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

(Opus 5.5)

What changed

The template expression sandbox in citry-core checked the function an expression calls, but not a function passed as an argument to another function that then calls it (such as the key of list.sort). It also allowed reading a string's format method and refused only a direct call.

  • Reading or calling format and format_map on any string (str, UserString, Django lazy strings) now raises SecurityError.
  • A call now raises SecurityError when one of its arguments is a function the sandbox would not call itself: a method marked @unsafe or alters_data, an unsafe built-in, a string format method, or a functools.partial of one.
  • A validate_callable hook passed to safe_eval() now also receives every function and class passed as an argument.
  • Release values: citry-core 2.1.2, citry 1.0.3 pinning citry-core==2.1.2, changelogs and uv.lock.

The fix is Python only (citry_core/safe_eval/sandbox.py, eval.py), with 30 regression tests that fail without it.

Checks

Run on the fix before this rebase (only the release values commit is new):

  • cargo test -p python_safe_eval: 344 passed.
  • safe_eval Python tests: Python 3.11 649 passed (18 version-gated skips), 3.12 and 3.13 651 passed, 3.14 and 3.15 667 passed. Free-threaded 3.14: the same 7 t-string failures as without the fix.
  • citry: 15,157 passed with and without the fix; citry_ui: 0 failures.
  • ruff and mypy (also --platform linux) clean on the touched files.
  • Two independent security reviews found no way past the fix from template text, and a Mechanism 8 check against the advisory survey.

Versioning

A security fix that refuses expressions citry-core 2.1.1 ran, allowed under the security-fix clause; the changelog says what is refused and what to use instead (an f-string). citry 1.0.3 is a patch that raises the exact citry-core pin.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

JuroOravec and others added 6 commits November 19, 2026 01:08
…unction

Reading `format` or `format_map` from any string, exact `str` and
`UserString` included, is now refused, as it already was for subclasses.
A call is also refused when one of its arguments is a function the
sandbox would not call itself, because a function such as `list.sort`
calls its `key=` argument without the sandbox's call check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
…uments the check cannot read

Django's lazy strings are not `str`, but their `format` follows paths
too, so the read check now treats them as strings. An argument whose
own attribute lookup raises during the check is refused instead of
raising its own error. Prose fixes from the review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
… arguments

A function passed to a call can be called by the function that receives
it, so a caller's `validate_callable` hook must see it too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
…cause of a failed check

A bound `format` of a Django lazy string is named `__wrapper__`, so the
call check now also compares the function with the one on the class.
When checking an argument raises, the `SecurityError` keeps that error
as its cause. Changelog and docs follow the second review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
@JuroOravec
JuroOravec merged commit 523173c into main Nov 19, 2026
42 checks passed
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.

1 participant