Bucket CORS policy
CORS (Cross-Origin Resource Sharing) is a feature that allows web applications running on a specific domain to access resources on another domain. By configuring a CORS policy for an Object Storage bucket, you can control responses so that only specific domains are allowed.
You can configure up to 10 CORS policies for a bucket. By default, the Origin in the CORS policy does not allow access from external domains.
CORS policy components
A CORS policy consists of origins, HTTP methods, request headers, response headers, and the preflight request cache duration.
If the detailed rules are not followed when setting a CORS policy, a 400 Bad Request error may occur.
Sequence of priority for CORS policy
When two or more CORS policies are entered and a request is received, policies are compared in the following order:
- Compare CORS policies in the order they were entered
- Check the policy for the first matching Origin in the CORS policy list
- Check
allowed_methodsandallowed_headersfor the first matching Origin and generate a response
Composition of policy details
The components of a CORS policy are as follows:
| Field | Description |
|---|---|
allowed_origins | Specifies the origins allowed for the bucket's CORS - Example: https://example.com |
allowed_methods | Specifies the HTTP methods allowed for CORS with the bucket - Access-Control-Allow-Methods is returned as a header value in response to a successful preflight request |
allowed_headers | Specifies the headers allowed for CORS with the bucket - Access-Control-Allow-Headers is returned as a header value in response to a successful preflight request |
expose_headers | Lists the header names exposed as part of the Access-Control-Expose-Headers response |
max_age_seconds | Cache duration, in seconds, for the preflight OPTIONS request response - Access-Control-Max-Age is returned as a header in response to a preflight request |
Detailed rules for each CORS component
Each CORS component must comply with specific rules.
allowed_origins
Specifies the origins allowed to access the resource. Required field.
- Case-sensitive
- Allows only one wildcard (*) per origin
- Valid:
console.*.kakao.io - Invalid:
*.*.kakao.io - Maximum length per origin: 200 characters
- Maximum of 10 origins per policy
- Allowed characters:
- Alphanumeric
- Colon (:)
- Forward slash (/)
- Dot (.)
- Wildcard (*)
- Cannot mix with disallowed characters
- Regex:
^[*a-zA-Z0-9:/.-]*$ - Max 10 entries per CORS object
allowed_methods
Specifies the allowed HTTP methods. Required field.
- Case-sensitive
- Only uppercase is valid; lowercase results in 400 Bad Request
- Allowed characters:
- Uppercase letters
- Wildcard (*)
- Cannot mix with disallowed characters
- Regex:
^[*A-Z]*$ - Duplicate entries are allowed
- Valid values:
GET,PUT,POST,DELETE,HEAD,* - If wildcard (
*) is entered, only the five methods listed above are applied - Max 5 methods per CORS object
allowed_headers
Specifies the request headers allowed in cross-origin requests. Required field.
- Case-sensitive
- Allows one wildcard (*)
- Max length per entry: 200 characters
- Allowed characters:
- Alphanumeric
- Dash (-)
- Wildcard (*)
- Cannot mix with disallowed characters
- Regex:
^[a-zA-Z\d-*]+$ - Max 10 entries per CORS object
expose_headers
Specifies additional response headers that browser scripts are allowed to read. Required field.
- Max length per entry: 200 characters
- Allowed characters:
- Alphanumeric
- Dash (-)
- Wildcard (*)
- Cannot mix with disallowed characters
- Regex:
^[a-zA-Z0-9*-]*$ - Max 10 entries per CORS object
- For headers like
x-account-meta-*,x-container-meta-*,x-object-meta-*, the exact meta name must be specified instead of using*
max_age_seconds
Indicates the cache duration for the preflight request result. Optional field.
- Enter the value in seconds
- Must be an integer greater than or equal to 0
- Max value: 86400 (1 day)
- Default: 0 if not specified
Configure bucket CORS policy
Follow the steps below to configure a CORS policy for a bucket in Object Storage.
Set new CORS policy
You can configure a new CORS policy for a bucket.
Only users with the storage admin role can configure CORS policies for individual buckets.
- Go to KakaoCloud console > Storage > Object Storage.
- Select the bucket from the General bucket menu.
- In Permission > CORS, click [Configure].
- Configure the CORS policy by writing it directly, loading a template, or loading an existing policy.
- Write directly
- Load template
- Load existing policy
Enter the CORS policy directly.
Load a template to automatically populate the JSON Editor with default code.
Edit the default code as needed. Using it as-is may result in unintended CORS behavior.
{
"cors": [
{
"allowed_origins": [
"http://example.com",
"http://example.com:8080",
"https://example.com",
"http://*.example.com"
],
"allowed_methods": [
"GET",
"HEAD"
],
"allowed_headers": [
"X-Auth-Token"
],
"expose_headers": [
"Access-Control-Allow-Origin"
],
"max_age_seconds": 0
}
]
}
Load a CORS policy currently used by another bucket. The policy used by the other bucket is automatically populated in the JSON Editor.
You need the storage.buckets.getIamPolicy permission to retrieve the other bucket's CORS policy.
Examples of bucket CORS policy
CORS policy configuration must be in JSON format and can include up to 10 policies. You can use a custom domain such as example1.com to serve content instead of accessing the website through an endpoint.
For details about policy configuration, see Configure bucket CORS policy.
The following CORS policy configuration example includes two CORS policy rules.
| Rule | Description |
|---|---|
| Rule 1 | - Allow cross-origin GET, HEAD, and PUT requests from the https://example.com and http://*.example.com Origins- Allow only X-Auth-Token for preflight OPTIONS requests through the Access-Control-Request-Headers header- Return the requested headers in response to preflight OPTIONS requests |
| Rule 2 | Allow cross-origin POST requests from all Origins- * (wildcard) means all Origins |
{
"cors": [
{
"allowed_origins": [
"https://example.com",
"http://*.example.com"
],
"allowed_methods": [
"GET",
"HEAD",
"PUT"
],
"allowed_headers": [
"X-Auth-Token"
],
"expose_headers": [
"Access-Control-Allow-Origin"
],
"max_age_seconds": 5
},
{
"allowed_origins": [
"*"
],
"allowed_methods": [
"POST"
],
"allowed_headers": [ ],
"expose_headers": [ ]
}
]
}
HTTP header list
The following HTTP headers are used in CORS requests and responses. For more information about HTTP headers, see the following documents.
| Header | Description |
|---|---|
| Accept | Request header listing MIME types the client can understand. Through content negotiation, the server selects a type and reports it in the Content-Type response header. Browsers set values based on the request context, such as loading a stylesheet, image, video, or script. |
| Accept-Ranges | Response header indicating support for partial requests. Its value specifies the units that can be used for ranges. |
| Content-Disposition | Indicates whether content is displayed inline as a page or part of a page, or downloaded and saved locally as an attachment. |
| Content-Encoding | Specifies additional content encodings applied to the body and tells the client how to decode it to obtain the media type identified by Content-Type. |
| Content-Length | Size of the message body in bytes. |
| Content-Range | Indicates the range of partial content |
| Content-Type | Media type of the resource |
| ETag | Response header identifying a specific resource version. It enables cache validation to save bandwidth when content is unchanged and helps prevent concurrent modifications from overwriting one another. |
| Expect | Indicates expectations from the server |
| Host | Request header specifying the host and port of the requested resource, derived from the original URI. |
| Last-Modified | Last modified date and time of the resource |
| Origin | Origin where a fetch request starts. It includes the server name without the full path and is sent with CORS requests and requests such as POST. Unlike Referer, it does not disclose the full path. |
| Range | Requests one or more portions of a resource. - The server returns 206 Partial Content for a partial response.- An invalid range returns 416 Range Not Satisfiable.- The server may ignore the Range header and return the entire resource with status 200. |
| Referer | Request header containing the absolute or partial address of the referring page. It identifies the page containing the link or using a resource from another domain. This information can support analytics, logging, and cache optimization. |
| Transfer-Encoding | Encoding for safely transmitting entity |
| X-Account-Meta-* | Account metadata. Requests store metadata on the account; responses return its metadata. |
| X-Auth-Token | Authentication token |
| X-Container-Bytes-Used | Total used bytes in container |
| X-Container-Meta-* | Container metadata. Requests store metadata on the container; responses return its metadata. |
| X-Container-Object-Count | Number of objects in container |
| X-Object-Manifest | Manifest for a dynamic large object. The value specifies the container and object-name prefix of its segments in container/prefix format. |
| X-Object-Meta-* | Object metadata. Requests store metadata on the object; responses return its metadata. |
| X-Openstack-Request-Id | Unique transaction ID for the request, equivalent to X-Trans-Id. The service provider may need this value when an issue is reported. |
| X-Static-Large-Object | Response header set to true when the object is a static large object manifest. |
| X-Subject-Token | Token returned after successful authentication. Set it in the X-Auth-Token request header to provide authentication information. |
| X-Timestamp | Date and time when the account, container, or object was first created in its current version, as a UNIX epoch timestamp. - Example: 1440619048 corresponds to August 26, 2015, 19:57:28 GMT |
| X-Trans-Id | Unique transaction ID for the request. The service provider may need this value when an issue is reported. |
| X-Trans-Id-Extra | Additional transaction information for debugging large object uploads and other Object Storage operations. - The server appends the first 32 characters of this request header to the transaction ID in the generated X-Trans-Id response header. - UTF-8 encode and then URL-encode the value before including it in the request header. - Use the same value when uploading each segment and the manifest. - If an error occurs, use this value to find all related requests in Object Storage logs, including requests for which no response was received. Operators can also search logs for this information. |