Skip to content

fix: custom-tool injection, SOCKS5 open proxy, multipart body cap, example IP - #575

Merged
BaaRai merged 6 commits into
BaaRai:mainfrom
5P34R:fix/main-security-hardening
Nov 26, 2026
Merged

BaaRai merged 6 commits into
BaaRai:mainfrom
5P34R:fix/main-security-hardening

Conversation

@5P34R

@5P34R 5P34R commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Four security fixes for issues found on main during a review of the open PRs and a backdoor audit of the codebase. Each fix is a separate commit with its own test.

Problems and fixes

1. Custom-tool parameters could inject shell commands through each other (server/customtool.go)

renderTemplate replaced placeholders one parameter at a time. A value that contains another placeholder was therefore expanded a second time, inside the first value's shell quotes. Example: with a="{b}" and b="; id", cmd {a} {b} rendered as cmd ''; id'' '; id', which runs id. Whether it happened depended on map iteration order. Any caller that controls two parameters can trigger it, including a prompt-injected agent.

Fix: render the template in a single left-to-right pass that never rescans a substituted value. A { that does not start a known placeholder is copied as is, so {{a}}, unclosed braces and unknown names render the same as before.

This overlaps with #562, which fixes the same bug with a similar scanner. Merge only one of the two; they conflict in server/customtool.go.

2. The SOCKS5 listener was an open proxy to any non-loopback client (traffic/socks5.go)

No-auth (0x00) was accepted from loopback clients only. Username/password (0x02) was offered to every client and accepted any credentials, so a remote client got past the loopback rule just by offering 0x02. The listener is off by default and binds 127.0.0.1:1080, so this mattered only when ARTEX_SOCKS5_ADDR was set to a reachable address.

Fix: credentials are still not verified, because the username only carries the pace marker. Both methods are now accepted from loopback clients only, and any other client gets 0xFF (no acceptable methods). Loopback behaviour is unchanged, including the artex-pace marker. docs/traffic-socks5.md and docs/traffic-socks5-udp.md are updated.

Behaviour change: a non-loopback bind now accepts no remote clients. The docs already told operators to keep the listener on loopback.

3. Requests labelled multipart had no body cap (server/server_mgmt.go)

limitRequestBody skipped every request with a multipart Content-Type. About 30 handlers decode JSON straight from r.Body, and each of them read an unbounded body when the client simply labelled the request multipart.

Fix: multipart bodies now get an outer cap of maxMultipartBodyBytes, the largest limit any upload handler sets (chat attachments, 513 MiB). No real upload is refused, and a test checks that the constant still covers every upload handler. The body is wrapped with a plain MaxBytesReader, not limitedBody, so decode() still applies its 32 MiB JSON cap. Upload handlers keep their own tighter limits and error messages.

4. A real IP in a tool description shown to the model (traffic/traffic.go)

The traffic_search host-filter example used 107.172.96.177, a routable third-party address. It now uses 192.0.2.10 from TEST-NET-1 (RFC 5737), so the example cannot prime the agent toward that host.

Tests

  • TestRenderTemplateDoesNotExpandSubstitutedValues renders the same template 200 times so the map-order bug shows up reliably; it fails on main. TestRenderTemplateLiteralBraces pins the literal-brace behaviour.
  • TestSOCKS5NonLoopbackClientRefusedForEveryMethod fails on main for both offers that include 0x02. TestSOCKS5LoopbackClientStillAccepted covers IPv4 and IPv6 loopback, with and without the pace marker.
  • TestMultipartLabelDoesNotUncapTheBody and TestMultipartCapCoversEveryUploadHandler cover the new cap.
  • go build ./..., go vet ./server/ ./traffic/ and go test -p 1 ./server/ ./traffic/ all pass.

CHANGELOG entries are added under [Unreleased] / Fixed.

🤖 Generated with Claude Code

Username/password was offered to any client and accepted any credentials,
so a non-loopback client bypassed the loopback-only rule applied to no-auth
by offering method 0x02. Credentials are never verified, so both methods are
now accepted from loopback clients only; any other client gets 0xFF.
renderTemplate replaced placeholders param by param, so a value containing
another placeholder was expanded again inside the first value's shell
quotes: a="{b}", b="; id" rendered {a} as ''; id'' and ran id. Whether it
happened depended on map iteration order. Scan the template once and never
rescan substituted values.
limitRequestBody skipped every request with a multipart Content-Type, so
any handler decoding JSON straight from r.Body (about 30 of them) read an
unbounded body when the client simply labelled the request multipart.
Multipart bodies now get an upload-sized cap (the largest limit an upload
handler sets); upload handlers keep their own tighter limits and messages.
…example

The host filter description showed a real routable IP (107.172.96.177) to
the model as its example. Use 192.0.2.10 from TEST-NET-1 (RFC 5737) so the
example cannot prime the agent toward a third-party host.
BaaRai added a commit to Coff0xc/ARTEX-contrib that referenced this pull request Nov 26, 2026
@BaaRai
BaaRai force-pushed the fix/main-security-hardening branch from 19490e5 to f3daf0c Compare November 26, 2026 22:24
BaaRai added a commit to Coff0xc/ARTEX-contrib that referenced this pull request Nov 26, 2026
@BaaRai

BaaRai commented Nov 26, 2026

Copy link
Copy Markdown
Owner

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

@BaaRai
BaaRai force-pushed the fix/main-security-hardening branch from f3daf0c to d3b351e Compare November 26, 2026 22:39
@BaaRai
BaaRai force-pushed the fix/main-security-hardening branch from d3b351e to c5c3ecf Compare November 26, 2026 22:40
@BaaRai
BaaRai merged commit 21c678b into BaaRai:main Nov 26, 2026
6 checks passed
@BaaRai

BaaRai commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged, thanks @5P34R. 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.

2 participants