Skip to content

fix(security): remove dangerous exec() in legacy function calling path#585

Open
ketan0095 wants to merge 1 commit intobolna-ai:masterfrom
ketan0095:fix/remove-exec-function-calling
Open

fix(security): remove dangerous exec() in legacy function calling path#585
ketan0095 wants to merge 1 commit intobolna-ai:masterfrom
ketan0095:fix/remove-exec-function-calling

Conversation

@ketan0095
Copy link
Copy Markdown

Summary

  • Removes compile() + exec() calls from the legacy string-template code path in function_calling_helpers.py
  • The exec was unnecessary — param % json_kwargs on the following line already produces the correct request_body
  • The exec posed a security risk if the template string or kwargs contained untrusted input (e.g., from LLM output)

What changed

Before (lines 90-92):

code = compile(param % json_kwargs, "<string>", "exec")
exec(code, globals(), json_kwargs)
request_body = param % json_kwargs

After:

request_body = param % json_kwargs

The new $var marker substitution system (already in the same function) is the recommended safe path. This just cleans up the legacy fallback.

Test plan

  • Verify existing function calling tests pass
  • Test legacy %(field)s style param templates still produce correct API payloads

Fixes #407

The legacy string-template code path used compile() + exec() to run the
formatted param string as Python code before using it as JSON. This is a
security risk if the template or kwargs contain untrusted input (e.g. from
LLM output). The exec call was also unnecessary — the string substitution
on the next line (param % json_kwargs) already produces the correct
request_body without executing anything.

The new $var marker system is already the recommended safe path. This
change just removes the exec from the legacy fallback.

Fixes bolna-ai#407
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.

Potential security concern: dynamic exec usage in function_calling_helpers.py

1 participant