Skip to content

fix(symbolic): prevent Python execution in expression parsing - #217

Merged
rororowyourboat merged 2 commits into
mainfrom
fix/symbolic-expression-security
Oct 3, 2026
Merged

rororowyourboat merged 2 commits into
mainfrom
fix/symbolic-expression-security

Conversation

@rororowyourboat

Copy link
Copy Markdown
Member

Summary

Untrusted symbolic expression strings could execute Python while compiling ODEs, linearizing state/output equations, or deriving Hamiltonian dynamics and running costs. Replace SymPy's Python-evaluating string parser with a shared AST allowlist that constructs SymPy expressions directly. The reported import/call payload now raises SymbolicError without executing.

Validate symbol names, use dummy arguments during numerical code generation, and bound expression length, node count, nesting, and integer literal size. Document the supported grammar and clarify that these limits do not bound subsequent symbolic computations.

Targets main at the maintainer's request for this security fix.

Package(s) affected

  • gds-domains symbolic implementation and tests
  • gds-symbolic compatibility documentation
  • Symbolic documentation

Type of change

  • Bug fix
  • Breaking change
  • Documentation update

Unknown symbols, arbitrary Python/SymPy constructors, unsupported syntax, and invalid symbol names are now rejected when expressions are consumed. Supported arithmetic and approved mathematical functions remain available.

Validation

  • All 1,323 gds-domains tests passed in the isolated branch checkout.
  • Ruff lint and format checks passed for all changed Python files.
  • Shared parser type check and git diff --check passed.
  • Regression tests cover all five expression entry points, absence of payload side effects, JSON-loaded models, unsafe state/input/parameter names, supported math and differentiation, expression limits, compatibility-wrapper behavior, and prevention of regressions to parse_expr.

The old gds-symbolic test suite could not collect because it imports submodules no longer provided by the compatibility package. Its supported public API is covered directly. Repository-wide tests/lint and a documentation build were not run.

@rororowyourboat
rororowyourboat merged commit 65c7042 into main Oct 3, 2026
12 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