You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CSRF failure doesn't pass ActionData to enhanced form callback nor supplies form.error. #10464
I'm noticing odd behaviour when CSRF fails - when the form is submitted no error message is given.
I see the server is returning code 403 with {message: "Cross-site POST form submissions are forbidden"} which doesn't comply with ActionResult type in the enhance callback function and form.error isn't updated.
{#if form?.success}
<p class="success">Success</p>
{:else if form?.error}
<p class="error">{form.error}</p>
{/if}
I agree. We should update the object shape returned from the CSRF failure to align the ActionResult type.
As an aside, the $page.form store is only updated when returning an object from the action (or with the fail() helper). It does not update when the CSRF failure occurs (because of the weird object shape). https://kit.svelte.dev/docs/form-actions#anatomy-of-an-action
A hacky workaround for now since the result object shape is { message: string } :
<formmethod="POST"use:enhance={async ({ formData }) => {
returnasync ({ result, update }) => {
if (result?.message==="Cross-site POST form submissions are forbidden") {
result.data= {
error: "The submission failed"
};
}
awaitapplyAction(result);
};
}}
>
It would be best if the ActionResult also exposes the response object.
I have a very similar issue:
Infront of my sveltekit app sits a traefik proxy with a rateLimit middleware protecting form actions (POST endpoints).
When an IP hits the limit, the proxy returns a 429 Too Many Requests. Since this response doesn't conform to the shape of ActionResult, you cant get the status code of the response. So you're not really able to render a warning that the user cannot login for a couple of minutes (for example)
Activity
teemingc commentedon Aug 1, 2023
I agree. We should update the object shape returned from the CSRF failure to align the ActionResult type.
As an aside, the
$page.formstore is only updated when returning an object from the action (or with thefail()helper). It does not update when the CSRF failure occurs (because of the weird object shape).https://kit.svelte.dev/docs/form-actions#anatomy-of-an-action
A hacky workaround for now since the
resultobject shape is{ message: string }:https://stackblitz.com/edit/sveltejs-kit-template-default-rarbe5?file=src%2Froutes%2F%2Bpage.svelte
Blackwidow-sudo commentedon Jan 4, 2026
It would be best if the
ActionResultalso exposes the response object.I have a very similar issue:
Infront of my sveltekit app sits a traefik proxy with a rateLimit middleware protecting form actions (POST endpoints).
When an IP hits the limit, the proxy returns a
429 Too Many Requests. Since this response doesn't conform to the shape ofActionResult, you cant get the status code of the response. So you're not really able to render a warning that the user cannot login for a couple of minutes (for example)fix: render the nearest error page when a form submission receives a …