# Same-Origin Policy

The Same-Origin Policy is a browser security rule that restricts how scripts from one origin can access documents and data belonging to another origin.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/same-origin-policy

> An origin is defined by its URL scheme, hostname, and effective port, so two applications can share a domain name yet still have different origins. The policy limits cross-origin data access in browsers, while mechanisms such as Cross-Origin Resource Sharing (CORS) let servers explicitly permit selected access without replacing authentication or authorization.

Practice exams covering Same-Origin Policy: [SCS-C03 AWS Certified Security - Specialty](https://blowstack.com/practice-exams/aws-certified-security-specialty).

## 6 key aspects of Same-Origin Policy

The Same-Origin Policy isolates browser origins, while carefully scoped CORS permissions enable necessary cross-origin access without replacing server-side security.

1. **Origin-based isolation**: Origins are distinguished by scheme, hostname, and effective port, not URL path. Separate subdomains are separate origins even when they belong to the same organization.
2. **Browser-enforced access restrictions**: The browser restricts cross-origin document interaction and response reading. It does not universally prevent requests from being sent, and non-browser clients do not inherit this enforcement.
3. **Explicit exceptions through CORS**: Servers use CORS response headers to permit selected browser origins to read responses. Allow only the origins, methods, and headers required by the application.
4. **Preflight negotiation**: Requests using certain methods or headers require an OPTIONS preflight that approves the intended request. Ensure routing, authentication handling, and edge rules do not unintentionally reject valid preflight traffic.
5. **Credential-sensitive configuration**: Credentialed cross-origin response access requires an explicit allowed origin and Access-Control-Allow-Credentials: true. Browser cookie policies remain independently applicable, and arbitrary origin reflection is unsafe.
6. **Independent authorization and edge controls**: CORS does not grant object permissions, authorize API operations, prevent CSRF, or mitigate DDoS attacks. Combine browser isolation with authorization, application security controls, and correctly configured edge caching.

## Cloud services for Same-Origin Policy

A frontend delivered through CloudFront can retrieve objects from S3 and call APIs exposed through API Gateway. If these endpoints have different browser origins, configure CORS on the relevant response paths and maintain independent authorization for objects and API operations. CloudFront can manage response headers centrally, but its forwarding and caching configuration must match any origin-dependent backend behavior. API preflight requests must reach an appropriate responder without being inadvertently blocked by authentication or edge rules. Alternatively, routing frontend assets and API paths through one public origin can avoid many CORS requirements while preserving separate backend services.

- **[Amazon S3](https://blowstack.com/tools/cloud-services-hub/amazon-s3)**: S3 bucket CORS configurations define permitted browser origins, methods, request headers, and exposed response headers for object requests. CORS configuration is separate from IAM policies, bucket policies, and other object-access controls.
- **[Amazon CloudFront](https://blowstack.com/tools/cloud-services-hub/amazon-cloudfront)**: CloudFront response headers policies can add CORS headers to responses delivered to browsers. When the backend evaluates CORS, configure request-header forwarding and cache keys so responses and preflight results are not incorrectly reused across origins.
- **[Amazon API Gateway](https://blowstack.com/tools/cloud-services-hub/amazon-api-gateway)**: API Gateway supports CORS configuration for browser-facing APIs, with different configuration responsibilities for HTTP APIs and REST APIs. Ensure preflight and actual responses receive the necessary headers; REST API proxy integrations generally require the backend to return CORS headers on actual responses.

## Same-Origin Policy exam questions

Real practice exam questions on Same-Origin Policy, with the correct answer and its explanation.

### Question 1 (SCS-C03)

**Question:**

A company uses Amazon CloudFront to serve an authenticated employee portal at https://portal.example.com/app/ and employee-uploaded HTML documents at https://portal.example.com/documents/. Separate cache behaviors route these paths to different origins. Uploaded documents must retain the ability to run arbitrary JavaScript.

A security assessment demonstrates that JavaScript in an uploaded document can read portal API responses by requesting /api/profile while the employee has an active session. The company must prevent uploaded scripts from reading portal documents and authenticated API responses without disabling JavaScript in uploaded documents. The portal URL must remain unchanged.

Which design meets these requirements?

**Correct answer:** Serve uploaded documents exclusively from https://documents.example.net and stop serving them from the portal hostname. Keep portal session cookies host-only, do not grant the document origin CORS access to portal APIs, and do not configure cross-origin DOM access.

**Explanation:** The separate hostname creates a different browser origin. Without an explicit mechanism permitting cross-origin access, scripts in uploaded documents cannot read portal documents or API responses. Host-only session cookies also avoid sharing portal credentials with the document host. CloudFront routing alone does not provide this browser isolation.

## Practice Same-Origin Policy in a full exam

Questions on Same-Origin Policy in each practice exam, with every answer option and an explanation for each:

- [SCS-C03](https://blowstack.com/practice-exams/aws-certified-security-specialty): 2 questions

## What is Same-Origin Policy

The Same-Origin Policy establishes an isolation boundary inside web browsers. For typical HTTP and HTTPS URLs, an origin consists of the scheme, hostname, and effective port; paths do not participate. For example, https://app.example.com/dashboard and https://app.example.com/settings share an origin, but https://api.example.com, http://app.example.com, and https://app.example.com:8443 are different origins. Explicitly specifying the default HTTPS port, 443, does not create a different origin.

The policy primarily restricts cross-origin reading and interaction, not every cross-origin network request. A page can often submit a form to another origin or embed cross-origin images and scripts, subject to other browser controls. However, its JavaScript generally cannot read another origin's documents or fetch responses unless an applicable mechanism permits access. Consequently, a browser can send a request that changes server state even when it refuses to expose the response to the calling script.

CORS is the standard HTTP mechanism for allowing selected cross-origin response access. Suppose a frontend at https://app.example.com fetches a JSON object from an Amazon S3 endpoint. The browser sends an Origin header, and the server must return an appropriate Access-Control-Allow-Origin value for JavaScript to read the response. An S3 CORS rule can allow the frontend's exact origin, required methods, and request headers. Access-Control-Expose-Headers makes selected response headers readable by JavaScript; it does not grant access to objects.

Some cross-origin requests require an OPTIONS preflight before the browser sends the actual request. For example, a request with an Authorization header normally triggers preflight. The server must approve the requested method and headers. S3 evaluates preflight against its configured CORS rules; OPTIONS itself is not an AllowedMethods entry in an S3 CORS rule. Requests that do not require preflight may reach the server even when the browser ultimately blocks response access.

Credentialed browser requests need particular care. If a cross-origin fetch uses credentials mode include, the response must identify the allowed origin explicitly and include Access-Control-Allow-Credentials: true; Access-Control-Allow-Origin: \* is not valid for that credentialed response. Browser cookie restrictions, including SameSite and third-party-cookie controls, still apply. Never blindly reflect arbitrary Origin values while enabling credentials, because doing so can expose authenticated responses to hostile websites.

Cloud deployments often introduce separate frontend, API, and object-storage origins. Serving the frontend and routing API paths through one public origin can reduce CORS complexity, although it adds routing and caching responsibilities. When using Amazon CloudFront, configure response headers consistently and forward the Origin and preflight request headers when the backend needs them. If responses vary by requesting origin or preflight parameters, configure the cache key accordingly or avoid caching those responses. Do not assume Vary alone configures CloudFront's cache key.

For troubleshooting, inspect the browser's network panel for the Origin header, any OPTIONS exchange, and the actual response headers and status. A backend authorization failure can appear to JavaScript as a CORS error if the error response lacks suitable CORS headers. Successful curl requests do not prove that browser access will work, because curl does not enforce the Same-Origin Policy.

The policy and CORS are not substitutes for IAM permissions, bucket policies, API authorization, or CSRF defenses. A private S3 object remains private when CORS permits an origin. AWS WAF can filter application attacks, Shield Advanced addresses DDoS protection, and AWS IoT policies authorize supported device actions; none implements the browser's same-origin boundary. Likewise, the Same-Origin Policy does not stop same-origin malicious scripts introduced through cross-site scripting. Use output encoding and a carefully designed Content Security Policy alongside these controls.

## Learn Same-Origin Policy in lessons

1 short lesson on Same-Origin Policy in 1 certification course.

- SCS-C03: Same-Origin Policy: controlled cross-origin response access (Premium), https://app.blowstack.com/lessons/same-origin-policy-controlled-cross-origin-response-access-scs-c03
