Skip to main content

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.

info

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_methods and allowed_headers for the first matching Origin and generate a response

Composition of policy details

The components of a CORS policy are as follows:

FieldDescription
allowed_originsSpecifies the origins allowed for the bucket's CORS
- Example: https://example.com
allowed_methodsSpecifies 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_headersSpecifies 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_headersLists the header names exposed as part of the Access-Control-Expose-Headers response
max_age_secondsCache 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 headers allowed by the browser (default exposed). 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 the headers that are not exposed by default in the browser. 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.

info

Only users with the storage admin role can configure CORS policies for individual buckets.

  1. Go to KakaoCloud console > Storage > Object Storage.
  2. Select the bucket from the Standard bucket menu.
  3. In Permission > CORS, click [Configure].
  4. Configure the CORS policy by writing it directly, loading a template, or loading an existing policy.

Load a template to automatically populate the JSON Editor with default code.

info

Edit the default code as needed. Using it as-is may result in unintended CORS behavior.

Default code for loading template
{
"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
}
]
}

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.

RuleDescription
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 2Allow cross-origin POST requests from all Origins
- * (wildcard) means all Origins
Example of CORS policy configuration
{
"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.

HeaderDescription
AcceptSpecifies accepted MIME types for the client
Accept-RangesIndicates partial request support
Content-DispositionIndicates how content should be displayed (inline or attachment)
Content-EncodingSpecifies compression used
Content-LengthSize of response body in bytes
Content-RangeIndicates the range of partial content
Content-TypeMedia type of the resource
ETagIdentifier for a specific version of a resource
ExpectIndicates expectations from the server
HostSpecifies domain and port number
Last-ModifiedLast modified date and time of the resource
OriginIndicates where fetch request originated from
RangeRequests a specific portion of a resource
RefererSpecifies the source of the request
Transfer-EncodingEncoding for safely transmitting entity
X-Account-Meta-*Account-level metadata
X-Auth-TokenAuthentication token
X-Container-Bytes-UsedTotal used bytes in container
X-Container-Meta-*Container-level metadata
X-Container-Object-CountNumber of objects in container
X-Object-ManifestManifest for segmented large objects
X-Object-Meta-*Object-level metadata
X-Openstack-Request-IdUnique request transaction ID
X-Static-Large-ObjectIndicates static large object manifest
X-Subject-TokenToken returned upon successful authentication
X-TimestampUNIX epoch timestamp of object creation
X-Trans-IdUnique transaction ID
X-Trans-Id-ExtraExtra information for debugging large transactions