Cross-Origin Resource Sharing
Function Description
The cors
plugin can enable CORS (Cross-Origin Resource Sharing) HTTP response headers for the server.
Execution Attributes
Plugin execution phase: Authorization Phase
Plugin execution priority: 340
Configuration Fields
Name | Data Type | Required | Default Value | Description |
---|---|---|---|---|
allow_origins | array of string | Optional | * | Allowed Origins for cross-origin access, formatted as scheme://host:port , for example, http://example.com:8081. When allow_credentials is false, * can be used to allow all Origins through. |
allow_origin_patterns | array of string | Optional | - | Patterns for matching allowed Origins for cross-origin access, using * to match domain or port, for example http://.example.com — matches domain, http://.example.com:[8080,9090] — matches domain and specified ports, http://.example.com:[] — matches domain and all ports. A single * indicates matching all domains and ports. |
allow_methods | array of string | Optional | GET, PUT, POST, DELETE, PATCH, OPTIONS | Allowed Methods for cross-origin access, for example: GET, POST, etc. * can be used to indicate all Methods are allowed. |
allow_headers | array of string | Optional | DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With, If-Modified-Since,Cache-Control,Content-Type,Authorization | Allowed Headers for the requester to carry that are not part of CORS specifications during cross-origin access. * can be used to indicate any Header is allowed. |
expose_headers | array of string | Optional | - | Allowed Headers for the responder to carry that are not part of CORS specifications during cross-origin access. * can be used to indicate any Header is allowed. |
allow_credentials | bool | Optional | false | Whether to allow the requester to carry credentials (e.g. Cookies) during cross-origin access. According to CORS specifications, if this option is set to true, * cannot be used for allow_origins, replace it with allow_origin_patterns. |
max_age | number | Optional | 86400 seconds | Maximum time for browsers to cache CORS results, in seconds. Within this time frame, browsers will reuse the previous inspection results. |
Note
- allow_credentials is a very sensitive option, please enable it with caution. Once enabled, allow_credentials and allow_origins cannot both be , if both are set, the allow_origins value of "" takes effect.
- allow_origins and allow_origin_patterns can be set simultaneously. First, check if allow_origins matches, then check if allow_origin_patterns matches.
- Illegal CORS requests will return HTTP status code 403, with the response body content as “Invalid CORS request”.