AWS S3 Blocks Browser Downloads with CORS When the Bucket Policy Allows Access but the CORS Rule Does Not
The browser blocks https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf with this error: Access to fetch at 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf' from origin 'https://app.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
What is actually failing
S3 can return the object successfully while the browser still refuses to expose the response to JavaScript. Those are separate checks.
The bucket policy answers a permission question: “Is this principal allowed to get this object?”
The CORS configuration answers a browser question: “May a page from this origin read the response to this cross-origin request?”
If the object is public, or the caller is signed and authorized, S3 can still send back 200 OK and the file bytes. But if the response does not include the right CORS headers, the browser’s fetch layer blocks JavaScript from reading the response body, status, or headers.
That distinction matters because the network request may succeed in DevTools while the code still sees a rejected fetch() promise or an opaque response, depending on the request mode and headers.
The exact failure shape
A typical browser console error looks like this:
textAccess to fetch at 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf' from origin 'https://app.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
If the request uses custom headers or PUT, POST, or DELETE, the preflight can fail first:
textAccess to fetch at 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf' from origin 'https://app.example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Methods' header is present on the requested resource.
Or:
textAccess to fetch at 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf' from origin 'https://app.example.com' has been blocked by CORS policy: Request header field x-amz-checksum-sha256 is not allowed by Access-Control-Allow-Headers in preflight response.
The object URL is still the same. The browser is rejecting the cross-origin response because the bucket’s CORS rule does not match the request.
IAM permission and CORS are different controls
S3 authorization and browser CORS are not interchangeable.
A bucket policy, IAM policy, or a presigned URL can authorize the request. That authorization determines whether S3 sends the object at all.
CORS determines whether the browser exposes that response to JavaScript.
For a simple GET, S3 may return the object even if no CORS rule exists. The browser then hides the response from fetch() or XMLHttpRequest because the response lacks Access-Control-Allow-Origin.
For requests that trigger a preflight, the browser sends an OPTIONS request first. S3 must answer that preflight with matching CORS headers before the actual request is even sent. In that case, a missing or incomplete CORS rule blocks the flow earlier.
The key point is that a valid bucket policy does not imply a valid browser-readable response.
Why S3 can return the file anyway
A browser-originated request crosses an origin boundary. The browser enforces the Same Origin Policy.
S3 does not decide whether a page can read the response based on the bucket policy alone. It evaluates the request against its authorization rules and, if the request is allowed, returns the object. Only after that does the browser inspect the response headers.
If the response does not contain a matching Access-Control-Allow-Origin value, the browser suppresses access to the body and most headers in JavaScript. The download can appear to work in a tab navigation or in curl, while fetch() still fails.
This is why a direct object URL in the address bar is not a useful test for browser CORS. A browser navigation is not the same as a cross-origin script read.
The CORS rule must match the actual request
An S3 CORS configuration needs to allow the origin, the method, and any headers involved in the request. If any one of those does not match, the browser can block the request.
A minimal rule for a frontend at https://app.example.com that reads objects with GET looks like this:
json[ { "AllowedOrigins": ["https://app.example.com"], "AllowedMethods": ["GET", "HEAD"], "AllowedHeaders": ["*"], "ExposeHeaders": [ "ETag", "Content-Length", "Content-Type", "Last-Modified", "x-amz-request-id", "x-amz-id-2" ], "MaxAgeSeconds": 3000 } ]
If you need to send credentials such as signed cookies, AllowedOrigins cannot be *. You must specify the exact origin, and the response must also include Access-Control-Allow-Credentials: true when applicable. S3 CORS supports this when the request is credentialed through the browser, but you still need the origin to match exactly.
If the request includes custom headers, they must be allowed. For example, if your frontend sends Authorization or x-amz-content-sha256, include them explicitly or use * if that fits your security model and the browser request qualifies.
Example XML for the same rule:
xml<CORSConfiguration> <CORSRule> <AllowedOrigin>https://app.example.com</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>HEAD</AllowedMethod> <AllowedHeader>*</AllowedHeader> <ExposeHeader>ETag</ExposeHeader> <ExposeHeader>Content-Length</ExposeHeader> <ExposeHeader>Content-Type</ExposeHeader> <ExposeHeader>Last-Modified</ExposeHeader> <ExposeHeader>x-amz-request-id</ExposeHeader> <ExposeHeader>x-amz-id-2</ExposeHeader> <MaxAgeSeconds>3000</MaxAgeSeconds> </CORSRule> </CORSConfiguration>
Matching the request headers matters
Preflight happens when the browser sees a cross-origin request that is not “simple.” Common triggers include a non-simple method like PUT, a custom header like Authorization, or a content type outside the simple set.
For example, this fetch() triggers preflight because it sends Authorization:
tsconst url = 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf'; const response = await fetch(url, { method: 'GET', headers: { Authorization: 'Bearer example-token' } }); if (!response.ok) { throw new Error(`Request failed: ${response.status}`); }
The bucket CORS rule must allow GET and Authorization in AllowedHeaders if the browser is going to send that header.
If you upload directly from the browser, the rule must also allow PUT or POST as needed. A download-only rule is not enough for upload code.
Check the exact origin, not a loose approximation
The Origin request header contains the full scheme, host, and port. https://app.example.com and https://app.example.com:443 are not always treated the same by configuration tools, and http://localhost:3000 is a different origin from http://localhost:5173.
A CORS rule that allows only https://app.example.com will not match http://localhost:3000. A CORS rule with * may work for public, non-credentialed reads, but it is not suitable for credentialed browser requests.
When testing locally, include your development origin explicitly:
json[ { "AllowedOrigins": [ "https://app.example.com", "http://localhost:3000" ], "AllowedMethods": ["GET", "HEAD"], "AllowedHeaders": ["*"], "ExposeHeaders": ["ETag", "Content-Length"], "MaxAgeSeconds": 3000 } ]
Verify the preflight and the response headers
Use curl to inspect the headers S3 returns. First test the actual request headers:
bashcurl -i \ -H 'Origin: https://app.example.com' \ 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf'
A correct response includes something like:
textHTTP/2 200 access-control-allow-origin: https://app.example.com access-control-expose-headers: ETag, Content-Length, Content-Type, Last-Modified, x-amz-request-id, x-amz-id-2 content-type: application/pdf
For preflight, simulate the browser’s OPTIONS request:
bashcurl -i -X OPTIONS \ -H 'Origin: https://app.example.com' \ -H 'Access-Control-Request-Method: GET' \ -H 'Access-Control-Request-Headers: authorization' \ 'https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf'
A valid preflight response should include:
textHTTP/2 200 access-control-allow-origin: https://app.example.com access-control-allow-methods: GET, HEAD access-control-allow-headers: authorization access-control-max-age: 3000
If access-control-allow-headers does not include the requested header, the browser blocks the real request.
Set the bucket CORS configuration explicitly
Use the AWS CLI to apply the rule.
JSON file cors.json:
json[ { "AllowedOrigins": ["https://app.example.com"], "AllowedMethods": ["GET", "HEAD"], "AllowedHeaders": ["*"], "ExposeHeaders": [ "ETag", "Content-Length", "Content-Type", "Last-Modified", "x-amz-request-id", "x-amz-id-2" ], "MaxAgeSeconds": 3000 } ]
Apply it:
bashaws s3api put-bucket-cors \ --bucket your-bucket \ --cors-configuration file://cors.json
Confirm it is set:
bashaws s3api get-bucket-cors \ --bucket your-bucket
If the frontend uses PUT uploads, expand the methods and headers accordingly:
json[ { "AllowedOrigins": ["https://app.example.com"], "AllowedMethods": ["GET", "HEAD", "PUT"], "AllowedHeaders": [ "Authorization", "Content-Type", "x-amz-*" ], "ExposeHeaders": [ "ETag", "x-amz-request-id", "x-amz-id-2" ], "MaxAgeSeconds": 3000 } ]
Use the right header list for the request you actually send
AllowedHeaders must cover what the browser includes in the preflight. That often means more than just Content-Type.
Common headers in S3 browser workflows include:
AuthorizationContent-Typex-amz-aclx-amz-content-sha256x-amz-datex-amz-security-tokenx-amz-meta-*x-amz-checksum-sha256
If you use presigned URLs for direct browser upload or download, many of those x-amz-* headers can appear depending on the signing method and SDK version. If the rule is too narrow, preflight fails even though the object path and signature are correct.
A broad pattern like x-amz-* is common for S3 browser upload flows, but you should still keep the allowed origin and methods narrow.
Keep the response readable by JavaScript
Some headers are present on the wire but invisible to browser JavaScript unless they are listed in ExposeHeaders. If the code needs ETag or Content-Length, add them.
Example:
tsconst response = await fetch('https://your-bucket.s3.us-east-1.amazonaws.com/path/to/file.pdf', { method: 'GET', mode: 'cors' }); const etag = response.headers.get('ETag'); const length = response.headers.get('Content-Length');
Without ExposeHeaders, response.headers.get('ETag') can return null even when S3 sent it.
When the object should be public
If the file is truly public and the browser only needs a simple read, a narrowly scoped CORS rule is enough. You still need it even when the bucket policy allows anonymous s3:GetObject.
If you want any origin to read a non-credentialed response, you can use * for AllowedOrigins:
json[ { "AllowedOrigins": ["*"], "AllowedMethods": ["GET", "HEAD"], "AllowedHeaders": ["*"], "ExposeHeaders": ["ETag", "Content-Length"], "MaxAgeSeconds": 3000 } ]
That works only for non-credentialed requests. If the browser includes credentials, * is not acceptable.
Practical takeaway
Prefer a bucket CORS rule that matches the exact browser origin, method, and request headers used by the frontend. Keep the bucket policy focused on authorization and use CORS only to make the response readable by the browser. For downloads, a rule with AllowedOrigins, AllowedMethods set to GET and HEAD, and AllowedHeaders covering the headers your code sends is the safest starting point. That prevents the common failure where S3 returns the object but JavaScript still gets blocked by the browser.