icon

Treat uploaded files as untrusted data through their lifecycle

Security editorial team
Treat uploaded files as untrusted data through their lifecycle
  • Author:
  • Sunny Security Labs

    Security editorial team

File handling starts before storage and continues after a user closes the upload dialog. An application may accept an attachment, scan it, create a preview, send a notification and later allow a different person to download it. Assign a security decision to each transition. This makes it easier to see where an unreviewed file could become visible or where a file might remain accessible after a case is closed.

Constrain the upload

Choose the file formats the business workflow needs and set size and count limits at the application and infrastructure layers. Evaluate the declared extension and the file's contents with suitable library checks. Use a server-generated storage key and keep the submitted name as separate, safely rendered metadata. A quarantine state lets the workflow accept a file without offering it to other users before required inspection finishes.

Control what downstream steps can do

Run scanners and preview generators with limited privileges, time and memory. Put uploaded originals outside an executable web path or in private object storage. Keep authorization on the download route and issue short-lived access where direct object delivery is needed. Where appropriate, serve files with download-oriented headers and isolate the origin that presents browser-viewable content. Apply retention and deletion rules to previews and thumbnails too.

Agree on what the user sees

Define clear states for accepted, pending, rejected and unavailable files. Decide what happens if a scanner is down, a background job retries or the upload is removed during review. Log an opaque file reference, actor and decision so support can trace a problem without reading the attachment. Start with a single common file flow and use its lifecycle to check other upload endpoints.

Sources

Request a quote
Book a consultation