Set CORS Rules

Replace the cross-origin (CORS) configuration of a bucket you own.
EndpointMethodAdmin Required
/api/v1/buckets/:bucketName/corsPUTNo

Replaces the CORS rules of a bucket you own, overwriting the existing configuration entirely, like S3's PutBucketCors. To remove every rule use Delete CORS Rules - an empty rules array is rejected.

CORS rules decide which browser origins may call the S3-compatible API on this bucket: Alarik answers preflight OPTIONS requests and adds the Access-Control-* headers to S3 responses from the first rule that matches the request's origin, method and requested headers, in the order given. Without a configuration, browser requests to the bucket's S3 endpoints are refused by the browser. The rules are validated by the same code path as the S3 PUT ?cors subresource. They have no effect on this Internal API, whose CORS policy is fixed to the console's origin.

Path Parameters

bucketName
string required
The name of the bucket.

Request Body

rules
array required
One to 100 rules, evaluated in order. Each rule has the fields below.

Rule fields

id
string
Optional identifier, at most 255 characters. Blank is treated as absent.
allowedOrigins
string[] required
Origins allowed to make requests, e.g. https://app.example.com. At least one. Each value may contain a single * wildcard (https://*.example.com, or * alone).
allowedMethods
string[] required
HTTP methods allowed, from GET, PUT, HEAD, POST, DELETE. At least one. Values are upper-cased for you.
allowedHeaders
string[]
Request headers a preflight may ask for. Each value may contain a single * wildcard. A preflight whose requested headers are not all covered does not match the rule.
exposeHeaders
string[]
Response headers the browser may read (e.g. ETag, x-amz-version-id). No wildcards.
maxAgeSeconds
integer | null
How long the browser may cache the preflight answer. Must be 0 or greater when set.

Blank entries in any list are dropped before validation.

Example

{
    "rules": [
        {
            "id": "web-app",
            "allowedOrigins": ["https://app.example.com"],
            "allowedMethods": ["GET", "PUT"],
            "allowedHeaders": ["*"],
            "exposeHeaders": ["ETag"],
            "maxAgeSeconds": 3600
        }
    ]
}

Response

Returns the saved rules:

{
    "rules": [
        {
            "id": "web-app",
            "allowedOrigins": ["https://app.example.com"],
            "allowedMethods": ["GET", "PUT"],
            "allowedHeaders": ["*"],
            "exposeHeaders": ["ETag"],
            "maxAgeSeconds": 3600
        }
    ]
}

The new rules take effect on every node immediately.

Errors

StatusReason
400Missing bucket name; rules empty or more than 100; an id longer than 255 characters; a rule without origins or methods; a method outside GET/PUT/HEAD/POST/DELETE; an origin or header with more than one *; an expose header containing *; a negative maxAgeSeconds
404Bucket not found (or not owned by you)