Architecture diagram illustrating S3 presigned PUT generation with short TTL, explicit Content-Type validation, and Content-Length-Range size restrictions tested via curl

When webhooks, ingestion pipelines, or mobile apps upload files directly to an S3-compatible bucket, proxying the upload through your web backend wastes server memory, ties up worker connections, and inflates cloud compute bills. Direct client-to-bucket uploads solve the bottleneck.

The vulnerability lies in how those upload URLs are generated. An unconstrained presigned PUT URL gives anyone who holds the link permission to upload up to 5 TB of arbitrary data—from ransomware binaries to multi-gigabyte disk-exhaustion bombs. Securing upload drops requires locking down Content-Type headers, enforcing strict size limits, and slashing token lifetimes.

Unconstrained vs hardened presigned upload drops

Here is what changes when you move from default SDK presigned PUT links to hardened, cryptographically enforced upload policies:

Security controlDefault presigned PUT (unconstrained)Hardened webhook drop (enforced)Risk reduction
Payload size limitUp to 5 TB (bucket object limit)10 KB – 50 MB strict boundaryPrevents storage exhaustion denial-of-service
Content-Type validationIgnored / unverifiedLocked to expected MIME (e.g. application/pdf)Blocks executable, script, and HTML uploads
URL expiration (TTL)24 hours (86,400 seconds)300 seconds (5 minutes)Closes exposure window if URLs leak into logs
Tamper responseHTTP 200 OK (payload accepted)HTTP 403 Forbidden (signature mismatch)Immediate gateway refusal at the edge
Access key riskZero credentials exposed to clientZero credentials exposed to clientMaintains zero-trust bucket architecture
Replay protectionReusable until expiry timestampSingle-use / tight 5-minute windowPrevents unauthorized object overwrites

How SigV4 header locking works

AWS Signature Version 4 (SigV4) does not just sign the HTTP method and object key. It also calculates a signature over the list of headers specified in the <code>X-Amz-SignedHeaders</code> parameter:

  • Content-Type signing: When your server includes ContentType='application/pdf' during URL generation, S3 inserts content-type into X-Amz-SignedHeaders. If the client tries to upload bad.sh as text/plain or application/octet-stream, the storage API immediately rejects the request with 403 SignatureDoesNotMatch.
  • Exact size enforcement: Including ContentLength=file_bytes forces the client to send that exact byte count. An attacker attempting to stream a 50 GB payload fails the header check.
  • Dynamic size boundaries: For clients where the exact size is not known in advance, S3 presigned POST policies enforce a strict range via ["content-length-range", 10240, 52428800] (10 KB to 50 MB).
  • Short expiration TTL: Reducing token lifetime from the default 3,600s or 86,400s down to 300s (5 minutes) ensures webhook callbacks must use the URL immediately or request a fresh ticket.

Generating hardened presigned URLs in Python

Use the following Python implementation with <code>boto3</code> to generate signed PUT URLs with enforced Content-Type, Content-Length, and short expiration:

python
import boto3
from botocore.config import Config

def create_hardened_upload_url(
    bucket_name: str,
    object_key: str,
    content_type: str = "application/pdf",
    expected_bytes: int = 1048576,  # 1 MB
    ttl_seconds: int = 300,
    endpoint_url: str = "https://s3.tport.space"
) -> str:
    """Generate a time-bound presigned PUT URL locking Content-Type and Content-Length."""
    s3_client = boto3.client(
        "s3",
        endpoint_url=endpoint_url,
        config=Config(signature_version="s3v4")
    )

    # Any param added here is added to X-Amz-SignedHeaders and cryptographically locked
    url = s3_client.generate_presigned_url(
        ClientMethod="put_object",
        Params={
            "Bucket": bucket_name,
            "Key": object_key,
            "ContentType": content_type,
            "ContentLength": expected_bytes,
        },
        ExpiresIn=ttl_seconds,
        HttpMethod="PUT"
    )
    return url

Testing attack scenarios with curl

We tested four curl scenarios against our hardened endpoint to verify rejection behavior:

bash
# Test 1: Legitimate upload with correct headers (Succeeds)
curl -s -i -X PUT "$SIGNED_URL" \
  -H "Content-Type: application/pdf" \
  -H "Content-Length: 1048576" \
  --data-binary @clean_invoice.pdf | head -n 1
# HTTP/1.1 200 OK

# Test 2: Attacker changes Content-Type to malicious executable (Fails)
curl -s -i -X PUT "$SIGNED_URL" \
  -H "Content-Type: application/x-executable" \
  -H "Content-Length: 1048576" \
  --data-binary @exploit.bin | head -n 1
# HTTP/1.1 403 Forbidden (SignatureDoesNotMatch)

# Test 3: Attacker attempts to flood with 2 GB payload (Fails)
curl -s -i -X PUT "$SIGNED_URL" \
  -H "Content-Type: application/pdf" \
  -H "Content-Length: 2147483648" \
  --data-binary @large_dump.iso | head -n 1
# HTTP/1.1 403 Forbidden (SignatureDoesNotMatch)

# Test 4: Attacker replays link after 300 seconds TTL lapses (Fails)
sleep 305
curl -s -i -X PUT "$SIGNED_URL" \
  -H "Content-Type: application/pdf" \
  -H "Content-Length: 1048576" \
  --data-binary @clean_invoice.pdf | head -n 1
# HTTP/1.1 403 Forbidden (Request has expired)

Worked math: storage exhaustion bill shock

Suppose a rogue webhook actor or unauthenticated client discovers an open presigned upload drop that lacks size limits. Here is how quickly storage costs compound compared to an enforced 50 MB boundary:

Attack volumePayload sizeIngested storageMonthly cost at $0.023/GB (AWS S3)Hardened drop (50 MB limit)Monthly cost with 50 MB cap
100 uploads10 GB dumps1,000 GB (1.0 TB)$23.00 / mo5.0 GB total$0.12 / mo
500 uploads50 GB dumps25,000 GB (25.0 TB)$575.00 / mo25.0 GB total$0.58 / mo
2,000 uploads100 GB dumps200,000 GB (200.0 TB)$4,600.00 / mo100.0 GB total$2.30 / mo

A strict 50 MB size ceiling neutralizes storage bill spikes by over 99.9%, while immediate 300-second token expirations prevent attackers from stockpiling reusable URLs.

Storage architecture on tport.space

<b>tport.space</b> provides high-performance, S3-compatible object storage with public files and zero egress fees. By combining S3 SigV4 presigned PUT drops for uploads with public buckets for downstream delivery, you build cost-effective file ingestion pipelines with zero per-gigabyte egress fees on downloads.

Check our companion guides for bucket caching and architecture best practices:

Secure your file drops and serve public files from S3-compatible storage with zero egress fees.

Deploy on tport.space