DEV Community

AndersonBlake6857
AndersonBlake6857

Posted on

Node.js File Uploads: Presigned URLs, Proxy Backend, and Security (Fintech)

Short answer: for browser file upload of fintech training artifacts, use a presigned URL when the browser can send bytes directly to private object storage; keep a proxy backend for content inspection or policy decisions that must happen before storage. Track both paths with the same retention record so cost, latency, and security are measurable instead of guessed.

The system has one job: accept a training artifact, preserve its chain of custody, and delete it according to a reproducible policy. A proxy path is browser -> Node.js -> storage. A direct path is browser -> storage, with Node.js authorizing the transfer and recording metadata. That small difference moves bandwidth, trust, and failure handling to different places.

Keep it private.

The first decision is about control, not a URL

Path Pick it when What you pay for operationally Main security control
Presigned URL Artifacts can be scanned after arrival and the browser needs low latency Upload state, CORS, and orphan cleanup Short expiry, private bucket, narrow key and size policy
Proxy backend Bytes need synchronous inspection, transformation, or a single egress point Application bandwidth, connection limits, and backpressure Stream validation before forwarding; never buffer unbounded bodies
Two-step quarantine You need direct transfer plus a gate before promotion A second state and scanner queue Write to quarantine, scan, then copy or mark approved

Cost follows byte movement. In a proxy design, every upload crosses the application network and competes with API traffic. Direct transfer usually lowers that contention, but it does not remove storage requests, failed retries, or abandoned multipart sessions. Latency follows the same shape: a nearby storage region can beat a distant application region, while a required scan can make a proxy the faster end-to-end choice because it rejects bad input early.

Should a web app use presigned URLs or a proxy backend for upload control?

Start with an application-level upload record. It should contain a random upload ID, tenant ID, expected byte count, content type, object key, retention class, and state (issued, received, quarantined, approved, or expired). The object key must not be derived from an untrusted filename. Keep the bucket private; a presigned URL grants a temporary operation, not a public link.

Here is a deliberately small Node.js authorization endpoint. It returns a generic storage URL produced by your storage adapter, so the rest of the application does not depend on an SDK. The adapter must enforce the same bucket, key prefix, method, and maximum size that the record contains.

import crypto from "node:crypto";

type UploadIntent = {
  uploadId: string;
  objectKey: string;
  contentType: string;
  maxBytes: number;
  expiresAt: string;
  uploadUrl: string;
};

export async function createUploadIntent(tenantId: string, contentType: string): Promise<UploadIntent> {
  const uploadId = crypto.randomUUID();
  const objectKey = `training/${tenantId}/${uploadId}`;
  const maxBytes = 50 * 1024 * 1024;
  const expiresAt = new Date(Date.now() + 10 * 60 * 1000).toISOString();

  const uploadUrl = await storage.presignPut({
    key: objectKey,
    contentType,
    maxBytes,
    expiresAt
  });

  await uploads.insert({ uploadId, tenantId, objectKey, contentType, maxBytes, expiresAt, state: "issued" });
  return { uploadId, objectKey, contentType, maxBytes, expiresAt, uploadUrl };
}
Enter fullscreen mode Exit fullscreen mode

The browser uses the returned URL with the method and headers that were signed. After the request completes, the API performs a head check and compares the recorded byte count and checksum before moving the record to received. A 201 from your intent endpoint is not proof that the file arrived. That distinction prevents a support ticket from becoming a forensic exercise.

For a proxy, keep the same record and state machine. Stream the request, reject an announced or observed body above the limit, and cap concurrent streams per tenant. Return 413 for an oversized body, and emit a request ID that joins the API log to the storage log. I put the byte counter beside the stream, not in a later batch job; that is where a sudden 2 GB upload becomes visible.

What does the retention policy look like after upload?

Retention is a data contract, not a cleanup slogan. Store a policy version such as train-artifact-v3 with each upload. A worker can then calculate delete_at from the artifact's creation time and policy version, while a lifecycle rule in object storage provides a second, time-based backstop. AWS documents lifecycle management for expiring objects, and Google Cloud documents equivalent storage concepts; the exact rule syntax differs, so test it in a disposable bucket.

The quarantine path is useful when malware scanning or PII detection must precede approval. Direct upload still handles the bytes efficiently, but only the scanner can change quarantined to approved. A proxy is the better fit when that scan must happen before any durable object exists, or when regulation requires one controlled ingress address.

Measure a decision with the same fields on both paths: upload ID, tenant, byte range, storage region, elapsed milliseconds, retry count, final state, and retention policy version. Alert on issued records older than the URL expiry, quarantined records past their scan SLO, and multipart sessions with no progress. A dashboard that only counts HTTP 200 responses misses the abandoned half of the workflow.

My rule is boring and useful: compare p95 time-to-received, application egress bytes, scanner queue time, and rejected-byte rate for a week of representative artifacts. Your mileage may vary with enterprise proxies and browser CORS settings; a synthetic test from one laptop cannot settle that question. Also test expiry, tab refresh, duplicate completion, and a 413 response before launch.

This measurement takes more care than it first appears. For example, a direct upload can show a fast browser transfer while the quarantine scanner waits in a queue; a proxy can show higher request latency while rejecting a disallowed file before it reaches durable storage. Put both timestamps in the upload record, then report transfer time and approval time separately. Tag retries by cause (expired URL, client disconnect, policy rejection), and sample a few raw request IDs each day. That makes a cost or latency regression explainable: you can point to extra application egress, a slow region, or a scanner backlog instead of arguing from averages.

Measure twice.

When an upload fails, classify the boundary before changing the architecture. A browser-side CORS rejection is different from an expired signature, and both are different from a storage write that succeeded while the acknowledgement was lost. In the direct path, have the client send the upload ID back to the API after completion; the API can then perform its head check and safely accept a retry as an idempotent operation. In the proxy path, distinguish a client disconnect from an upstream timeout, and stop reading the request as soon as the policy limit is crossed. Record the first failure cause, not only the final retry status. A single artifact may produce three attempts: the first can fail at 8 MB because the tab was closed, the second can receive all bytes but miss its response, and the third can be rejected because the retention class changed while it was pending. Without per-attempt counters and a stable upload ID, those events collapse into one vague upload_failed metric. With them, an on-call engineer can decide whether to extend URL lifetime, tune connection pools, or fix a policy transition. The right response is often a small state-machine fix, not a wholesale move from direct upload to proxying.

The limits that should change your choice

The catch is that presigned URLs are delivery-simple, not policy-complete. They are a poor fit when every byte must be inspected synchronously, when clients cannot be trusted to reach storage, or when a single ingress point is a hard audit requirement. Stick with a proxy in those cases, accepting its throughput and scaling work.

Conversely, a proxy is not a free security upgrade. It enlarges the blast radius of a compromised app process and can turn a burst of large uploads into exhausted connections. Do not choose direct transfer for permanent public links, either; anonymous distribution is a separate access-control problem.

For this fintech workflow, I choose direct presigned transfer into quarantine, followed by a scanner and versioned retention policy. I choose a proxy only for the artifacts whose inspection or network boundary demands it. The decision is reversible when the upload record, metrics, and state transitions stay independent of the byte path.

References

Top comments (0)