Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add body parser limit for server actions #51104

Merged
merged 23 commits into from Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8941247
feat: add body parser limit for server actions
devjiwonchoi Jun 10, 2023
bd5a4e2
chore: add validation for server actions in use
devjiwonchoi Jun 10, 2023
c69d44d
fix: fix validating serverActionsLimit as ternary
devjiwonchoi Jun 10, 2023
aaaaea3
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 10, 2023
f244f03
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 11, 2023
540a05f
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 12, 2023
e3d8323
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 12, 2023
38e7a37
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 13, 2023
b6bd10d
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 13, 2023
119afe3
refac: remove unnecessary condition
devjiwonchoi Jun 14, 2023
3cc4a47
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 15, 2023
710d810
chore: add serverActionsSizeLimit type to config-schema
devjiwonchoi Jun 15, 2023
d08d078
chore: move loadConfig to renderOpts
devjiwonchoi Jun 15, 2023
7e6c80d
Merge branch 'canary' into feat/server-actions-bodyparser-limit
devjiwonchoi Jun 15, 2023
aa9e0db
chore: add error case for serverActionsSizeLimit
devjiwonchoi Jun 15, 2023
b7daec8
chore: add fail test for invalid size limit config
devjiwonchoi Jun 15, 2023
7d918db
chore: modify test condition text
devjiwonchoi Jun 15, 2023
402e61c
chore: correct grammar of test condition text
devjiwonchoi Jun 15, 2023
8ce8a96
Merge branch 'canary' into feat/server-actions-bodyparser-limit
shuding Jun 23, 2023
915b9b9
avoid loading nextConfig again
shuding Jun 23, 2023
2e39afe
fix lint and early error
shuding Jun 23, 2023
351c20e
fix test
shuding Jun 23, 2023
cf79508
Merge branch 'canary' into feat/server-actions-bodyparser-limit
shuding Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/next/src/server/app-render/action-handler.ts
Expand Up @@ -17,12 +17,14 @@ import {
isRedirectError,
} from '../../client/components/redirect'
import RenderResult from '../render-result'
import loadConfig from '../config'
import { StaticGenerationStore } from '../../client/components/static-generation-async-storage'
import { FlightRenderResult } from './flight-render-result'
import { ActionResult } from './types'
import { ActionAsyncStorage } from '../../client/components/action-async-storage'
import { filterReqHeaders, forbiddenHeaders } from '../lib/server-ipc/utils'
import { appendMutableCookies } from '../web/spec-extension/adapters/request-cookies'
import { PHASE_PRODUCTION_SERVER } from '../../shared/lib/constants'

function nodeToWebReadableStream(nodeReadable: import('stream').Readable) {
if (process.env.NEXT_RUNTIME !== 'edge') {
Expand Down Expand Up @@ -352,7 +354,20 @@ export async function handleAction({
} else {
const { parseBody } =
require('../api-utils/node') as typeof import('../api-utils/node')
const actionData = (await parseBody(req, '1mb')) || ''

const nextConfig = await loadConfig(
PHASE_PRODUCTION_SERVER,
'/',
undefined,
undefined,
true
)
devjiwonchoi marked this conversation as resolved.
Show resolved Hide resolved

const serverActionsSizeLimit =
nextConfig.experimental?.serverActionsSizeLimit

const actionData =
(await parseBody(req, serverActionsSizeLimit ?? '1mb')) || ''

if (isURLEncodedAction) {
const formData = formDataFromSearchQueryString(actionData)
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/server/config-shared.ts
Expand Up @@ -9,6 +9,7 @@ import {
import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin'
import { WEB_VITALS } from '../shared/lib/utils'
import type { NextParsedUrlQuery } from './request-meta'
import { SizeLimit } from '../../types'

export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete>
Expand Down Expand Up @@ -281,6 +282,11 @@ export interface ExperimentalConfig {
* Enable `react@experimental` channel for the `app` directory.
*/
serverActions?: boolean

/**
* Allows adjusting body parser size limit for server actions.
*/
serverActionsSizeLimit?: SizeLimit
devjiwonchoi marked this conversation as resolved.
Show resolved Hide resolved
}

export type ExportPathMap = {
Expand Down