DedSec Project

Browser Isolation, Origins, CORS, CSP and Client-Side Trust — DedSec Project

Browser Isolation, Origins, CORS, CSP and Client-Side Trust Purpose: Understand browser security as a set of isolation boundaries and delegated capabilities rather than a collection of…

Purpose: Understand browser security as a set of isolation boundaries and delegated capabilities rather than a collection of headers.

Learning objectives

Origin as a security principal

A web origin is based on scheme, host, and port. The browser uses origin relationships to decide whether scripts can read or manipulate resources from another context. This is one of the core isolation mechanisms of the web platform.

“Site” is a related but different concept used by cookie and browser policies. Modern browsers increasingly use schemeful site concepts and storage partitioning, so do not treat origin and site as interchangeable.

Same-Origin Policy

The Same-Origin Policy limits how one origin can interact with data from another. It is not a network firewall and it does not stop a browser from sending every type of cross-origin request. In many cases, the critical restriction is whether script can read the response.

Server-side authorization remains mandatory because requests can be initiated outside a browser entirely.

CORS

Cross-Origin Resource Sharing lets a server relax selected browser read restrictions by returning policy headers. CORS is an opt-in browser mechanism; it is not authentication.

A strong CORS review asks:

Wildcard plus credentials is restricted by browsers for good reason, but many unsafe custom reflection patterns remain possible.

Preflight requests

For certain cross-origin requests the browser sends an OPTIONS preflight describing intended method and headers. The server replies with allowed policy. Preflight behavior can reduce accidental cross-origin capability but cannot be treated as an access-control barrier because non-browser clients do not need to obey it.

Cookies and SameSite

Cookies are scoped by attributes such as Domain, Path, Secure, HttpOnly, SameSite, and lifetime. Host-only cookies reduce scope compared with Domain cookies. HttpOnly prevents ordinary script access but does not stop the browser sending the cookie.

SameSite influences when cookies accompany cross-site requests and is an important CSRF defense layer. Sensitive state changes should also use origin-aware request design and anti-CSRF techniques appropriate to the application.

Content Security Policy

CSP constrains which sources a document may load/execute and can reduce the impact of injection flaws. A robust policy minimizes broad wildcards and unsafe script allowances. Nonces/hashes can support strict script policies.

CSP is defense in depth: fix the injection source rather than using CSP as the only control.

Frame isolation

Applications may need to prevent or control embedding. CSP frame-ancestors is the modern policy mechanism; legacy frame options may also exist. Framing risk is especially important for sensitive confirmation flows because UI redressing can cause a user to click an action they do not understand.

postMessage

Cross-origin windows can deliberately exchange messages. The receiver must validate event.origin, message schema, and expected sender context. The sender should use an exact target origin rather than * when the message is sensitive.

Treat the message payload like any other untrusted input even after origin validation.

Browser storage

LocalStorage, sessionStorage, IndexedDB, Cache API, service-worker storage, and cookies have different lifetimes and access semantics. Do not place long-lived bearer secrets in script-readable storage without carefully understanding XSS impact and threat model.

Storage partitioning and privacy features vary by browser version; test your supported browsers rather than relying on old assumptions.

Service workers

A service worker can intercept requests within its scope and support offline/caching behavior. Because it persists beyond one page load, insecure cache logic or compromised script can have longer-lived effects.

Secure service-worker design includes narrow scope, controlled updates, cache versioning, no caching of inappropriate authenticated content, and clear invalidation behavior.

DOM trust boundaries

Client-side code often reads URL fragments, query values, postMessage, storage, DOM attributes, and API responses. Those values remain untrusted. Use safe DOM APIs and context-appropriate encoding. Avoid converting strings into executable code or HTML when a text/content API is sufficient.

Client-side authorization is not authorization

Disabling a button, hiding a route, or checking a role in JavaScript improves UX but does not secure the backend. The server must authorize every protected operation using authenticated identity and current policy.

Trusted Types and safer sinks

Modern browser mechanisms such as Trusted Types can reduce DOM XSS risk by restricting assignment to dangerous sinks unless values are produced through approved policies. Availability and deployment details vary; treat them as a hardening layer alongside output encoding and safe APIs.

Safe local origin lab

Run two localhost services on different ports, such as 127.0.0.1:8000 and 127.0.0.1:8001. They are different origins because the port differs. Create a tiny page that attempts fetch() between them. Observe browser console behavior before and after adding a narrowly scoped CORS policy to the second service.

Use only synthetic data. The goal is observing browser enforcement, not bypassing another site's policy.

Security review checklist

Guided study workflow

Before you begin

Complete Modules 11, 14, 39, 44, 52, and 69.

Practice task

Build two localhost origins. Demonstrate SOP blocking a cross-origin read, then configure an exact CORS allow rule. Add a postMessage demo that rejects messages from unexpected origins.

Evidence to keep

Browser console/network observations, response headers, origin diagram, and the code enforcing exact origin checks.

Common mistakes to avoid

Mastery check

Explain the difference between SOP, CORS, CSRF defenses, CSP, and server authorization in one coherent request flow.

Continue with

Modules 71, 78, and 84.