MORTIMERDEV GUIDES / AWS S3

Why your S3 CORS request is blocked, and how to fix it

8 minute read Updated Sources checked 1 December 2026

Short answer: the browser only lets your page read a response from S3 if S3 sends back CORS headers that allow your page's origin. S3 sends them only when one of the bucket's CORS rules matches the request: the page's origin, the method and, for a preflight, every non-safelisted header your script sets. S3 uses the first rule that matches. If none does, S3 sends no CORS headers and the browser blocks the response. Usually the fix is in the rule, and remember that CORS never grants access to the bucket: that's still up to the bucket policy or a presigned URL.

What the error looks like

In Chrome's console, a blocked request to S3 usually shows one of these:

  • No 'Access-Control-Allow-Origin' header is present on the requested resource. S3's response had no CORS headers. Either no rule matched, the bucket has no CORS configuration, or something in front of S3 got in the way: CloudFront not forwarding Origin, or a cached response without CORS headers (see below).
  • Response to preflight request doesn't pass access control check: followed by a reason. The browser asked first with an OPTIONS request and the answer didn't allow the real request, so the real request was never sent. When S3 rejects a preflight, the reason is usually the same "No 'Access-Control-Allow-Origin' header" text. "It does not have HTTP ok status" means CORS headers came back but the status wasn't 2xx, which points at something other than S3's CORS rules, such as CloudFront not allowing OPTIONS.

Chrome may also log the request with its status (for example net::ERR_FAILED 403), but the CORS message doesn't include S3's error body or headers. Open the Network tab or test with curl to see them.

Test it with curl

S3 matches rules against the request's Origin header. Browsers add it to cross-origin requests; curl doesn't, so a curl test without it shows no CORS headers even when the configuration is right. Send the headers the browser would. -D - prints the response headers of a real GET. Don't use curl -I: it sends a HEAD, and S3 checks HEAD against AllowedMethods separately.

curl -s -o /dev/null -D - -H "Origin: https://app.example.com" \
  https://amzn-s3-demo-bucket.s3.eu-west-2.amazonaws.com/photo.jpg
curl -i -X OPTIONS \
  -H "Origin: https://app.example.com" \
  -H "Access-Control-Request-Method: PUT" \
  -H "Access-Control-Request-Headers: content-type" \
  https://amzn-s3-demo-bucket.s3.eu-west-2.amazonaws.com/photo.jpg

If a rule matches, the response includes Access-Control-Allow-Origin and, for the preflight, Access-Control-Allow-Methods. AWS documents a 403 Forbidden with "This CORS request is not allowed" when no rule matches, and "CORS is not enabled for this bucket" when there's no CORS configuration. You'll normally see those on the preflight test. AWS doesn't say what a simple GET gets; in practice it's usually the object with no CORS headers.

How S3 picks a rule

A CORS configuration is a list of rules. S3 checks them in order and uses the first one where all of these hold:

CheckWhat must match
OriginThe Origin header matches one of AllowedOrigins
MethodThe method (for a preflight, Access-Control-Request-Method) is one of AllowedMethods
HeadersFor a preflight only, every header in Access-Control-Request-Headers matches an AllowedHeaders

Later rules are ignored, even if they'd match too. That matters for ExposeHeaders and MaxAgeSeconds, which come from whichever rule S3 used. Put specific rules before catch-all ones.

Why the preflight fails

The browser sends an OPTIONS preflight before any request that isn't "simple". Roughly, a request is simple only if it's a GET, HEAD or POST and every header your script sets is on the Fetch standard's safelist, with short values. Content-Type is only safelisted for application/x-www-form-urlencoded, multipart/form-data and text/plain. So all of these trigger a preflight:

  • a PUT or DELETE (an upload to a presigned URL, for example);
  • Content-Type: application/json or image/png;
  • an Authorization header, or any x-amz-* header your script sets.

For the preflight, S3 checks the method the browser asks about and every requested header. This rule allows content-type but not authorization, so a PUT that sets both is blocked:

[
  {
    "AllowedHeaders": ["content-type"],
    "AllowedMethods": ["GET", "PUT"],
    "AllowedOrigins": ["https://app.example.com"]
  }
]

Add the header to AllowedHeaders (or a pattern such as x-amz-*), or stop sending it if you don't need it. Each value can contain at most one *, and a single * allows any header. Header names in Access-Control-Request-Headers are lower case.

Don't add OPTIONS to AllowedMethods: S3 only accepts GET, PUT, POST, DELETE and HEAD, and answers preflights itself using the method the browser asks about. PATCH isn't allowed either.

Mistakes that look right

AWS doesn't spell out how S3 compares origins, so most of these follow from how browsers write the Origin header: scheme, host and port, nothing else.

MistakeWhy it fails
https://www.example.com/ in AllowedOriginsBrowsers send the origin with no trailing slash, so it never matches
https://*.example.com for the apex domainThe text around the * must be there, so it doesn't match https://example.com. Add both
http:// instead of https://, or no portThe origin is scheme, host and port. http://localhost:3000 is not http://localhost
https://*.*.example.comAWS allows only one * per origin
A catch-all rule firstS3 uses it and ignores the more specific rule below, including its ExposeHeaders
Testing with curl and no Origin, or -INo Origin, no CORS headers; -I tests HEAD, not GET. The configuration may be fine

