Security: fix critical exec(), path traversal, and tool output injection#1424
Open
johnpippett wants to merge 1 commit into
Open
Security: fix critical exec(), path traversal, and tool output injection#1424johnpippett wants to merge 1 commit into
johnpippett wants to merge 1 commit into
Conversation
…paths, sanitize tool outputs - Restrict builtins in _tools_from_code() to mitigate arbitrary code execution via --functions exec() (Critical) - Enforce cwd containment in resolve_fragments() and resolve_attachment() to block path traversal (High) - Wrap tool_result.output in structural delimiters before injecting into OpenAI messages to reduce indirect prompt injection risk (High) - Update test_chat_fragments to use isolated filesystem relative paths
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.
This PR addresses three security findings identified in an audit of the simonw/llm repository:\n\n1. Critical – Arbitrary code execution via
--functions\n -llm/cli.py:_tools_from_code()usedexec(code_or_path, namespace)with no sandboxing.\n - Fix: Restrict available builtins to a safe subset (removesexec,eval,compile,__import__,open, etc.).\n\n2. High – Path traversal in fragment and attachment resolution\n -llm/cli.py:resolve_fragments()andresolve_attachment()accepted arbitrary filesystem paths.\n - Fix: Contain resolved paths to the current working directory usingpathlib.Path.relative_to().\n\n3. High – Indirect prompt injection via unsanitized tool outputs\n -llm/default_plugins/openai_models.py: Tool results were injected directly into OpenAI messages.\n - Fix: Wrap tool output in structural<tool_result>delimiters to provide a boundary against prompt injection.\n\nAll existing tests in the affected modules pass.