fix(logic): harden formula eval against sandbox escape#66
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 754c857283
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ast.Call, | ||
| ast.Name, | ||
| ast.Load, | ||
| ast.Constant, | ||
| ast.List, |
There was a problem hiding this comment.
Permit keyword args in safe formula calls
The new AST allowlist rejects ast.keyword, so any formula that uses keyword arguments (for example round(x, ndigits=1) or min(a=..., b=...)) now fails with Disallowed expression element: keyword. This is a regression from previous behavior where such expressions evaluated successfully, and it can break already-saved formulas after this hardening change even though the called function is still from the allowed name set.
Useful? React with 👍 / 👎.
Upstream Tracking
Motivation
value_formulastrings from user-editable datapoint nodes were evaluated viaGraphExecutor._safe_evaland could be abused to escape the Python sandbox and execute arbitrary code via object introspection.__builtins__, which is insufficient to prevent attribute traversal and other Python constructs from reaching import or OS primitives.Description
GraphExecutor._validate_formula_astwhich inspects the parsed AST and rejects disallowed node types and constructs before evaluation._validate_formula_astfromGraphExecutor._safe_evalto enforce an allowlist of safe AST nodes and permitted names.tests/unit/test_executor.pyto assert that attribute-based sandbox escape payloads are blocked (replacing the previous attribute-access expectation).Testing
pytest -q tests/unit/test_executor.py, which completed successfully with193 passedand no failures.obs/logic/executor.pyandtests/unit/test_executor.pyand preserve existing executor behavior for allowed math expressions.Codex Task