S3 CORS configuration: one guide for S3, R2, MinIO, B2 and Wasabi

by Opndrive14 min read
Title card with the post title: S3 CORS configuration, one guide for S3, R2, MinIO, B2 and Wasabi
On this page

Your browser app calls a bucket directly, and the console shows one generic CORS failure. The rule you pasted came from a guide written for another provider. Every provider that takes bucket rules uses the same five rule fields, but each takes them in a different place and shape, with its own limits and defaults.

Below are the five fields, where each provider takes them, console steps, one SDK program, and one curl test that reads the same way everywhere. We checked all five providers against their documentation only, and the self-hosted server against its source code too. Nothing here ran against a live bucket, so run the curl test before you rely on a rule.

In this guide:

What an S3 CORS configuration does

An S3 CORS configuration is a list of rules on a bucket, up to 100 on AWS. Each rule tells the browser which origins may call the bucket, with which methods and request headers, which response headers JavaScript may read, and how long to cache the answer. Before most uploads and signed calls, the browser checks the rules with an OPTIONS preflight.

The preflight carries Origin, Access-Control-Request-Method and, when the real request sends extra headers, Access-Control-Request-Headers (MDN). A header-signed SDK call carries Authorization, which forces a preflight. So does an upload with a Content-Type such as image/png or application/octet-stream, because only three form and text types are safelisted.

A preflight never carries credentials. That is why an unauthenticated curl request can imitate it faithfully.

How a preflight is answered, drawn from AWS and MDN documentation rather than a live capture. The bucket decides from its rules before the real request is sent, and no matching rule means no Access-Control-* headers.

A CORS rule grants no access. On AWS, ACLs and access policies still apply after you enable CORS, so the browser’s keys still need permission for each call. For that side, see the minimum IAM policy for a browser client.

The five fields every provider shares

Each field answers one part of the preflight. This mapping comes from AWS’s CORS elements page and MDN, not from a live capture:

The preflight sends The rule field The bucket answers with
Origin AllowedOrigins Access-Control-Allow-Origin
Access-Control-Request-Method AllowedMethods Access-Control-Allow-Methods
Access-Control-Request-Headers AllowedHeaders Access-Control-Allow-Headers
(nothing) ExposeHeaders Access-Control-Expose-Headers
(nothing) MaxAgeSeconds Access-Control-Max-Age

AllowedOrigins

Use the exact value the browser sends as Origin. Copy it from the request in your browser’s developer tools rather than typing it. AWS allows one * per origin string, such as http://*.example.com. R2 has the same one-wildcard limit, and there the wildcard can span periods. On both, a bare * matches every origin.

If the browser app is Opndrive, which runs in your browser and talks to the bucket directly, the origin is the address you open it at (Configure CORS). That app also needs POST and DELETE in AllowedMethods and ETag in ExposeHeaders, and the Configure CORS page gives a ready policy for each provider.

AllowedMethods

List the methods the real requests use, and nothing more. AWS’s valid values are GET, PUT, POST, DELETE and HEAD, so never list OPTIONS, and don’t use *. On S3-style APIs, multipart uploads and multi-object deletes use POST, so add it if the app does either.

AllowedHeaders

This field is matched against Access-Control-Request-Headers. On AWS, every requested header must match an entry, and each entry may hold one *, such as x-amz-*. Cloudflare’s R2 page asks you to list custom headers and does not say whether * is accepted, so list your headers there. MDN adds that a literal * in the response never covers Authorization; it has to be named.

ExposeHeaders

Browsers hide most response headers from JavaScript unless you expose them. Expose ETag, which a multipart upload reads for each part and which R2’s page gives as its example. Also expose any custom header the app reads, such as x-amz-meta-* (AWS).

MaxAgeSeconds

This is how long the browser may cache the preflight answer. Browsers cap it: Chromium at 2 hours and Firefox at 24 hours. A value above 7200 buys nothing in Chromium.

A starter rule

This is the console shape, a bare JSON array. The values are examples: replace the origin with yours, and the header list with the names your own preflight shows in Access-Control-Request-Headers.

