Skip to content

Security: fix critical exec(), path traversal, and tool output injection#1424

Open
johnpippett wants to merge 1 commit into
simonw:mainfrom
johnpippett:security/critical-fixes-2026-04-28
Open

Security: fix critical exec(), path traversal, and tool output injection#1424
johnpippett wants to merge 1 commit into
simonw:mainfrom
johnpippett:security/critical-fixes-2026-04-28

Conversation

@johnpippett
Copy link
Copy Markdown

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() used exec(code_or_path, namespace) with no sandboxing.\n - Fix: Restrict available builtins to a safe subset (removes exec, eval, compile, __import__, open, etc.).\n\n2. High – Path traversal in fragment and attachment resolution\n - llm/cli.py: resolve_fragments() and resolve_attachment() accepted arbitrary filesystem paths.\n - Fix: Contain resolved paths to the current working directory using pathlib.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.

…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
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