WEBA-3Lesson 3 of 310 min

Attacks through the browser

Some web attacks do not target the server. They use a site you trust to make your own browser do something you did not ask for. This lesson covers the two best known.

Cross-site scripting

Figure WEBA-3.1A comment that the browser obeys

comments

asha: Great notes, thank you!
bhavesh: Is this in the exam?
1/4

A course page lets students post comments, which are shown to everyone who opens the page.

Step 1 of 4

Requests you did not mean to send

Cross-site request forgery (CSRF) works differently. You are signed in to your college portal in one tab. In another tab you open a harmful page, which quietly makes your browser send a request to the portal, such as “change my email address”. Your browser includes your login automatically, so the portal thinks you asked.

Defences

  • Encode output: turn user text into plain characters before putting it in a page. This stops XSS completely.
  • Content Security Policy: a setting that tells browsers which scripts a page may run.
  • CSRF tokens: a secret value included in each real form, which a harmful page cannot know. SameSite cookies also stop the browser sending your login with requests that start on other sites.

WEBA-3 counts as completed once you step through the figure to its last step.