JSON
[
  {
    "AllowedOrigins": ["https://app.example.com"],
    "AllowedMethods": ["GET", "PUT", "HEAD"],
    "AllowedHeaders": ["authorization", "content-type", "x-amz-date", "x-amz-content-sha256"],
    "ExposeHeaders": ["ETag"],
    "MaxAgeSeconds": 3600
  }
]

A signed SDK request carries at least authorization, x-amz-date and x-amz-content-sha256, and content-type covers the upload. The AWS SDK for JavaScript v3 can also send amz-sdk-invocation-id, amz-sdk-request, x-amz-user-agent and checksum headers such as x-amz-checksum-crc32 and x-amz-sdk-checksum-algorithm. Copy the names your own preflight shows. The 3600 sits inside B2’s range of 0 to 86400 and under Chromium’s cap.

Where each provider takes the rules, and what differs

The five fields are the same wherever a provider takes bucket rules; the place, the shape and the limits are not. MinIO Community takes only an origin list.

Provider Where you set it Format Limits Watch out for
Amazon S3 Console, or put-bucket-cors Console: JSON, a bare array. CLI and API: {"CORSRules": [...]} 100 rules, 64 KB, one * per origin First matching rule wins; a write replaces the old set
Cloudflare R2 Dashboard JSON tab, Wrangler, or S3 API Dashboard: bare array. Wrangler: a rules array of allowed objects (R2 docs) One * per origin; no rule limit stated * for headers not documented; up to 30 seconds to apply
Wasabi Console, or the S3 API JSON array of rule objects None stated Open by default; saving a rule replaces the default
Backblaze B2 S3 API PutBucketCors, or the native API and b2 CLI S3 API: the AWS format. Native: B2’s own Non-empty origin, max age 0 to 86400, 100 KB of XML; 100 rules Native rules list no POST; S3 API cannot see native rules
MinIO Community Server setting api cors_allow_origin One comma-separated origin list, default * n/a PutBucketCors returns NotImplemented; repository archived
MinIO AIStor mc cors set per bucket S3 CORS XML file 100 rules per bucket Bucket rules override the global list

Cloudflare R2: two formats for one policy

The dashboard’s JSON tab takes the bare array, like the S3 console. Wrangler takes a file with a top-level rules array, where each entry holds an allowed object. The R2 page’s Wrangler example shows only origins and methods inside it (example values):

JSON
{
  "rules": [
    {
      "allowed": {
        "origins": ["https://app.example.com"],
        "methods": ["GET", "PUT", "HEAD"]
      }
    }
  ]
}

The R2 CORS page shows no other keys. Cloudflare’s API reference for bucket CORS gives the schema: allowed holds methods, origins and headers, and each rule can also have exposeHeaders and maxAgeSeconds. Check them with npx wrangler r2 bucket cors list <BUCKET_NAME> after you apply the file. Apply the file with the Wrangler command:

Bash
npx wrangler r2 bucket cors set <BUCKET_NAME> --file cors.json

R2’s presigned-URL guidance names GET, PUT, HEAD and DELETE; POST appears only as an example value in the page’s field table, so test POST before you rely on multipart uploads. The same page asks you to list every header the client sends with a presigned URL.

Wasabi: open by default until you save a rule

With no configuration of its own, a Wasabi bucket answers with Access-Control-Allow-Origin: *, a literal Access-Control-Allow-Headers: * and Access-Control-Max-Age: 86400. Saving any configuration replaces that default, and deleting yours brings it back.

Wasabi says its implementation does not perform full CORS validation. Since a literal * never covers Authorization, run the curl test below with authorization in Access-Control-Request-Headers before you rely on the Wasabi default.

Backblaze B2: use the S3 API for POST

B2’s rules page lists four S3 operations for native rules: Delete, Get, Head and Put Object. None of them is POST. B2’s own PutBucketCors example includes POST, so set rules through the S3 API when the app needs it. Any S3 client that calls PutBucketCors works; the AWS CLI is one.

The two APIs do not see each other’s rules the same way: the native API shows rules set through the S3 API, but not the reverse. The S3 API cannot change native rules, and GetBucketCors does not return them, so an empty answer does not mean the bucket has no rules. Native rules can only be changed through B2’s native API or the b2 tool, using b2 bucket update --cors-rules. That command also takes the bucket type, allPublic or allPrivate, and Backblaze’s page warns that its example makes the bucket public, so pass the type the bucket already has (allPrivate for a private bucket).

