CORS Configuration Reference
The CORS (Cross-Origin Resource Sharing) configuration is common across all services. This reference documents the configuration options for controlling cross-origin HTTP requests.
For a comprehensive understanding of CORS, see MDN's CORS documentation.
Configuration Schema
{
"cors": {
"enabled": boolean,
"allowHeaders": string[],
"allowMethods": string[],
"credentials": boolean,
"exposeHeaders": string[],
"maxAge": number,
"origin": string[]
}
}
Configuration Options
enabled
- Type:
boolean
- Default:
false
- Description: Controls whether CORS is enabled for the service
- Type:
string[]
- Default:
[]
- Description: List of non-standard HTTP headers that browsers are allowed to send
- Behavior:
- CORS-safelisted headers (always allowed):
Accept
Accept-Language
Content-Language
Content-Type
(with restrictions)
- See:
Example configuration:
{
"cors": {
"allowHeaders": ["Authorization", "X-Requested-With", "X-Custom-Header"]
}
}
Effect on response headers:
allowMethods
- Type:
string[]
- Default:
["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
- Description: HTTP methods allowed in CORS requests
- Allowed values: Based on HTTP/1.1 Method Definitions
Example configuration:
{
"cors": {
"allowMethods": ["GET", "POST", "OPTIONS"]
}
}
Effect on response headers:
credentials
Example configuration:
Note: When credentials
is true
, the Access-Control-Allow-Origin
header must be a specific origin (not *
), so origin
must be set accordingly.
{
"cors": {
"credentials": true,
"origin": ["https://app.example.com"]
}
}
Effect on response headers:
- Type:
string[]
- Default:
[]
- Description: Response headers that browsers are allowed to access
- Behavior:
- CORS-safelisted response headers (always exposed):
Cache-Control
Content-Language
Content-Length
Content-Type
Expires
Last-Modified
Pragma
- See:
Example configuration:
{
"cors": {
"exposeHeaders": ["X-Request-ID", "X-RateLimit-Limit", "X-RateLimit-Remaining", "X-RateLimit-Reset"]
}
}
Effect on response headers:
maxAge
- Type:
number
- Default:
86400
- Description: Duration in seconds browsers should cache CORS preflight responses
- Unit: Seconds
- Valid range:
0
to 86400
(24 hours)
- See: MDN: Access-Control-Max-Age
Example configuration:
{
"cors": {
"maxAge": 3600 // Cache preflight results for 1 hour
}
}
Effect on response headers:
origin
Example configuration with wildcard:
{
"cors": {
"origin": ["*"]
}
}
Effect on response headers:
Example configuration with specific origins:
{
"cors": {
"origin": ["https://app.example.com", "https://admin.example.com"]
}
}
Effect on response headers (varies based on request origin):
Default Configuration
{
"cors": {
"enabled": false,
"origin": ["*"],
"credentials": false,
"allowMethods": ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
"exposeHeaders": [],
"allowHeaders": [],
"maxAge": 86400
}
}
Additional Resources