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.
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
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 userreadable response ≠ permission to change data
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 interpolationintentionally allowed HTML → maintained HTML sanitizer + safe sink
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