When you hand out a presigned S3 URL, you are giving someone a signed authorization to read or write a specific object. The URL looks like a regular HTTPS link with query parameters attached: X-Amz-Algorithm, X-Amz-Credential, X-Amz-Date, X-Amz-Expires, X-Amz-SignedHeaders, and X-Amz-Signature. But the moment someone touches the link—extending the expiry, adding a tracking parameter, or passing it through a proxy that changes headers—the storage server returns 403 Forbidden (SignatureDoesNotMatch). I generated presigned URLs with Python's boto3 and systematically mutated parameters and headers to see what breaks and what passes.
How SigV4 presigning works under the hood
Standard AWS Signature Version 4 (SigV4) puts authentication into the HTTP Authorization header. Presigned URLs move that entire authentication proof into the query string so any browser, curl script, or client can access the object without holding your secret access key.
When boto3 generates a presigned URL, it constructs a Canonical Request string consisting of six lines:
HTTPMethod (e.g. GET or PUT)
CanonicalURI (e.g. /my-bucket/backup.tar.gz)
CanonicalQueryString (alphabetically sorted, URL-encoded query params)
CanonicalHeaders (lowercase header names and values in X-Amz-SignedHeaders)
SignedHeaders (semicolon-separated list, e.g. host or content-type;host)
nHashedPayload (for presigned URLs, always the literal 'UNSIGNED-PAYLOAD')|/code>The server hashes that canonical request with SHA-256, binds it to a StringToSign containing the timestamp and credential scope, and derives the final HMAC-SHA256 hex signature using your signing key. When the request arrives at the storage endpoint (like Amazon S3 or tport.space), the server reconstructs the exact same Canonical Request from the incoming HTTP request. If a single character differs, the hashes do not match, and you get 403 SignatureDoesNotMatch.
The 12 mutations tested: safe edits vs signature killers
To test what can and cannot be modified once a link is generated, I created baseline presigned GET and PUT URLs with boto3 against an S3 bucket (endpoint_url='https://s3.tport.space', region auto) and executed 12 targeted mutations. Here is what happened:
| # | Client Edit / Mutation | Target Component | Result Code | Why it passes or fails |
|---|---|---|---|---|
| 1 | Reorder query parameters (swap X-Amz-Expires and X-Amz-Date) | Query string | 200 OK (SAFE) | Server sorts all query parameters alphabetically by key prior to hashing. Order does not matter. |
| 2 | Extend link expiry (edit X-Amz-Expires=3600 to 7200) | Query parameter | 403 SignatureDoesNotMatch | X-Amz-Expires is hashed into the Canonical Query String. Changing the value alters the hash. |
| 3 | Append tracking query (add ?utm_source=email) | Query parameter | 403 SignatureDoesNotMatch | SigV4 includes all query parameters in the canonical hash. Extra parameters break it. |
| 4 | Add response override (inject response-content-disposition) | Query parameter | 403 SignatureDoesNotMatch | Response override headers must be signed when generating the URL; cannot be injected later. |
| 5 | Client sends Range header (Range: bytes=0-1048575) | Request header | 206 Partial Content (SAFE) | Range is not listed in X-Amz-SignedHeaders (only host). Unsigned headers are ignored. |
| 6 | Client custom User-Agent (User-Agent; my-app/2.0) | Request header | 200 OK (SAFE) | Not in signed headers. Clients and download managers can send any User-Agent freely. |
| 7 | Proxy rewrites Host header (e.g. to internal upstream IP) | Signed header | 403 SignatureDoesNotMatch | Host is always listed in X-Amz-SignedHeaders. Rewriting it breaks the canonical header check. |
| 8 | Path trailing slash added (/data.tar.gz to /data.tar.gz/) | CanonicalURI | 403 SignatureDoesNotMatch | URI path is the second line of the canonical request. Trailing slashes alter the URI hash. |
| 9 | PUT with signed Content-Type (upload matches image/png) | Signed header | 200 OK (SAFE) | Header exactly matches the value hashed into content-type;host during generation. |
| 10 | PUT without Content-Type (bare curl -T file) | Signed header | 403 SignatureDoesNotMatch | Header was signed in X-Amz-SignedHeaders, but the client omitted it from the request. |
| 11 | PUT with browser charset (image/png; charset=utf-8) | Signed header | 403 SignatureDoesNotMatch | Browsers often append ; charset=utf-8, mutating the exact signed header string. |
| 12 | Request after expiry window (time > date + expires) | Timestamp check | 403 AccessDenied | Signature is mathematically valid, but storage clock check fails: <Message>Request has expired</Message>. |
The 5 major traps when sharing presigned URLs
- Trap 1: The 'extend expiry' instinct. Frontend clients often see
X-Amz-Expires=3600(1 hour) and try to change it to86400(24 hours). BecauseX-Amz-Expiresis part of the Canonical Query String, modifying it immediately triggersSignatureDoesNotMatch. Expiry can only be set when generating the link. Furthermore, static access keys can sign URLs up to 604,800 seconds (7 days), but temporary STS session credentials cap validity at the credential lifetime (often 15 to 60 minutes), returningExpiredTokeneven if the URL's expiry parameter has days left. - Trap 2: Marketing and tracking query injection. Email software, Slack link unfurlers, and frontend routers love appending tracking parameters like
?utm_source=email,?ref=share, or cache-busters like?_t=1732439000. In standard HTTP APIs, unrecognized query parameters are ignored. In S3 SigV4, every single query parameter is canonicalized and hashed. Appending a tracking tag invalidates the entire signature. - Trap 3: The presigned PUT Content-Type trap. If you pass
ContentType='image/png'to boto3'sgenerate_presigned_url('put_object', ...), boto3 addscontent-typeintoX-Amz-SignedHeaders(resulting incontent-type;host). If a browser uploads usingfetch()and setsContent-Type: image/png; charset=utf-8, or if an Axios wrapper defaults toapplication/x-www-form-urlencoded, the upload fails withSignatureDoesNotMatch. If you want clients to upload arbitrary formats without signature errors, do not includeContentTypein the presigning call. - Trap 4: Reverse proxies and CDN Host header rewrites. The
Hostheader is always included inX-Amz-SignedHeaders. If your application server generates a presigned URL pointing tos3.tport.space, but you route client requests through an internal Nginx proxy that usesproxy_set_header Host $proxy_host;(rewriting it to an internal hostname or IR), the signature check fails immediately. Proxies passing presigned URLs must preserve the originalHostheader. - Trap 5: Space encoding: '+' vs '%20'. SigV4 requires RFC 3986 percent-encoding: spaces must be encoded as
%20, never+. If an object key or a response override header (likeresponse-content-disposition=attachment; filename="Monthly Report.pdf") has spaces encoded as+by an HTTP client, the server computes a different canonical string and rejects the request.
Safe modifications: what you can actually change
Notice in our test matrix that two common client operations are completely safe and will never break a presigned URL:
- HTTP Range requests for streaming and seeking: A client can send
Range: bytes=0-1048575to read the first 1 MB of a large video or archive. BecauseRangeis not inX-Amz-SignedHeaders, S3 evaluates the signature normally, honors the byte range, and responds with206 Partial Content. This allows resumable downloads and media seeking on presigned URLs without re-signing. - Query parameter reordering: If a client or proxy reorders the query parameters (for example, putting
X-Amz-Signaturefirst andX-Amz-Algorithmlast), the link still works. The SigV4 specification mandates that servers sort all query parameters alphabetically by URI-encoded key before calculating the canonical hash. - Client metadata headers: Headers such as
User-Agent,Accept,Accept-Encoding, andCache-Controlcan be freely added or changed by the client browser or download tool, provided they were not explicitly added toSignedHeadersat generation time.
Code recipes: generating robust presigned URLs with boto3
Here is how to generate presigned GET and PUT URLs in Python using boto3 that avoid signature traps:
import boto3
from botocore.client import Config
# Configure client with explicit SigV4 signing
s3 = boto3.client(
's3',
endpoint_url='https://s3.tport.space',
aws_access_key_id='YOUR_KEY_ID',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='auto',
config=Config(signature_version='s3v4')
)
# 1. Robust Presigned GET with custom download filename
# Response overrides MUST be passed inside Params so they are signed into the query string
get_url = s3.generate_presigned_url(
'get_object',
Params={
'Bucket': 'my-bucket',
'Key': 'reports/financial-2026.pdf',
'ResponseContentDisposition': 'attachment; filename="financial-2026.pdf"',
'ResponseContentType': 'application/pdf'
},
ExpiresIn=3600 # 1 hour
)
# 2. Robust Presigned PUT for direct browser uploads
# To avoid brittle signed header mismatches from browser Content-Type variations,
# omit ContentType from Params unless you strictly enforce exact MIME in the frontend
put_url = s3.generate_presigned_url(
'put_object',
Params={
'Bucket': 'my-bucket',
'Key': 'uploads/user-123/document.dat'
},
ExpiresIn=1800 # 30 minutes
)How to debug a 403 SignatureDoesNotMatch error
If you hit a signature mismatch, do not guess what failed. Amazon S3 and S3-compatible endpoints like tport.space return detailed error XML when signature verification fails with a test request:
When you run curl -i "<presigned-url>" on a failing request, the XML response body contains:
<CanonicalRequest>: The exact 6-line canonical string the server reconstructed from your incoming HTTP request.<StringToSign>: The exact string the server hashed with your credentials.<SignatureProvided>: The signature value from your query string.
By comparing the server's CanonicalRequest against what your signing script generated, you can spot the mismatch in seconds: whether an extra query parameter snuck in, the Host header was rewritten, or a signed header like content-type was altered by the client.