0
0
AWScloud~10 mins

CORS configuration in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - CORS configuration
Client sends request
Browser checks CORS policy
Browser sends OPTIONS preflight request?
NoSend actual request
Yes
Server responds with CORS headers
Browser checks headers
Allow or block request based on CORS
Client receives response or error
This flow shows how a browser and server interact to enforce CORS rules, allowing or blocking cross-origin requests.
Execution Sample
AWS
PUT /bucket-name
{
  "CORSConfiguration": {
    "CORSRules": [{
      "AllowedOrigins": ["https://example.com"],
      "AllowedMethods": ["GET", "POST"]
    }]
  }
}
This code sets a CORS policy on an AWS S3 bucket allowing GET and POST from https://example.com.
Process Table
StepActionRequest TypeCORS Headers SentBrowser DecisionResult
1Client sends GET request from https://example.comGETOrigin: https://example.comCheck if origin allowedProceed to send request
2Browser sends OPTIONS preflight for POSTOPTIONSOrigin: https://example.com, Access-Control-Request-Method: POSTWait for server responseWaiting
3Server responds with CORS headersOPTIONS ResponseAccess-Control-Allow-Origin: https://example.com, Access-Control-Allow-Methods: GET, POSTCheck if POST allowedAllowed
4Browser sends actual POST requestPOSTOrigin: https://example.comCheck if origin allowedProceed to send request
5Server responds to POSTPOST ResponseAccess-Control-Allow-Origin: https://example.comAllow responseResponse received
6Client sends GET request from https://malicious.comGETOrigin: https://malicious.comCheck if origin allowedBlocked
7Browser blocks responseN/AN/AOrigin not allowedError: CORS policy blocks request
💡 Execution stops when browser blocks request from disallowed origin or completes allowed request.
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5After Step 7
OriginN/Ahttps://example.comhttps://example.comhttps://example.comhttps://malicious.com
AllowedOrigins["https://example.com"]["https://example.com"]["https://example.com"]["https://example.com"]["https://example.com"]
Request Allowedfalsetruetruetruefalse
Response Receivedfalsefalsefalsetruefalse
Key Moments - 2 Insights
Why does the browser send an OPTIONS preflight request before the actual POST?
The browser sends OPTIONS to check if the server allows the POST method from the origin. This is shown in execution_table step 2 and 3 where the preflight is sent and the server responds with allowed methods.
Why is the request from https://malicious.com blocked?
Because the CORS policy only allows https://example.com. The browser checks the origin against AllowedOrigins and blocks it as shown in execution_table step 6 and 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what CORS header does the server send in response to the OPTIONS preflight?
AAccess-Control-Allow-Methods: GET, POST
BAccess-Control-Allow-Origin: https://example.com
CAccess-Control-Allow-Headers: Content-Type
DAccess-Control-Allow-Credentials: true
💡 Hint
Check step 3 in the execution_table under 'CORS Headers Sent'
At which step does the browser block the request due to CORS policy?
AStep 6
BStep 7
CStep 5
DStep 4
💡 Hint
Look for 'Blocked' or 'Error' in the 'Result' column of execution_table
If AllowedOrigins included "https://malicious.com", how would the 'Request Allowed' variable change at step 7?
AIt would remain false
BIt would become undefined
CIt would become true
DIt would cause an error
💡 Hint
Check variable_tracker for 'Request Allowed' at step 7
Concept Snapshot
CORS configuration controls which origins can access resources.
Browsers enforce CORS by sending preflight OPTIONS requests for some methods.
Server responds with headers like Access-Control-Allow-Origin and Access-Control-Allow-Methods.
If origin or method not allowed, browser blocks the request.
Set CORS on AWS S3 via CORSConfiguration with AllowedOrigins and AllowedMethods.
Full Transcript
CORS configuration is a security feature that controls which websites can access resources on a server. When a client from a different origin tries to access a resource, the browser checks the CORS policy. For some requests, it sends a preflight OPTIONS request to ask the server if the actual request is allowed. The server responds with headers indicating allowed origins and methods. If the origin or method is not allowed, the browser blocks the request. In AWS S3, you configure CORS by setting AllowedOrigins and AllowedMethods in the bucket's CORSConfiguration. This example showed a client from https://example.com allowed to GET and POST, while a client from https://malicious.com was blocked.