Skip to content

cors

The cors plugin controls cross-origin requests and handles preflight responses.

  • Phase: Access, Response
  • Purpose: Configure CORS headers for cross-origin requests
  • Behavior: Handles preflight requests and adds CORS headers
{
"pluginName": "cors",
"config": {
"origins": ["https://example.com", "https://app.example.com"],
"methods": ["GET", "POST", "PUT", "DELETE"],
"headers": ["Content-Type", "Authorization"],
"exposed_headers": ["X-Custom-Header"],
"credentials": true,
"max_age": 3600
}
}
OptionTypeDefaultDescription
originsstring[]["*"]Allowed origins
methodsstring[]Default HTTP verbsAllowed methods
headersstring[]Mirror request headersAllowed request headers
exposed_headersstring[][]Headers exposed to client
credentialsbooleanfalseAllow cookies/credentials
max_agenumber0Preflight cache duration (seconds)
private_networkbooleanfalseAllow private network access
preflight_continuebooleanfalseForward OPTIONS upstream

OPTIONS requests are handled automatically:

  1. Check origin against allowed list
  2. Verify requested method is allowed
  3. Return 204 with CORS headers

When origin is not in the allowed list, preflight returns 403.

When requested method is not in the allowed methods list.

Allow requests from public network to private network:

{
"private_network": true
}

Handles Access-Control-Request-Private-Network header.

To forward OPTIONS to backend instead of handling locally:

{
"preflight_continue": true
}

Use when backend needs to handle CORS itself.