Skip to content

fix(security): 2 improvements across 2 files#6196

Open
tomaioo wants to merge 2 commits into
swarmauri:masterfrom
tomaioo:fix/security/unsafe-eval-in-chaincontextbase-resolve-
Open

fix(security): 2 improvements across 2 files#6196
tomaioo wants to merge 2 commits into
swarmauri:masterfrom
tomaioo:fix/security/unsafe-eval-in-chaincontextbase-resolve-

Conversation

@tomaioo

@tomaioo tomaioo commented May 24, 2026

Copy link
Copy Markdown

Summary

fix(security): 2 improvements across 2 files

Problem

Severity: Critical | File: pkgs/base/swarmauri_base/chains/ChainContextBase.py:L28

The _resolve_fstring method in ChainContextBase uses Python's eval() to resolve expressions within f-string templates. This is a critical security vulnerability as it allows arbitrary code execution if an attacker can control the template string or the context data. The eval() is called with empty globals but has access to self.context as locals, which could still be exploited for code injection.

Solution

Replace eval() with a safe expression parser such as ast.literal_eval() for simple expressions, or implement a restricted template engine using string.Template, Jinja2 with sandboxing, or a custom parser that only allows whitelisted operations. Never use eval() on untrusted input.

Changes

  • pkgs/base/swarmauri_base/chains/ChainContextBase.py (modified)
  • pkgs/base/swarmauri_base/prompt_templates/PromptTemplateBase.py (modified)

tomaioo added 2 commits May 24, 2026 11:36
- Security: Unsafe eval() in ChainContextBase._resolve_fstring
- Security: Missing input validation in PromptTemplateBase.fill() allows format string injection

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
- Security: Unsafe eval() in ChainContextBase._resolve_fstring
- Security: Missing input validation in PromptTemplateBase.fill() allows format string injection

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@tomaioo tomaioo requested a review from cobycloud as a code owner May 24, 2026 18:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02743b53c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +47 to +49
template = string.Template(self.template)
try:
return template.substitute(safe_vars)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep brace-style formatting in prompt template fill

Switching fill() to string.Template.substitute changes placeholder syntax from {name} to $name, but this codebase (for example pkgs/swarmauri_standard/tests/unit/prompt_templates/PromptTemplate_unit_test.py lines 25-26) and existing callers use brace-style templates. With the new implementation, templates like "Please find {number} items." are returned with {number} still present (and missing-variable errors for brace placeholders are no longer raised), so prompt rendering silently stops working for current templates.

Useful? React with 👍 / 👎.

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