CORS Configuration
The cors plugin enables cross-origin resource sharing, allowing servers to specify permitted origins and instructing browsers to load resources from those origins, enhancing API accessibility. Configuration covers plugin parameters and plugin metadata.
Parameters
See plugin common configurations for configuration options available to all plugins.
allow_origins
Comma-separated string of origins to allow CORS.
If
allow_credentialis set totrue, you can forcefully allow CORS on all origins by configuring the field to**but sensitive data, such as authentication tokens or cookies, can get exposed to any malicious website.You can also configure allow origins on a global scale using the plugin metadata, which configures the allow origins for all
corsplugin instances. See the example for more details.allow_methods
Comma-separated string of HTTP request methods to allow CORS.
If
allow_credentialis set totrue, you can forcefully allow CORS on all methods by configuring the field to**, but a malicious actor can use HTTP methods, such asPUTorDELETE, to make unexpected modifications to shared resource and pose a security threat.allow_headers
Comma-separated string of HTTP headers allowed in requests.
If
allow_credentialis set totrue, you can forcefully allow CORS on all request headers by configuring the field to**, but it can potentially allow malicious headers to be sent to the server.expose_headers
Comma-separated string of HTTP headers that should be made available in response to a cross-origin request.
max_age
Maximum time in seconds for which the results of a preflight request can be cached. If the time is within this limit, the browser will check the cached result. To disable caching, set
max_ageto-1.Note that the maximum value allowed is browser-dependent. See
Access-Control-Max-Agefor more details.allow_credential
If true, allow requests to include credentials, such as cookies. According to CORS specification, when
allow_credentialis set to true, you cannot use*for other CORS attributes.To allow all origins, set the field to
**. This can potentially allow sensitive user data, such as authentication tokens or cookies, to be exposed to malicious actors.allow_origins_by_regex
Regular expressions used to match origins that allow CORS. When configured, these expressions replace literal matching through
allow_origins.If
allow_origins_by_metadatais also configured, named metadata origins are evaluated first. The regular expressions are used as a fallback only whenallow_originsis explicitly set to a value other than*.For example,
['.*\.test.com$']can match all subdomains oftest.com.allow_origins_by_metadata
Origins to enable CORS referenced from
allow_originsset in the plugin metadata. For example, ifallow_origins: {'EXAMPLE': 'https://example.com'}is set in the plugin metadata, then['EXAMPLE']can be used to allow CORS on the originhttps://example.com.Named metadata origins are evaluated before local origin settings. If none match, local literal or regular-expression matching is available only when
allow_originsis explicitly set to a value other than*.timing_allow_origins
Comma-separated string of origins to allow to access the resource timing information. See
Timing-Allow-Originfor more details.timing_allow_origins_by_regex
RegEx to match with origin for enabling access to the resource timing information. When configured, only domains matching the RegEx will be allowed and any configuration in
timing_allow_originswill be ignored.For example,
['.*\.test.com']can match all subdomain oftest.com.
Plugin Metadata
allow_origins
A map of named origins to allow for CORS, where each key is an identifier referenced by
allow_origins_by_metadataand each value is the corresponding origin string.For example,
{'EXAMPLE': 'https://example.com'}defines the keyEXAMPLEfor the originhttps://example.com.If
allow_credentialis set totrue, you can forcefully allow CORS on all origins by setting a map value to**, but sensitive data, such as authentication tokens or cookies, can get exposed to any malicious website.