Repository navigation
fix(symbolic): prevent Python execution in expression parsing - #217
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SymbolicErrorwithout 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
mainat the maintainer's request for this security fix.Package(s) affected
gds-domainssymbolic implementation and testsgds-symboliccompatibility documentationType of change
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
gds-domainstests passed in the isolated branch checkout.git diff --checkpassed.parse_expr.The old
gds-symbolictest 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.