Homework

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.

  1. 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's runtime.ReadMemStats logged before and after). The resident size does not jump by 20 MB — because io.MultiWriter never holds the file, it streams. Now picture the naive io.ReadAll version and what ten concurrent uploads would do to it.

  2. 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 the documents table is unchanged. Then read http.MaxBytesReader's doc: what does it do when the limit is hit, and why is that the right behaviour for a server?

  3. Attack the key (on paper). safePath rejects any key that is not 32 hex chars. Suppose you removed that check and an attacker could set storage_key to ../../main.go. Trace what Open would then read. Write one sentence on why validating the key — not the filename — is the right place for the guard.

  4. Verify integrity by hand. Take a file you uploaded and run sha256sum on the original. Compare it to the file_hash column — 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.