Skip to content

fix: refuse anything but a JSON body on /connect and its preview - #6

Merged
benclarkeio merged 1 commit into
mainfrom
fix/require-json
Nov 10, 2026
Merged

benclarkeio merged 1 commit into
mainfrom
fix/require-json

Conversation

@benclarkeio

Copy link
Copy Markdown
Contributor

Summary

The README says requiring application/json is what stops a form on another site from redeeming a link as whoever is signed in. But handleConnectRequest and handlePreviewRequest parsed whatever arrived. A <form enctype="text/plain"> can send a body that parses as JSON:

<form method="post" action="https://app.example.com/connect" enctype="text/plain">
  <input name='{"token":"ATTACKER_TOKEN","x":"' value='"}'>
</form>

That posts {"token":"ATTACKER_TOKEN","x":"="}. Whenever the visitor's session cookie went along, main answered 200 and redeemed the attacker's own Connect link as the signed-in customer, without the page or its preview ever being shown. A cookie with no SameSite attribute gets Chrome's two-minute Lax-by-default grace period on a POST, and a cookie set SameSite=None always goes. From then on, the attacker's Slack or Teams messages run as that customer.

  • Both handlers answer 415 to any other Content-Type, before reading the session or calling Agenta. application/json; charset=utf-8 is fine.
  • AGENTS.md makes it the third rule the endpoint must keep. Handlers written in a framework's own style (Express, Fastify, Koa) don't inherit the check. Fastify, for one, parses text/plain by default.
  • The README now says the header has to be checked, not the body.

Agenta's own /connect/link already does this (isJson, 415).

Reported by Codex.

Checks

  • On main, Codex's request reproduces: text/plain with {"token":"attacker-token","x":"="} gives 200, and Agenta receives {"linkToken":"attacker-token","customerId":"victim-customer"}. With this change it gets 415 and Agenta is never called.
  • 6 new tests cover text/plain, urlencoded and multipart on both handlers, checking 415, no session lookup and no Agenta call. They all fail on main. A seventh accepts JSON with a charset.
  • bun run check, bun run typecheck and bun test pass (26). Merged with fix: hold Connect until the preview answers, and stop calling every refusal expired #5 they still pass (43), and the two branches don't conflict.

Generated by Claude Code

The README says requiring `application/json` is what stops a form on
another site from redeeming a link as whoever is signed in, but the
handlers parsed whatever arrived. A `text/plain` form can send
`{"token":"…","x":"="}`, which parses as JSON, so a cross-site form
carrying the visitor's cookies redeemed the attacker's own token as
them, without the preview ever being shown.

- Both handlers answer 415 to any other Content-Type, before reading the
  session or calling Agenta. A charset parameter is fine
- AGENTS.md makes it a rule for handlers written in a framework's own
  style, which do not get the check from these ones
- README says the header is what has to be checked, not the body

Reported by Codex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013TYQ7D3Pk6WDSYuhCUvtGN
@benclarkeio
benclarkeio merged commit a3d1c86 into main Nov 10, 2026
3 checks passed
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