M. Kodirov

STAGE 05 / LESSON 04

OWASP, XSS and CSRF

Security starts by identifying what can go wrong across trust boundaries.

THE IDEA

Understand it.

The OWASP Top 10 is an awareness guide to major web application risk categories. Broken access control and injection are examples. Use it as a starting point, not a guarantee that an application is secure.

XSS involves untrusted content being executed as script in a page. CSRF tricks a browser into sending an unwanted authenticated request. Context-appropriate output handling, server-side authorization, CSRF defenses and careful cookie settings address different parts of these risks.

SEE IT IN CONTEXT

Different attack, different defense

Untrusted text → interpreted as script  = XSS risk
Other site → unwanted authenticated action = CSRF risk
Changed task ID → unauthorized access = access-control risk

A single header or library does not solve every category. Apply the appropriate defense at each boundary.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

GitHub

GitHub engineering, 2016

Restrict script execution with CSP

GitHub described its work deploying Content Security Policy as a defense against cross-site scripting.

  1. Response policy
  2. Browser checks content
  3. Restricted script execution

What to learn: CSP is a defense in depth, not a replacement for safely handling untrusted content; the article is historical.

Read the source: GitHub CSP journey

Google

Google security, 2020

Trusted Types for My Google Activity

Google reported launching Trusted Types for My Google Activity in 2020 to help prevent DOM-based XSS.

  1. Untrusted strings
  2. Trusted Types policy
  3. Sensitive DOM operation

What to learn: This protection targets unsafe DOM operations. It does not replace server-side authorization or CSRF defenses.

Read the source: Google Online Security Blog: July 2020

TRY IT YOURSELF

Practice.

Does a CORS policy alone replace server-side authorization?

Show one possible answer

No. CORS controls certain browser cross-origin access behaviors; it is not an authorization mechanism for all clients.

GO DEEPER

Official references.