Your script can't read ETag

The request works, but response.headers.get("ETag") returns null. Browsers only let scripts read a short list of response headers: Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified and Pragma. Anything else has to be listed in the rule's ExposeHeaders, which S3 sends as Access-Control-Expose-Headers. Browser multipart uploads need it, because completing the upload means sending back each part's ETag. The same goes for x-amz-version-id if your script reads it.

Cookies and credentials

A request sent with credentials (fetch(url, { credentials: "include" }), or an image with crossorigin="use-credentials") needs the response to name your exact origin and include Access-Control-Allow-Credentials: true. Browsers reject Access-Control-Allow-Origin: * on such requests. S3 has no credentials setting in a CORS rule; when a specific origin matches, AWS's example response shows S3 sending Access-Control-Allow-Credentials: true itself. AWS doesn't document the value S3 sends for an AllowedOrigins of *, but it's commonly observed to be *, so list your origins explicitly when credentials are involved. Presigned URLs carry their authorisation in the URL and don't need cookies, so * works for them.

CORS isn't permission

CORS only decides whether a browser lets your page read a response. It doesn't let anyone into the bucket, and servers, server-side scripts and curl ignore it completely. A request that passes CORS still needs permission: a bucket policy, a presigned URL, or CloudFront with origin access control. S3's CORS failures are 403s with an XML body too, so look at the error code: <Code>AccessDenied</Code> means permissions, not CORS.

Behind CloudFront

When the bucket sits behind CloudFront, S3 only sees the headers CloudFront forwards. If CloudFront doesn't forward Origin, S3 sees a request with no Origin, applies no rule and sends no CORS headers, however good the configuration is. For S3's CORS rules to work through CloudFront:

  1. Forward the CORS headers: Origin, Access-Control-Request-Headers and Access-Control-Request-Method. The managed CORS-S3Origin origin request policy forwards exactly these three.
  2. Allow OPTIONS on the cache behavior, or preflights never reach S3. The console and CDK default is GET and HEAD only.
  3. Put Origin in the cache key with a cache policy. Otherwise a response cached for a request with no Origin (with no CORS headers) can be served to a CORS request, or one cached for one origin served to another. If you cache OPTIONS responses, add Access-Control-Request-Headers and Access-Control-Request-Method too, since S3's answer depends on them.

The alternative is to let CloudFront add the CORS headers itself with a response headers policy. You still need to allow OPTIONS on the behavior, so test the preflight through CloudFront with curl either way. The CloudFront policy builder sets up both.

Caching the preflight

MaxAgeSeconds sets Access-Control-Max-Age: how long the browser may reuse a preflight result before asking again. Browsers cap it, so a very large value doesn't help, and it only saves preflights, not the request itself. While you're fixing a rule, a cached preflight can make an old result stick: disable the cache in DevTools or wait it out.

S3 also sends Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method, so browsers and HTTP caches that honour Vary keep separate copies for different origins and preflights. CloudFront doesn't: it uses its cache policy's cache key instead (see above).

A rule that works

This configuration lets https://app.example.com read and upload with a Content-Type header and read each upload's ETag, and lets any site make GET and HEAD requests for objects it can already reach, such as through a presigned URL. The specific rule comes first:

[
  {
    "AllowedHeaders": ["content-type"],
    "AllowedMethods": ["GET", "PUT"],
    "AllowedOrigins": ["https://app.example.com"],
    "ExposeHeaders": ["ETag"],
    "MaxAgeSeconds": 3000
  },
  {
    "AllowedMethods": ["GET", "HEAD"],
    "AllowedOrigins": ["*"]
  }
]

The same in CDK:

new s3.Bucket(this, "Bucket", {
  blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
  enforceSSL: true,
  cors: [
    {
      allowedOrigins: ["https://app.example.com"],
      allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.PUT],
      allowedHeaders: ["content-type"],
      exposedHeaders: ["ETag"],
      maxAge: 3000,
    },
    {
      allowedOrigins: ["*"],
      allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.HEAD],
    },
  ],
});
        s3.Bucket(
            self, "Bucket",
            block_public_access=s3.BlockPublicAccess.BLOCK_ALL,
            enforce_ssl=True,
            cors=[
                s3.CorsRule(
                    allowed_origins=["https://app.example.com"],
                    allowed_methods=[s3.HttpMethods.GET, s3.HttpMethods.PUT],
                    allowed_headers=["content-type"],
                    exposed_headers=["ETag"],
                    max_age=3000,
                ),
                s3.CorsRule(
                    allowed_origins=["*"],
                    allowed_methods=[s3.HttpMethods.GET, s3.HttpMethods.HEAD],
                ),
            ],
        )

The bucket stays private: CORS settings don't make anything public. Paste your own configuration and request into the S3 CORS explainer to see which rule S3 uses and why, or check a non-S3 API with the CORS explainer.