Secure Node.js Exports with Presigned URLs

Summary

Pixel shares a practical guide to delivering large CSV, PDF, and ZIP exports from private object storage with short-lived presigned GET URLs. It covers bounded-memory workers, tenant authorization, unique object keys, and idempotent cleanup—key safeguards for protecting sensitive SaaS export data.

DEV Community

Node.js Presigned URLs: Private Object Storage for Large Export Files

Short answer: keep the export private, give the browser a short-lived presigned GET URL only after the file is complete, and make the object key unique per export attempt. For large B2B SaaS exports, that split matters more than the SDK choice: the worker handles bytes and retries, while the application controls who may request a link and when the artifact is deleted. The concrete flow is small. An authenticated user starts an export for one tenant. A worker validates and writes the CSV, PDF, or ZIP to a private bucket. The service records the object key and readiness, then signs a GET request for the browser. The browser downloads the bytes from storage; it never receives a storage credential. That last part is the boundary I want in an eval harness too. Export files can contain prompt fragments, retrieved passages, scores, or tool output. A link that stays valid forever is an access policy pretending to be a convenience. The artifact has three identities The first failure is a memory failure. Proxying a multi-gigabyte file through a Node.js route adds application bandwidth, buffering risk, and another timeout to the path. A direct storage download removes that hop, but the worker still needs a bounded-memory export strategy: stream rows into the writer, use multipart upload for genuinely large objects, and measure the time from first byte to completed object. The second failure is a lifecycle race. URL expiry and object deletion are separate clocks. An expired URL does not delete the object, and a lifecycle rule does not revoke a URL that was already copied. Keep the object private, record delete_at, and make cleanup idempotent. The deletion worker should be able to retry without turning a missing object into a user-visible incident. The third failure is tenant confusion. A filename is not an authorization check. Every request that creates a link must verify both the job owner and the job state; every retry must preserve the tenant association. Small tests. Expensive bugs avoided. I test this with two tenants, an expired URL, a duplicate delivery, a malformed row, and a refresh while rendering is still running. A long export can start as a CSV with a few thousand rows and finish as a ZIP containing several gigabytes, so a happy-path test that only checks HTTP 200 says very little about throughput or cleanup. A Python worker can make the handoff explicit Use a job record with tenant_id, job_id, object_key, state, and delete_at. The worker should write to a new key such as exports/tenant-42/job-724/attempt-2.csv, rather than racing to replace latest.csv. Once the upload succeeds, the API checks that the requesting principal owns the job and asks the storage SDK for a presigned GET URL. A 15-minute expiry is an example policy, not a universal answer. The example below keeps the storage operation in Python because that is where I usually keep the export worker. The same contract works with a Node.js API: ready is the handoff point, and the API returns a capability rather than proxying a large response through its own process. I've kept validation explicit because a notebook export that quietly emits a malformed row is much harder to diagnose after it becomes a customer-facing file. import csv
import io
import os
import uuid
from collections.abc import Iterable, Mapping

import boto3

FIELDS = ("run_id", "score", "model")

def create_export(
rows: Iterable[Mapping[str, object]], tenant_id: str
) -> tuple[str, str]:
materialized = list(rows)
for row_number, row in enumerate(materialized, start=1):
missing = [field for field in FIELDS if field not in row]
if missing:
raise ValueError(f"row {row_number} is missing: {', '.join(missing)}")

content = io.StringIO(newline="")
writer = csv.DictWriter(content, fieldnames=FIELDS)
writer.writeheader()
writer.writerows(
    {field: row[field] for field in FIELDS} for row in materialized
)

bucket = os.environ["EXPORT_BU...

Secure Node.js Exports with Presigned URLs
Powered by Readybot.io

The latest from Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …