Commit d7ef83d2 authored by Cursor Agent's avatar Cursor Agent

refactor: remove server actions env var, keep only allowedDevOrigins

Based on feedback, removing NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS as it's just a shorthand for existing config. Keeping only NEXT_ALLOWED_DEV_ORIGINS which is the main requirement for sandboxed environments.

- Remove NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS env var parsing
- Remove related tests for server actions env var
- Remove server actions env var documentation
- Keep only NEXT_ALLOWED_DEV_ORIGINS functionality
parent 05bce9de
......@@ -9,8 +9,6 @@ Options for configuring Server Actions behavior in your Next.js application.
A list of extra safe origin domains from which Server Actions can be invoked. Next.js compares the origin of a Server Action request with the host domain, ensuring they match to prevent CSRF attacks. If not provided, only the same origin is allowed.
### Configuration File
```js filename="next.config.js"
/** @type {import('next').NextConfig} */
......@@ -23,16 +21,6 @@ module.exports = {
}
```
### Environment Variable
You can also configure allowed origins using the `NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS` environment variable. This is useful for sandboxed or containerized environments where you don't want to modify the user's configuration file:
```bash
NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS="my-proxy.com,*.my-proxy.com" npm run dev
```
The environment variable accepts a comma-separated list of origins. Values from the environment variable are merged with any values specified in `next.config.js`, allowing both sources to work together.
## `bodySizeLimit`
By default, the maximum size of the request body sent to a Server Action is 1MB, to prevent the consumption of excessive server resources in parsing large amounts of data, as well as potential DDoS attacks.
......
......@@ -379,7 +379,7 @@ function assignDefaultsAndValidate(
},
}
// Parse and merge environment variables for allowed origins
// Parse and merge environment variables for allowed dev origins
if (process.env.NEXT_ALLOWED_DEV_ORIGINS) {
const envOrigins = process.env.NEXT_ALLOWED_DEV_ORIGINS.split(',')
.map((origin) => origin.trim())
......@@ -393,25 +393,6 @@ function assignDefaultsAndValidate(
}
}
// Parse and merge environment variables for server actions allowed origins
if (process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS) {
const envOrigins = process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS.split(
','
)
.map((origin) => origin.trim())
.filter(Boolean)
if (envOrigins.length > 0) {
if (!result.experimental.serverActions) {
result.experimental.serverActions = {}
}
result.experimental.serverActions.allowedOrigins = [
...(result.experimental.serverActions.allowedOrigins || []),
...envOrigins,
]
}
}
// ensure correct default is set for api-resolver revalidate handling
if (!result.experimental.trustHostHeader && ciEnvironment.hasNextSupport) {
result.experimental.trustHostHeader = true
......
......@@ -224,7 +224,7 @@ describe('config', () => {
})
})
describe('Environment variable support for allowed origins', () => {
describe('Environment variable support for allowedDevOrigins', () => {
it('Should merge NEXT_ALLOWED_DEV_ORIGINS with config allowedDevOrigins', async () => {
const originalEnv = process.env.NEXT_ALLOWED_DEV_ORIGINS
process.env.NEXT_ALLOWED_DEV_ORIGINS = 'example.com,*.test.com'
......@@ -286,55 +286,6 @@ describe('config', () => {
}
})
it('Should merge NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS with config', async () => {
const originalEnv = process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS
process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS = 'api.example.com'
try {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
experimental: {
serverActions: {
allowedOrigins: ['localhost'],
},
},
},
})
expect(config.experimental.serverActions?.allowedOrigins).toContain(
'localhost'
)
expect(config.experimental.serverActions?.allowedOrigins).toContain(
'api.example.com'
)
} finally {
if (originalEnv === undefined) {
delete process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS
} else {
process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS = originalEnv
}
}
})
it('Should create serverActions config from NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS when not set', async () => {
const originalEnv = process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS
process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS = 'api.example.com'
try {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {},
})
expect(config.experimental.serverActions?.allowedOrigins).toContain(
'api.example.com'
)
} finally {
if (originalEnv === undefined) {
delete process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS
} else {
process.env.NEXT_SERVER_ACTIONS_ALLOWED_ORIGINS = originalEnv
}
}
})
it('Should handle empty NEXT_ALLOWED_DEV_ORIGINS', async () => {
const originalEnv = process.env.NEXT_ALLOWED_DEV_ORIGINS
process.env.NEXT_ALLOWED_DEV_ORIGINS = ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment