Dung (Donny) Nguyen

Senior Software Engineer

Cross-Origin Resource Sharing (CORS)

CORS (Cross-Origin Resource Sharing) policy in AWS is a mechanism that allows web applications running on one domain to access resources hosted on a different domain, while enforcing necessary security restrictions. AWS implements CORS in several services, most commonly in Amazon S3 and API Gateway, enabling controlled cross-origin communication between clients and AWS-hosted resources.[1][2][3]

Core Concepts

CORS builds on the browser’s same-origin policy, which by default restricts web applications from making requests across domains for security reasons. CORS is an extension that lets developers specify, via a configuration document, which external origins are permitted to access resources, what methods (like GET, PUT, POST) can be used, and which headers can be exchanged during such requests.[2][1]

Example Use Cases

Configuring CORS in AWS Services

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "DELETE",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [
            "ETag",
            "x-amz-server-side-encryption",
            "x-amz-request-id",
            "x-amz-id-2"
        ],
        "MaxAgeSeconds": 3000
    }
]

This allows any origin and several HTTP methods, but can be restricted as needed for security.[4][3]

Security and Best Practices

While CORS enables richer client-side applications, it should be carefully configured to avoid unintended access. For example, allowed origins and methods should be as restrictive as possible, and wildcards (“*”) should only be used for public, non-sensitive resources. Standard bucket policies and IAM roles continue to apply alongside CORS; enabling CORS does not change your access controls, but instead layers browser-specific permissions on top.[2][3]

1 2 3 4 5 6 7 8