#18142·astro

Actions return 500 on a malformed JSON body or an undecodable action name

Author: skezoCreated Sep 26, 2026Updated Sep 26, 2026
Labelspkg: astro- P3: minor bugtriage: fix pending

Astro Info

block
Astro                    v7.3.5
Vite                     v8.3.1
Node                     v24.15.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

An action request with a malformed JSON body, or with an action name that can't be URL-decoded, returns a 500 instead of an action error. This happens on both the RPC route (/_actions/<name>) and the form action path (?_action=<name> on a page).

We noticed it in production from scanners, which post Content-Type: application/json with a body like a=b to form actions. Each request logs SyntaxError: Unexpected token 'a', "a=b" is not valid JSON and counts as a server error. A request to ?_action=%25 fails the same way with URIError: URI malformed.

Both errors escape from the action handler in getActionContext:

  • The parseRequestBody catch at runtime/server.ts#L204-L212 turns only ActionError and TypeError into an action error. JSON.parse and Request.json() throw a SyntaxError on a malformed body, so it gets rethrown.
  • The getAction catch at runtime/server.ts#L185-L198 turns only ActionNotFoundError into NOT_FOUND. The decodeURIComponent call at load.ts#L32 throws a URIError for a lone %, so that gets rethrown too.

A JSON body skips checkOrigin, so none of these requests need an Origin header.

For comparison, valid JSON sent to the same accept: 'form' action returns 415, and an unknown action name returns 404. Only the malformed cases leak out as a 500.

What's the expected result?

An action error, not a 500. For example, BAD_REQUEST for a malformed JSON body and NOT_FOUND for an action name that can't be decoded, the same answer an unknown name already gets.

I have a PR up with the fix and unit tests: #18141

Link to Minimal Reproducible Example

https://github.com/skezo/astro-actions-500

Participation

  • I am willing to submit a pull request for this issue.