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
* remove urlencoded server action handling (#14)
* remove urlencoded server action handling
* urlencoded POSTs should still flow through action handler
* bailout early for urlencoded
* tweak handling to 404 in feetch action case
* error when there are no server actions (#15)
* remove custom error
* remove dev gate
* error when there are no server actions
* gate against dev
* Check whether action ids are valid before parsing (#16)
* Check whether action ids are valid before parsing
In an effort to narrow access to parsing methods Next.js now prequalifies MPA form parsing by ensuring there are only valid action IDs as part of the submission. This is not meant to be a strong line of defense against malicious payloads since action IDs are not private and are for many apps relatively easy to acquire. It does however provide some limited narrowing of code paths so that action decoding only happens for plausible actions
Additionally all other branches that use next-action header now consistently check the header before proceeding with parsing. This is also a perf improvement.
* fix test assertion
---------
Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
---------
Co-authored-by: Josh Story <story@hey.com>
Copy file name to clipboardExpand all lines: packages/next/errors.json
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -720,5 +720,8 @@
720
720
"719": "Failed to get source map for '%s'. This is a bug in Next.js",
721
721
"720": "Client Max Body Size must be a valid number (bytes) or filesize format string (e.g., \"5mb\")",
722
722
"721": "Client Max Body Size must be larger than 0 bytes",
723
-
"722": "Request body exceeded %s"
723
+
"722": "Request body exceeded %s",
724
+
"723": "Server Actions are not enabled for this application. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
725
+
"724": "Failed to find Server Action. This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
726
+
"725": "Failed to find Server Action%s. This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action"
// TODO: This can be from skew or manipulated input. We should handle this case
734
+
// more gracefully but this preserves the prior behavior where decodeAction would throw instead.
735
+
thrownewError(
736
+
`Failed to find Server Action. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action`
// TODO: This can be from skew or manipulated input. We should handle this case
935
+
// more gracefully but this preserves the prior behavior where decodeAction would throw instead.
936
+
thrownewError(
937
+
`Failed to find Server Action. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action`
938
+
)
939
+
}
940
+
941
+
// TODO: Refactor so it is harder to accidentally decode an action before you have validated that the
@@ -1178,10 +1206,121 @@ function getActionModIdOrError(
1178
1206
constactionModId=serverModuleMap[actionId]?.id
1179
1207
1180
1208
if(!actionModId){
1181
-
thrownewError(
1182
-
`Failed to find Server Action "${actionId}". This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action`
`Failed to find Server Action${actionId ? ` "${actionId}"` : ''}. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action`
1218
+
)
1219
+
}
1220
+
1221
+
const$ACTION_='$ACTION_'
1222
+
const$ACTION_REF_='$ACTION_REF_'
1223
+
const$ACTION_ID_='$ACTION_ID_'
1224
+
constACTION_ID_EXPECTED_LENGTH=42
1225
+
1226
+
/**
1227
+
* This function mirrors logic inside React's decodeAction and should be kept in sync with that.
1228
+
* It pre-parses the FormData to ensure that any action IDs referred to are actual action IDs for
1229
+
* this Next.js application.
1230
+
*/
1231
+
functionareAllActionIdsValid(
1232
+
mpaFormData: FormData,
1233
+
serverModuleMap: ServerModuleMap
1234
+
): boolean{
1235
+
lethasAtLeastOneAction=false
1236
+
// Before we attempt to decode the payload for a possible MPA action, assert that all
1237
+
// action IDs are valid IDs. If not we should disregard the payload
0 commit comments