MinIO: Community has one server-wide list

MinIO Community has no bucket CORS. In its source, PutBucketCors is a dummy handler that returns NotImplemented, and GetBucketCors always returns NoSuchCORSConfiguration, so that error proves nothing. The only setting is the server’s api cors_allow_origin, a comma-separated origin list that defaults to *.

Changes made with mc admin config apply without a restart; values set through environment variables are not dynamic. The repository was archived on 2026-04-25 and is no longer maintained, so this behavior is frozen. AIStor adds per-bucket rules that take precedence over the global setting.

For the exact commands and a MinIO preflight test, see how to fix CORS errors on a MinIO bucket.

Console steps for S3, R2 and Wasabi

Amazon S3

From AWS’s CORS configuration page:

  1. Open the Amazon S3 console. In the left navigation pane, choose General purpose buckets, then choose the name of your bucket.
  2. Choose Permissions. In the Cross-origin resource sharing (CORS) section, choose Edit.
  3. In the CORS configuration editor, paste the bare JSON array (no CORSRules wrapper), then choose Save changes.

Cloudflare R2

From Cloudflare’s R2 CORS page:

  1. In the Cloudflare dashboard, go to R2 object storage and select your bucket.
  2. Select Settings. Under CORS Policy, select Add CORS policy.
  3. On the JSON tab, paste the policy, then select Save. Allow up to 30 seconds before you test.

Wasabi

From Wasabi’s CORS page:

  1. On the Buckets list, click your bucket’s icon, then click Settings.
  2. Click the Permissions tab, click Cross-Origin Resource Sharing (CORS) at the bottom of the screen, then click Edit.
  3. Enter the configuration and click Save.

Wasabi’s console page names only methods, origins and exposed headers as rule properties, so check AllowedHeaders with the curl test after you save.

The Backblaze pages above set rules through B2’s APIs and the b2 tool, so for B2 use the next section. MinIO Community has no bucket rules to set.

Set the same rule from the command line or from code

From the command line

Wrap the starter rule as {"CORSRules": [ ... ]}, save it as cors.json, and apply it with the AWS CLI. Leave out --endpoint-url on AWS.

Bash
aws s3api put-bucket-cors --bucket <BUCKET> --cors-configuration file://cors.json --endpoint-url <ENDPOINT>

The command replaces any existing configuration, and B2’s PutBucketCors does the same. On R2 you can use Wrangler instead.

Provider <ENDPOINT> Notes
Cloudflare R2 https://<ACCOUNT_ID>.r2.cloudflarestorage.com Region auto (R2 S3 API)
Wasabi https://s3.<REGION>.wasabisys.com The region in the URL must be the bucket’s
Backblaze B2 https://s3.<REGION>.backblazeb2.com Sign in with the application key ID and key
Amazon S3 none Use the bucket’s own region

A working SDK example (JavaScript, AWS SDK v3)

Untested: built from the AWS SDK for JavaScript v3 documentation and its PutBucketCors example; not run against any provider. It reads the rules, writes the starter rule, and reads them back. Run npm i @aws-sdk/client-s3, fill in the <...> placeholders, save the file as cors.mjs, and run node cors.mjs with your keys in AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

JavaScript
// cors.mjs. Untested: built from the AWS SDK for JavaScript v3 documentation;
// not run against any provider.
import {
  S3Client,
  GetBucketCorsCommand,
  PutBucketCorsCommand,
  S3ServiceException,
} from "@aws-sdk/client-s3";

const ENDPOINT = "<ENDPOINT>"; // "" for AWS, otherwise a value from the endpoint table
const REGION = "<REGION>"; // "auto" for R2
const BUCKET = "<BUCKET>";
const ORIGIN = "<ORIGIN>"; // for example https://app.example.com

const client = new S3Client({
  region: REGION,
  ...(ENDPOINT ? { endpoint: ENDPOINT, forcePathStyle: true } : {}),
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  },
});

