Web and API securityHackBlue

File upload validation

Nine uploads hit a profile picture endpoint: two real photos and seven files that should never be stored as sent. Turn on checks until every one is handled.

  • Interactive lab
  • Intermediate
  • 5 graded steps
  • 0 of 5 solved

Your goal

Your goalTurn on the checks that keep both real photos working and stop all seven bad uploads from being stored dangerously.

The profile picture endpoint accepts anything today and saves it in the public folder under the name the client sent. A test suite of nine uploads is ready: two real photos and seven files that should never be stored as they are.

Turn checks on and off and watch what the server would store. Nothing is uploaded or executed; each row is a description of a file and the decision the server makes about it.

What’s on screen
Server checks, in order
the switches on the left. Each is one rule the server applies to every upload.
Upload test suite
the table on the right: nine files with what they claim to be, their first bytes, size, and what the server does.
Walkthrough
the numbered path beside the workbench (below it on a phone). Each step says what to do and what you should see. Hints open one at a time.
Words to know
XML
Extensible Markup Language, a tagged text format
MB
megabyte

Server checks, in order

Upload test suite7 wrong
FileClaimedFirst bytesSizeServer
avatar.pngA real photoimage/png89 50 4e 47 0d 0a 1a 0a182 kBaccepted
Stored as an image.
Holiday Photo.JPGA real photoimage/jpegff d8 ff e0 00 10 4a 462.3 MBaccepted
Stored as an image.
shell.phpContains server-side scriptimage/png3c 3f 70 68 70 20 2f 2f1 kBdangerous
Stored in the web root with its own name, where the server may run it as PHP.
avatar.php.pngContains server-side scriptimage/png3c 3f 70 68 70 20 2f 2f1 kBdangerous
Stored in the web root with its own name, where the server may run it as PHP.
badge.jpgContains script text hidden in a JPEG comment segmentimage/jpegff d8 ff fe 00 2c 3c 3f48 kBdangerous
Stored in the web root with its own name, where the server may run it as PHP.
logo.svgContains an inline <script> elementimage/svg+xml3c 73 76 67 20 78 6d 6c3 kBdangerous
Served with a type the browser can sniff as a page, so the script runs on your origin.
../../static/js/app.pngContains a path that climbs out of the upload folderimage/png89 50 4e 47 0d 0a 1a 0a40 kBdangerous
Stored at the client’s path, overwriting /static/js/app.png.
scan.pngContains a 96 MB file meant to exhaust disk and decoder memoryimage/png89 50 4e 47 0d 0a 1a 0a96 MBdangerous
Stored a 96 MB file; repeated uploads fill the disk and stall the thumbnailer.
profile.pngContains an HTML page saved with a .png nameimage/png3c 21 64 6f 63 74 79 702 kBdangerous
Served with a type the browser can sniff as a page, so the script runs on your origin.