How to Fix CORS Errors in S3 Object Storage

CORS (Cross-Origin Resource Sharing) is a browser security mechanism that defines whether a site can access resources from another origin. S3 Object Storage can generate CORS errors when a website or web application is retrieving, uploading, or accessing files stored in a Space.

Suppose your website is https://example.com and you want to load an image from another storage endpoint . The browser checks if this is allowed to be loaded cross origin .

Common Causes of CORS Errors

How to Troubleshoot CORS Errors

1. Check the Browser Console

Open your website in a browser and press F12 to open Developer Tools. Select the Console tab and reproduce the error.

The message may indicate whether the origin, request method, headers, or preflight request is causing the problem.

2. Verify the Allowed Origin

Check the origin of the website making the request. An origin includes the protocol, domain, and port.

For example, https://example.com and http://example.com are different origins. Similarly, https://app.example.com and https://example.com are different origins.

The storage CORS configuration must allow the origin used by your application.

3. Check the Allowed Methods

Make sure the CORS rules allow the HTTP method required by your application.

Common methods include:

Allowing a method through CORS does not automatically grant permission to perform that action. Storage permissions must also allow it.

4. Verify the Allowed Headers

Some requests include headers such as Content-Type, Authorization, or S3-compatible request headers. If the browser requests permission to send headers that the CORS configuration does not allow, the request may fail.

Use the browser's Network tab to inspect the failed request and identify the headers involved.

5. Check the Preflight Request

For certain cross-origin requests, the browser sends an OPTIONS request before sending the actual request.

If this preflight request fails, check whether the storage service returns the required CORS headers and allows the requested origin, method, and headers.

6. Review the Storage CORS Configuration

If your storage panel supports CORS settings, verify the allowed origins, methods, and request headers. Include only the origins and operations required by your application.

If the panel does not provide CORS settings, check whether configuration through a supported S3-compatible client or API is available.

7. Verify the Endpoint and Object Access

Confirm that the application uses the correct storage endpoint and object key. Also check whether the file exists and whether the request has permission to access it.

A missing object or a 403 Forbidden response may be accompanied by a CORS error if the response does not include the expected CORS headers.

Common CORS Errors

Error or symptom

What to check

Access-Control-Allow-Origin missing

Verify the allowed origin and response headers.

Preflight request failed

Check the OPTIONS response, methods, and headers.

Method not allowed

Confirm the required method is included in the CORS rules.

Request header not allowed

Check the headers requested by the browser.

File works through a direct link but not in the website

Check the website's origin and the storage response's CORS headers.

CORS error with a 403 response

Check object permissions, credentials, and response headers.

Important Things to Know

Security note: Never expose secret access keys, passwords, or authorization tokens in browser-side code or while sharing troubleshooting details.