async function printRules(label) {
  try {
    const { CORSRules } = await client.send(
      new GetBucketCorsCommand({ Bucket: BUCKET }),
    );
    console.log(label, JSON.stringify(CORSRules, null, 2));
  } catch (caught) {
    // B2: rules set through the native API never appear here.
    // MinIO Community: this error always comes back, so it proves nothing.
    if (
      caught instanceof S3ServiceException &&
      caught.name === "NoSuchCORSConfiguration"
    ) {
      console.log(label, "no CORS configuration");
      return;
    }
    throw caught;
  }
}

async function main() {
  await printRules("Before:");

  // Replaces every existing rule, and on Wasabi the permissive default too.
  await client.send(
    new PutBucketCorsCommand({
      Bucket: BUCKET,
      CORSConfiguration: {
        CORSRules: [
          {
            AllowedOrigins: [ORIGIN],
            AllowedMethods: ["GET", "PUT", "HEAD"],
            AllowedHeaders: ["authorization", "content-type", "x-amz-date", "x-amz-content-sha256"],
            ExposeHeaders: ["ETag"],
            MaxAgeSeconds: 3600,
          },
        ],
      },
    }),
  );

  await printRules("After:");
}

try {
  await main();
} catch (caught) {
  if (caught instanceof S3ServiceException && caught.name === "NotImplemented") {
    console.error("This server has no bucket CORS (MinIO Community): set api cors_allow_origin instead.");
  } else if (caught instanceof S3ServiceException) {
    console.error(`${caught.name}: ${caught.message}`);
  } else {
    console.error(caught);
  }
  process.exitCode = 1;
}

Test the preflight with one curl command

AWS documents this test itself. The browser always sends Origin and curl does not, so add it by hand. No credentials are needed, because a preflight never carries them. Copy the URL the app calls from developer tools, so the host and path style match. The origin and headers below are example values.

Bash
curl -v -X OPTIONS "<OBJECT_URL>" \
  -H "Origin: https://app.example.com" \
  -H "Access-Control-Request-Method: PUT" \
  -H "Access-Control-Request-Headers: authorization,content-type"

Read the answer by its headers, the same way on every provider:

What comes back What it means
Access-Control-Allow-Origin is your origin or *, and Access-Control-Allow-Methods includes your method Origin and method matched
Access-Control-Allow-Headers names each header you asked for Headers matched. AWS returns the requested headers that are allowed
Access-Control-Allow-Headers: * Not an echo. Wasabi’s default sends this, and a literal * never covers Authorization
No Access-Control-* headers at all No rule matched. On AWS, one disallowed header removes them all

Status codes are documented only for AWS: 200 OK on a match, and a 403 with This CORS request is not allowed, or CORS is not enabled for this bucket when the bucket has no configuration. For R2, B2, Wasabi and MinIO the refusal status is not documented, so judge the test by the headers, not the status.

Run the command once per method the app uses, changing Access-Control-Request-Method each time. This matters most for POST on R2 and B2.

If curl passes but the browser still blocks the request

  • The browser cached the old preflight. Preflight answers live in a cache separate from the HTTP cache, kept for up to Access-Control-Max-Age within the browser caps. Wait for it to expire, then retry.
  • The provider hasn’t applied the change yet. R2 can take up to 30 seconds. On an R2 custom domain, use Cache Purge on the hostname after a CORS change.
  • A CDN or proxy cached an answer without CORS headers. Add the origin header to its cache key. A response that names a single origin should also send Vary: Origin.
  • JavaScript can’t read ETag, so finishing a multipart upload fails. Add ETag to ExposeHeaders.
  • The preflight passes but the upload fails with SignatureDoesNotMatch. That is a signing problem, not CORS: compare the signed and sent headers.

Try Opndrive

Opndrive gives any S3-compatible bucket a Drive-like web interface you host yourself.
See it on GitHub or read the docs.

Curious about Opndrive?

Take a look at our FAQ to learn more.

Opndrive

Ready to take control of your S3 storage?

Connect your S3 bucket in minutes and start managing your files with Opndrive's beautiful, modern interface.

Build Opndrive with us

Live demos, reviews on your PRs, and a hand when you get stuck.

Be an early member
Join our Discord