rm -rf on an Empty Variable

Easy

· Backend

Incident

SEV-1

BUG-STEAMROOT

Priority: Critical (data loss) · reported by linux support

Time to fix: 10 min

Failing checks on the shipped build

  • an empty root is refused

    an unset root must never become /: expected {"safe":false,"path":""} but got {"safe":true,"path":"/steamapps"}

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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  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

Steam for Linux · 2015

Modelled on the Steam for Linux bug (January 2015): an uninstall script ran rm -rf "$STEAMROOT/"*. When STEAMROOT was empty the expansion became rm -rf "/"*, and users lost everything the account could write, including mounted backup drives.

uninstall.js builds the same kind of path and never checks that the root is real.

Fix buildRemovePath so an empty, missing or root value is refused.

Code map

// Builds the directory the uninstaller will remove.
exports.buildRemovePath = function (root, subdir) {
  return { safe: true, path: root + "/" + subdir };
};

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.

rm -rf on an Empty Variable — JavaScript Bug Hunt

Modelled on the Steam for Linux bug (January 2015): an uninstall script ran rm -rf "$STEAMROOT/"*.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Shell Safety, Empty Values
  • Modelled on: Steam for Linux · 2015
  • Visible tests: a normal root builds a path; an empty root is refused
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (data loss))
  • Ticket: BUG-STEAMROOT
  • Reported by: linux support
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • an empty root is refused — an unset root must never become /: expected {"safe":false,"path":""} but got {"safe":true,"path":"/steamapps"}

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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  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 Steam for Linux bug (January 2015): an uninstall script ran rm -rf "$STEAMROOT/"*. When STEAMROOT was empty the expansion became rm -rf "/"*, and users lost everything the account could write, including mounted backup drives.

uninstall.js builds the same kind of path and never checks that the root is real.

Fix buildRemovePath so an empty, missing or root value is refused.

Bug report

BUG-STEAMROOT · Priority: Critical (data loss) · Reported by: linux support

buildRemovePath(root, subdir) must return:

  • { safe: true, path: root + "/" + subdir } for a sane absolute root
  • { safe: false, path: "" } when root is empty, undefined, "/" or does not start with "/"

Observed: an empty root produces "/steamapps" — and callers happily recurse from the filesystem root.

Logs

[uninstall] removing "/*" (STEAMROOT was empty)
[uninstall] 1.4 TB removed from an external mount

The code as shipped

src/installer/uninstall.js (editable)

// Builds the directory the uninstaller will remove.
exports.buildRemovePath = function (root, subdir) {
  return { safe: true, path: root + "/" + subdir };
};

Read-only context: src/installer/SAFETY.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.