Homework — prove the flat stream, trip the cap
Expand the app. Add upload to your app if its domain has files — otherwise do these on SignFlow.
-
Prove the stream is flat. Create a large file —
head -c 20000000 /dev/urandom > big.bin(20 MB). Upload it while watching memory (top, or Go'sruntime.ReadMemStatslogged before and after). The resident size does not jump by 20 MB — becauseio.MultiWriternever holds the file, it streams. Now picture the naiveio.ReadAllversion and what ten concurrent uploads would do to it. -
Trip the cap. Upload a file just over 25 MiB (
head -c 27000000 /dev/urandom > toobig.bin). Confirm the response is 413,uploads/gained nothing, and thedocumentstable is unchanged. Then readhttp.MaxBytesReader's doc: what does it do when the limit is hit, and why is that the right behaviour for a server? -
Attack the key (on paper).
safePathrejects any key that is not 32 hex chars. Suppose you removed that check and an attacker could setstorage_keyto../../main.go. Trace whatOpenwould then read. Write one sentence on why validating the key — not the filename — is the right place for the guard. -
Verify integrity by hand. Take a file you uploaded and run
sha256sumon the original. Compare it to thefile_hashcolumn — they match. Change one byte of the original, hash again: completely different. That exact property is what a signature will later depend on, which is why the hash is worth storing at upload time.
Next lesson turns this list into a real surface: viewing a document, downloading it, and deleting a draft — with authorization enforced in the SQL itself, not in an if after the fetch.