Reference

Security & identity

Look up identity, access checks, browser defenses, secrets and safe input boundaries.

Scope and conventions

Web/API security patterns, not a complete authentication implementation or security certification. Sequences are labeled sketches. Use maintained framework/provider libraries for identity and cryptography; adapt policies to your trust boundaries. Primary sources accompany each entry.

Browser boundaries

Protect cookie-authenticated state changes from CSRF

Web & API security

Use your framework’s CSRF protection, with a validated token or an origin policy (Origin or Sec-Fetch-Site checks) suited to the application. Browsers can attach credentials to requests initiated elsewhere. SameSite is a useful layer, not a universal replacement.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Web & API security · Protect cookie-authenticated state changes from CSRF
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
state-changing request
→ authenticate session
→ validate CSRF protection and origin policy
→ authorize action
→ mutate state

Do not use CORS as an access check

Web & API security

CORS regulates browser-script access to cross-origin responses. Non-browser clients are not constrained by it, and some cross-origin requests are still sent. Authorize the server operation independently.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Web & API security · Do not use CORS as an access check
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
allowed browser origin ≠ authenticated user
readable response      ≠ permission to change data

Render untrusted text in the correct output context

Web & API security

Use framework text interpolation or an ordinary text-only DOM sink for plain text. HTML, attribute, URL, CSS and JavaScript contexts need different handling. Validating input does not make it safe in every output context.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Web & API security · Render untrusted text in the correct output context
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
untrusted plain text → text node / framework text interpolation
intentionally allowed HTML → maintained HTML sanitizer + safe sink

Use CSP as an additional browser defense

Web & API security

A Content Security Policy can restrict script sources and other resource use. Deploy and test a policy for your application; it complements contextual output handling rather than repairing unsafe HTML insertion.

Fragment

Illustrative report-only response header; it does not enforce blocking. A production policy needs app-specific scripts, nonces/hashes and reporting decisions.

Web & API security · Use CSP as an additional browser defense
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Content-Security-Policy-Report-Only: default-src 'self'; object-src 'none'; base-uri 'self'