Secure file uploads: check file types, storage and access
The form accepts a PDF, the upload completes and the preview opens: the feature looks finished. Yet you still need to establish what the server stored and who can read the document. Whether you build with AI or add attachments to a low-code app, review the entire file journey, from the browser picker to every download route.
Follow the file beyond the upload form
In a fictional design approval service, a member attaches a PNG or PDF to a private project. The file passes through the form, upload handler, storage and preview generator. It may later appear in a project card, be downloaded through a link or be included in an export. Each step is another place where a mistake can occur.
Draw a small map: where the file is accepted, which services process it, where originals and copies remain, and which URLs serve them. Record the intended audience for each URL. This can reveal a private project card that uses a public preview. The scenario is educational, not a finding from a customer audit.
Browser hints do not validate the contents
MDN explains that the accept attribute guides users towards suitable files; it does not perform server-side validation. A picker that displays only PDFs does not establish that the server accepts only PDFs.
Blob.type, which is also available on File objects, is not a reliable inspection of file contents: the browser may infer the type from the extension. On the server, check the permitted format against the content and the processing your product supports. A MIME header or recognizable signature alone does not establish that a file is safe.
Define acceptance rules on the server
Keep the formats your product needs and set a size limit. Generate the storage name in the application: a user-supplied name must not choose the path or replace an existing file. The display name and internal identifier serve different purposes.
OWASP recommends combining format checks with safe content processing. If you generate previews or inspect files, handle processor failures and limit its resources. In our educational service, an attachment starts as pending and becomes available after successful checks. That is a design option, not a required state name.
Protect storage and every download route
Microsoft recommends separating uploads from the application directory tree and disabling execution in the upload area. A separate directory does not determine who may read its contents: download access needs its own design.
Enforce permissions on the server for originals, previews and exports. A random filename makes a URL harder to guess but does not replace authorization. MDN describes Content-Disposition: attachment as a way to suggest downloading a response rather than displaying it inline. That header does not make a file private.
Test access to one educational document
Use your own test environment, a small harmless document and two test accounts in different projects. First confirm that the owner can open an existing file. Then request that same object from the other account and without signing in. This prevents confusing an access denial with a missing document.
Inspect the response contents as well as the status code: can an outsider obtain the original, preview image or exported contents? Define the expected behavior first. In our fictional service, all three are restricted to project members. Do not use customer documents or retrieve other people’s records during the test.
- The owner opens the original and preview, providing a successful control.
- A test user in another project receives no contents through the same link.
- A signed-out browser receives neither the private document nor its preview.
- After a planned deletion or access revocation, behavior matches the product policy.
Check failures and incomplete processing
In your own environment, use small safe files in accepted and unsupported formats. Check the permitted size boundary separately. The goal is a clear rejection, not excessive load or malicious content.
For the educational pending state, record what users see before checks finish and when processing fails. A failure must not silently turn into successful publication. Logs can record an operation ID and rejection reason; keep document contents, tokens and private links out of them.
Give the team a specific fix
If a private attachment is served to an outsider, start with server-side authorization on that read path. Align the policies for previews, originals and exports, review acceptance rules, then repeat both successful and denied scenarios. A useful ticket records the download URL, test context, expected result and actual result.
This review helps a team find the cause of a failure; it does not establish the safety of every processor and format. As a next step, you can request a free CheckMyApp audit of your own website or web application. Keep the specific upload feature and all its delivery paths in your team’s test plan.