Skip to content
BDOT SOFTWAREBDOT Software

Insights / Security

Secure File Upload for Web Applications

File uploads combine untrusted bytes, storage, access control, and background processing. Validate each boundary instead of trusting the filename or browser.

Kiran Bandarupalli · 25 Oct 2026 · 3 min read

A mobile device representing a client interface that can submit files to a web application

Secure file upload for web applications is not just a form field. It gives an untrusted client a path to consume storage, trigger parsers, and possibly expose content to other users. File upload security for business applications depends on the complete lifecycle, from upload through download and deletion: validate every upload, scan for malware, store files privately, and enforce access at every stage.

Authorize and bound the request

Check that the user may upload to the specific record before accepting bytes. Enforce a request-size limit at the proxy and application layers; do not rely only on a browser-side limit. Apply per-user or per-tenant quotas if the product needs them. Stream large files rather than buffering unbounded content in memory.

Do not trust the filename or MIME header

Generate an opaque storage key on the server. Treat the original name as display metadata and escape it wherever it is rendered. Browser-provided content type is a hint, not proof. Inspect file signatures and allow only formats the product needs. For documents that require parsing or conversion, run that work in a constrained worker with time, memory, and filesystem limits.

Store privately by default

Keep uploads outside the public web root or in a private object store. To download, authorize access to the underlying record and issue a short-lived, signed URL or stream the file through a checked endpoint. Set safe content disposition and avoid serving active content from the same origin as the application when possible.

Scan and process safely

Use malware scanning where the threat model and file types warrant it. Treat archive extraction as especially sensitive: defend against path traversal, excessive expansion, and nested archives. Make processing asynchronous for expensive operations, and track a clear state such as received, scanning, available, rejected, or failed.

  • Use CSRF protection where cookie authentication is in play.
  • Log an opaque file ID and processing outcome, not file contents.
  • Define retention and deletion behavior, including backups.
  • Test oversized files, spoofed types, duplicate names, and unauthorized downloads.

File-upload security checklist for business applications

Use this as the go-live check before a new upload feature ships. The companion file-upload security checklist for business applications walks through the same checks from the launch side.

  • Authorize the upload against the specific record before accepting any bytes.
  • Enforce a size limit at the proxy and in the application, not only in the browser.
  • Detect the real file type from its magic bytes and allow only the formats the product needs.
  • Store the file under an opaque, server-generated key, never under the user-supplied name.
  • Scan uploads where the threat model warrants it, and isolate parsing and extraction.
  • Serve downloads only through authorized, expiring links, never from a public path.
  • Log an opaque file ID and outcome, define retention, and test unauthorized downloads before launch.

The validation core looks like this in Node.js:

import { fileTypeFromBuffer } from 'file-type';

const ALLOWED = new Set(['image/jpeg', 'image/png', 'application/pdf']);
const MAX_BYTES = 10 * 1024 * 1024;

async function acceptUpload(buffer, claimedName) {
  if (buffer.length > MAX_BYTES) throw new Error('file too large');
  const detected = await fileTypeFromBuffer(buffer); // magic-byte sniffing
  if (!detected || !ALLOWED.has(detected.mime)) {
    throw new Error('type not allowed');
  }
  // Opaque storage key: the original name is display metadata, never a path.
  const storageKey = crypto.randomUUID() + '.' + detected.ext;
  return { mime: detected.mime, storageKey };
}

For teams running uploads as part of a larger platform, the same discipline belongs in cloud and DevOps delivery: size limits, scanning, and private storage are production controls, not one-off code checks. If uploads are part of custom software you are building, treat this checklist as a launch gate, and talk to us if you want a second pair of eyes on it.

Security is not achieved by a single antivirus call. It comes from minimizing accepted formats, isolating parsers, enforcing access at every stage, and giving operators a way to investigate failures without exposing private files.