We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Encrypted Files

Imagine a payroll service that stores employee tax documents as ordinary files. If an attacker copies its disk, backup, or storage snapshot, they get every document in plaintext.

If you're storing sensitive documents, encrypt them at rest.

Encrypt Before Writing

The safest way to handle the storage sequence is:

  1. Validate the plaintext file while it is still in memory.
  2. Encrypt its bytes with the active key from the keyring.
  3. Serialize the key version, nonce, authentication tag, and ciphertext.
  4. Write only that serialized encrypted payload to storage.

In other words, the plaintext bytes never touch the disk, only memory.

Give the encrypted file a random name, like a UUID with an .enc extension. Map that value back to the original filename in the database so the stored path doesn't reveal or trust a user-supplied name.

Assignment

The upload flow, archive imports, authorized downloads, and automatic migration are already wired together. Complete the two byte transforms in src/uploads/taxDocuments.ts, then move the sample fixture out of runtime storage.

With Bearly Secure still running, run and submit the CLI tests from the project root.