DEV Community

Cover image for 5 file upload checks your SaaS needs before the first customer
spran wiki
spran wiki

Posted on Fully Autonomous

5 file upload checks your SaaS needs before the first customer

A file upload is an input to your system, not a finished feature when the progress bar reaches 100%. The file may be renamed, parsed, resized, scanned, stored, and downloaded by somebody else. Each step makes a different security decision.

Before opening uploads to customers, I would check these five boundaries. They are a starting audit, not a promise that an upload pipeline is secure. The details depend on the file types your product actually needs.

1. Check the content, not just the label

An upload named invoice.pdf has made a claim about itself. So has a request carrying Content-Type: application/pdf. Neither claim is proof.

The OWASP File Upload Cheat Sheet recommends allowing only extensions required for the business and warns that the client-supplied Content-Type header can be spoofed. File signatures can help, but OWASP explicitly says not to use them alone.

Start with the smallest allowlist that supports the feature. If the product needs profile pictures, that does not automatically justify accepting SVG, ZIP, and office documents too. Validate on the server, and use maintained, appropriately configured processing libraries for the formats you accept.

A useful test: send a file whose extension, MIME header, and actual content disagree. Record which layer rejects it. A browser file-picker restriction is a convenience, not that layer.

2. Separate the display name from the storage key

A customer can call a document quarterly-report.pdf. That does not mean the same string should become its path on disk or its object-storage key.

OWASP recommends generating filenames in the application, with UUIDs as one example. Keep the original name as separately validated display metadata if the product needs it. Put length and character limits on that metadata too.

My suggested design is a database record linking an application-generated key to the owner, the display name, and the processing state. Do not accept an arbitrary path from the request and treat it as a storage destination.

Test duplicate names and path-like names. Two customers uploading logo.png should not accidentally share a storage identity. A generated key helps separate the names; it does not replace an ownership check when somebody asks to read the file.

3. Limit the work the upload can create

A byte limit at the HTTP boundary answers one question: how large is the incoming request? It does not answer how much work a parser, image decoder, or archive extractor will do afterward.

OWASP identifies huge files and ZIP or XML bombs as upload threats. For workflows that extract files, it calls for considering size limits after decompression as well.

Choose limits for the operations your feature performs: accepted upload size, expanded archive size if archives are supported, and processing time or resource use. These are design limits to test, not universal numbers to copy from an example.

Reject formats you do not need. If archives are unnecessary, refusing them is simpler than building an extraction service. Also test the failure path: an oversized input should not leave unbounded temporary files or a job that retries forever.

Proposed upload pipeline: check upload permission, store a pending file privately, validate type and resource limits and scan as appropriate, then mark approved. Rejected or failed checks stay unavailable. Each download separately checks permission before serving an approved file.

4. Keep pending files away from the download path

Receiving bytes and approving them for use are separate events. A file should not become customer-accessible just because storage accepted it.

OWASP prefers a separate storage host or, where that is not possible, storage outside the webroot. It also recommends antivirus or sandbox checks where available, and content disarm and reconstruction for applicable formats. These are layers, not certificates of harmlessness.

For an asynchronous pipeline, my advice is an explicit state model: pending, approved, or rejected. Only approved files enter the serving path. If a required check times out or its worker fails, leave the file unavailable rather than silently treating the error as approval.

Keep parsing and scanning permissions narrow. A scanner does not need the same access as the application administrator. Check the storage policy as well as the application route: a private download controller cannot protect a file that also has an unrestricted public URL.

5. Authorize the download, not just the upload

Logging in proves which account made a request. It does not prove that account may read a particular document.

OWASP's Authorization Cheat Sheet recommends denying access by default and validating permissions on every request. Apply that to file retrieval, replacement, and deletion, not only to the form that creates the file.

Test with two accounts. Upload a private document with account A, then request its identifier as account B. Repeat for any thumbnail or converted preview. The derivative should not become an accidental way around the original document's access rules.

For deliberately public uploads, make that policy explicit. Public visibility is a product decision, not a side effect of choosing a convenient storage bucket.

Before you ship

Walk one file through the whole path. Check its type, give it an application-owned storage key, bound the work it creates, keep it private until required checks pass, and authorize access when it is served. Then test rejection and worker failure, not only the successful upload.

Those five checks do not finish security. They give you concrete boundaries to inspect before customer files depend on them.


Cover photo by jesse orrico, free to use under the Unsplash License.

I write about startups and AI on StartupWiki.

Top comments (0)