Java, Newline, Script

Medium

· Frontend

Incident

SEV-1

BUG-SAMY

Priority: Critical (stored XSS) · reported by security

Time to fix: 20 min

Failing checks on the shipped build

  • a scheme split by a newline is still refused

    browsers ignore the newline: expected false but got true

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

MySpace · Samy worm 2005

Modelled on the Samy worm on MySpace (October 2005): MySpace's profile filter removed the word javascript, but some browsers still ran a CSS url() in which the word was split by a newline — java\nscript:. Samy Kamkar's profile used that gap to add him as a friend of everyone who viewed it, and the worm reached over a million profiles in about a day.

This project is a reconstruction. sanitize.js decides whether a URL may go into a profile's background style by searching for a forbidden word.

Fix isSafeUrl so the check is made on what the browser will actually see, and only known-safe schemes pass.

Code map

// Decides whether a user-supplied URL may appear in a profile style.
exports.isSafeUrl = function (url) {
  return String(url).toLowerCase().indexOf("javascript") === -1;
};

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

Java, Newline, Script — JavaScript Bug Hunt

Modelled on the Samy worm on MySpace (October 2005): MySpace's profile filter removed the word javascript, but some browsers still ran a CSS url() in which…

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Medium
  • Concepts: Security, Parsing
  • Modelled on: MySpace · Samy worm 2005
  • Visible tests: an https background is allowed; a scheme split by a newline is still refused
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (stored XSS))
  • Ticket: BUG-SAMY
  • Reported by: security
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • a scheme split by a newline is still refused — browsers ignore the newline: expected false but got true

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Modelled on the Samy worm on MySpace (October 2005): MySpace's profile filter removed the word javascript, but some browsers still ran a CSS url() in which the word was split by a newline — java\nscript:. Samy Kamkar's profile used that gap to add him as a friend of everyone who viewed it, and the worm reached over a million profiles in about a day.

This project is a reconstruction. sanitize.js decides whether a URL may go into a profile's background style by searching for a forbidden word.

Fix isSafeUrl so the check is made on what the browser will actually see, and only known-safe schemes pass.

Bug report

BUG-SAMY · Priority: Critical (stored XSS) · Reported by: security

isSafeUrl(url):

  • first remove every character with code <= 32 (spaces, tabs, newlines and other control characters) and code 127, then lower-case the result
  • if what remains starts with a scheme (a letter, then letters, digits, "+", "-" or ".", then ":"), the URL is safe ONLY when that scheme is http or https
  • a URL with no scheme (e.g. "/img/bg.png", "img/bg.png") is relative and safe

render.backgroundStyle uses it to decide whether a URL is emitted.

Observed: "java<newline>script:…" passes the filter and runs in the viewer's browser.

Logs

[profile] saved style for user 11851658 (filter: ok)
[profile] friend count for user 11851658 growing without user action

The code as shipped

src/profile/sanitize.js (editable)

// Decides whether a user-supplied URL may appear in a profile style.
exports.isSafeUrl = function (url) {
  return String(url).toLowerCase().indexOf("javascript") === -1;
};

Read-only context: src/profile/render.js.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.