Secure Private Document Uploads in Startup Apps

Résumé

Pixel’s announcement explains a quarantine-first design for securing uploaded documents in startup apps. It covers private buckets, ownership checks in the application, upload validation, and short-lived signed download URLs, plus tests for pending files, expired links, retries, and access isolation.

DEV Community

Private Access for Uploaded Documents in Startup Apps: A Quarantine-First Design

Short answer: keep uploaded documents in a private bucket, make the application the authorization authority, and issue short-lived signed URLs only after it confirms ownership and document state. That decision is less about picking the “simplest” S3-compatible alternative and more about keeping the trust boundary small. The bucket stores bytes. The Python app decides who can ask for them. A quarantine step prevents an upload that merely exists from becoming a document the rest of the product can process. What should a startup app verify before granting private document access? The data flow is straightforward. A browser asks the API for an upload intent; the API authenticates the user, creates an opaque object key, records a pending row, and returns a constrained upload grant. A worker checks the completed object for size, media type, and application policy before marking it ready. A download follows the reverse path: the API checks the caller against the row, then signs a GET for a short window. A signed URL is a bearer capability. Anyone who gets the string can use it until expiry, so query strings belong in neither analytics events nor ordinary request logs. Store the stable object key, never the URL, and mint a fresh URL after each authorization decision. Keep the bucket private even if every current caller is “trusted.” No public shortcut. My eval harness treats these as invariants: Alice can retrieve her ready document; Bob cannot obtain Alice’s URL; an expired URL is rejected; a pending object is not downloadable; duplicate completion events are harmless; and deleting the application row stops new URL issuance. I add a zero-byte upload, a filename containing quotes and non-ASCII characters, a client retry, and a 25 MB boundary case. Your mileage may vary on expiry duration because mobile networks differ, but the ownership check should not. The application owns identity, metadata, lifecycle, and audit events. The object service owns durable bytes and signature validation. A worker can inspect content, but it never grants user access. This separation also makes an S3-compatible alternative useful: the protocol is an adapter boundary, not the policy engine. Put a small Python boundary in front of the object service The example below uses the standard S3 signing shape so the application boundary stays visible. The endpoint is configuration; business code deals in document IDs. Direct browser uploads keep large bodies out of the API process. import os
import sqlite3
import uuid
from contextlib import closing

import boto3
from fastapi import Depends, FastAPI, HTTPException
from pydantic import BaseModel

app = FastAPI()
s3 = boto3.client(
"s3",
endpoint_url=os.environ.get("S3_ENDPOINT_URL"),
region_name=os.environ.get("S3_REGION", "us-east-1"),
)
BUCKET = os.environ["DOCUMENT_BUCKET"]
DB_PATH = os.environ.get("DOCUMENT_DB", "documents.db")

def current_user_id() -> str:
# Replace with the app's verified session or token identity.
return "user_123"

def initialize() -> None:
with closing(sqlite3.connect(DB_PATH)) as db:
db.execute(
"CREATE TABLE IF NOT EXISTS documents "
"(id TEXT PRIMARY KEY, owner_id TEXT, object_key TEXT, status TEXT)"
)

class UploadRequest(BaseModel):
content_type: str

@app.post("/documents/upload-intent")
def create_upload_intent(
request: UploadRequest, user_id: str = Depends(current_user_id)
) -> dict:
document_id = str(uuid.uuid4())
object_key = f"users/{user_id}/{document_id}"
with closing(sqlite3.connect(DB_PATH)) as db:
db.execute(
"INSERT INTO documents VALUES (?, ?, ?, 'pending')",
(document_id, user_id, object_key),
)
db.commit()

upload = s3.generate_presigned_post(
    Bucket=BUCKET,
    Key=object_key,
    Fields={"Content-Type": request.content_type},
    Conditions=[
        {"Content-Type": request.content_type},
        [...

Secure Private Document Uploads in Startup Apps
Powered by Readybot.io

Les dernières actus de 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 …