Skip to content

fix(server): substitute custom-tool placeholders once - #562

Merged
BaaRai merged 6 commits into
BaaRai:mainfrom
Coff0xc:fix/render-template
Nov 26, 2026
Merged

BaaRai merged 6 commits into
BaaRai:mainfrom
Coff0xc:fix/render-template

Conversation

@Coff0xc

@Coff0xc Coff0xc commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

renderTemplate applied each parameter with ReplaceAll on the string so far. Map order decided whether a value containing {other} was expanded again. After shell quoting, '{b}' could still turn into the next argument.

Each {name} is now taken from the original template. Inserted text is not scanned. An unknown placeholder stays as written. Command and HTTP custom tools both use this helper.

go test -count=1 -run TestRenderTemplate ./server/ passed.

renderTemplate walked the param map and replaced into the string so far,
so a value containing {other} could be expanded on a later key. Replace
each {name} in the original template only.
@5P34R

5P34R commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review notes

Recommendation: merge this one first. On main it's a real shell injection, not just a cleanup.

  • I confirmed the bug on main. With a="{b}" and b="; id", cmd {a} {b} renders as cmd ''; id'' ... whenever a is replaced before b. That breaks out of the quoting and runs id. Anything that controls two parameters can trigger it, including a prompt-injected agent.
  • The single-pass scanner handles {{a}}, unclosed {, and unknown placeholders the same way as before. The only edge case is a parameter name that contains }, which no longer matches. That doesn't matter in practice.
  • The new test fails on main only about half the time, because it depends on map order. Rendering in a loop (e.g. 200 iterations) would make it fail every time.

Heads-up: #575 fixes the same bug with an equivalent scanner. Only one of the two should land, since they conflict in server/customtool.go.

@BaaRai
BaaRai force-pushed the fix/render-template branch from 38860a3 to aadd77f Compare November 26, 2026 22:24
BaaRai added a commit to Coff0xc/ARTEX-contrib that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai merged commit ad27d1d into BaaRai:main Nov 26, 2026
6 checks passed
@BaaRai

BaaRai commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged, thanks @Coff0xc. Rebased on current main and verified with its tests and negative control.

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.

3 participants