Repository navigation
Block markerless execution-class tool-call promotion in Studio - #6967
danielhanchen wants to merge 58 commits into
Conversation
The markerless tool-call parsers promoted a bare call:NAME{...} and
NAME[ARGS]{json} found anywhere in assistant text into a real tool call,
gated only by whether NAME was an enabled tool. When the model quotes
attacker-controlled content (web, RAG, pasted text) shaped like one of
those, the safetensors, MLX and GGUF loops would execute it via
execute_tool, so prose could be turned into host code execution through
the python and terminal tools.
Real Gemma and Mistral calls carry an unambiguous wrapper
(<|tool_call>...<tool_call|>, [TOOL_CALLS]), but generation streams with
skip_special_tokens=True, which strips that wrapper before the parser
sees it and forces the bare-text fallback that cannot tell a real call
from a quote.
Never promote or strip a markerless execution-class call. Add a shared
EXECUTION_CLASS_TOOL_NAMES = {python, terminal} and a _markerless_promotable
helper in tool_healing, and route every markerless parse and strip path
through it: the bare Gemma call, the bare rehearsal name[ARGS]{...}, the
bare Llama-3.2 {"name":...} JSON, and the two leading-dispatch guards.
Trusted wrapped and structured forms (<|tool_call>, [TOOL_CALLS],
<function=>, and GGUF structured tool_calls) still promote python and
terminal normally, and benign bare tools are unchanged.
Existing tests that used python/terminal as placeholder names to exercise
parser mechanics are re-pointed to benign tools; add
test_markerless_exec_tool_guard.py plus loop-level cases proving a bare
execution call in prose never reaches execute_tool while the wrapped
forms still execute.
|
Confirmed this hits the markerless paths in studio/backend/core/inference/tool_call_parser.py where a bare call:python{...} is still promoted on the enabled-tool gate alone. The branch has conflicts now, so could you rebase and I will get this reviewed. |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53512cf491
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a122980db2
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
CI note: the two red jobs on this head are both pre-existing on main, not from this branch.
Both reproduce with the same counts on a worktree checked out at the merge base (6e21a68), so neither is caused by the diff here. The two failures this branch did introduce, the |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae7c972eff
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| name = _top_level_bare_json_name(probe) | ||
| blocked = _markerless_blocked_execution(name, enabled_tool_names) | ||
| if not blocked and not _markerless_promotable(name, enabled_tool_names): |
There was a problem hiding this comment.
Use the decoded JSON name for the strip guard
When a model emits duplicate top-level name keys, _top_level_bare_json_name returns the first value while _parse_llama3_bare_json uses json.loads, which keeps the last one. For {"name":"web_search","name":"terminal","arguments":{}}, the parser correctly blocks terminal, but this cleanup classifies the object as promotable web_search and deletes the entire assistant response; reversing the names executes web_search while preserving its raw serialization. Derive the guard name from the already decoded object (or reject duplicate keys) so parsing and cleanup make the same decision.
Useful? React with 👍 / 👎.
…arkerless-code-tools # Conflicts: # studio/backend/core/inference/inference.py # studio/backend/core/inference/mlx_inference.py # studio/backend/core/inference/tool_call_parser.py # studio/backend/core/tool_healing.py # studio/backend/tests/test_mlx_inference_backend.py
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca022edc14
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ``promotable_gemma_call_pos`` needs the ``{``, so a mid-prose call leaks ``call:web`` | ||
| first. STREAMING holds this tail as it holds a split ``NAME[ARGS]`` rehearsal; prose | ||
| releases it, and so does a closed call, whose boundary the signal scan already owns. |
There was a problem hiding this comment.
Rewind detection to the held Gemma opener
In the safetensors streaming path, a mid-prose bare Gemma call whose enabled tool name exceeds _TOOL_SIGNAL_OVERLAP (27 characters) leaks when the name and { arrive in separate snapshots. _tool_signal_scanned_upto advances while this helper withholds the partial tail, so the next _earliest_tool_signal scan starts after call: and misses the completed opener; once the body closes, this helper returns zero on the assumption that the signal scan owns it, causing the raw serialization to be emitted even though the end-of-turn parser subsequently executes it. Rewind detection to the start of the held tail, or make its overlap cover the full supported Gemma prefix.
Useful? React with 👍 / 👎.
|
Conflicts are resolved and the branch is current with Five files conflicted. Local run on the merged head: 1190 passed, 16 skipped across the guard, parser, streaming and per-backend loop suites. Also slimmed the comments across the nine touched source files in two passes, roughly 200 lines lighter, AST-verified comment-only both times so the code is byte-identical. Cleared the superseded review acks from the thread to make the open items easier to find. |
|
Superseded by #10507, which carries the identical tree from this branch's head Closing this one to keep the review on a single thread. The earlier rounds and their resolutions stay here for reference. |
Summary
Two HIGH-severity prompt-injection to RCE findings in Unsloth Studio.
The markerless tool-call parsers promoted a bare
call:NAME{...},NAME[ARGS]{json}or{"name":...}found anywhere in assistant text into a real tool call, gated only on whetherNAMEwas enabled. When the model quoted attacker-controlled content (web, RAG, pasted text) shaped like one of those, the safetensors, MLX and GGUF loops ran it throughexecute_tool->_bash_exec/_python_exec. The model never decided to call a tool; it echoed text shaped like one.Root cause: real Gemma, Mistral and Llama calls carry an unambiguous wrapper (
<|tool_call>,[TOOL_CALLS],<|python_tag|>), but generation streams withskip_special_tokens=True, which strips the wrapper before the parser sees it and forces a bare-text fallback that cannot tell a real call from a quote.Fix
1. Never promote a markerless execution-class call.
EXECUTION_CLASS_TOOL_NAMES(python,terminal,edit_file, plus everymcp__*) is always prose in the markerless paths, regardless of the enabled list. Such a call must carry a wrapper or arrive as a structuredtool_callsentry. New_markerless_promotable()incore/tool_healing.py; every markerless parse and strip path routes through it. Parse and strip stay symmetric, so a blocked call stays visible as text instead of silently vanishing.2. Stop destroying the wrapper.
NativeToolTokenDecoder(core/inference/native_tool_tokens.py) is a tokenizer proxy used on tool-enabled turns by the Transformers text and vision streamers and both MLX paths. It keeps the provenance-bearing controls (<tool_call>,[TOOL_CALLS],<|python_tag|>,<think>, DeepSeek and Kimi envelopes) and suppresses every other special token exactly as before. A tokenizer with no usableall_special_idsfalls back toskip_special_tokens=True, so (1) remains the security boundary and this is capability restoration only.Streaming: the safetensors and GGUF loops now treat a promotable bare Gemma call as a boundary and hold a trailing partial
call:NAME{.., so a blocked-then-promotable chain cannot leak before the parse decides.Impact
<|tool_call>,[TOOL_CALLS],<function=>, GGUF structuredtool_calls) still promotepythonandterminal; benign bare tools likeweb_searchstill work.python/terminal/edit_file/mcp__*call renders as text instead of executing. That is the fix. Wrapped and structured MCP calls are unaffected.Verification
python,edit_file,mcp__*) all reachexecute_tool; on this branch all six return no calls, while the wrapped, structured and benign-bare forms still execute.skip_special_tokens=Trueon every one. Onunsloth/Llama-3.2-1B-Instruct,<|python_tag|>was being stripped and is now preserved, which is the difference between a lost wrapped call and a promoted one.Qwen2.5-0.5B-Instruct,gemma-3-270m-it): streams byte-identical with and without the decoder for ordinary answers; a genuine<tool_call>-wrappedterminalcall still parses and strips cleanly.Status
Merged up to date with
main(the branch was 201 commits behind and is now conflict-free). CI is re-running on the merged head; any red job will be triaged againstmainbefore this is ready.