From Unauthenticated Upload to Stored XSS: Breaking a Production S3 Upload Flow
An unauthenticated upload endpoint issued AWS S3 presigned URLs to anyone, and the uploader could set the Content-Type to SVG. The production CloudFront distribution served the stored SVG as image/svg+xml without nosniff or attachment disposition, so JavaScript executed in the CDN origin when a victim opened the asset URL.
Published on medium.com
Bug Bounty
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
The target was an e-commerce and gifting application that let users work with image assets. The feature under test was its image upload flow: the frontend exposed a tRPC API, and the upload procedure of interest was public.imageUpload.initiateUpload. The server generated an AWS S3 presigned PUT URL, the client uploaded the file directly to S3, and the resulting object was delivered to users through the application's production CloudFront distribution.
The researcher's framing is worth keeping in mind throughout: the bug was not one obvious mistake but a chain of individually small decisions. An unauthenticated user could obtain a production S3 upload grant, choose the object's Content-Type, and have CloudFront serve the stored SVG as image/svg+xml without X-Content-Type-Options: nosniff or Content-Disposition: attachment. That turned an upload primitive into stored JavaScript execution on the CDN origin.
The full chain, as the author draws it:
Unauthenticated user ↓CSRF token ↓Unauthenticated upload initiation ↓AWS S3 presigned PUT URL ↓Attacker controls Content-Type ↓Upload malicious SVG ↓Production S3 asset storage ↓CloudFront serves SVG as image/svg+xml ↓Browser renders SVG ↓JavaScript executes
Setup
No accounts, roles, tool versions or special tooling are described. The testing was done with ordinary HTTP requests against the application and a real browser to verify execution. The preconditions that mattered were properties of the target itself:
- A tRPC endpoint for upload initiation reachable without a session.
- A CSRF endpoint that issues tokens to anyone.
- A presigned S3 URL whose signature did not bind
Content-Type. - A CloudFront distribution serving uploaded objects inline.
The author's starting checklist for any upload feature was:
Who can upload?What can they upload?Where is the file stored?Who controls the filename?Who controls the Content-Type?How is the file served?Which domain serves it?Can the browser execute it?
A secure implementation, in this view, needs independent controls stacked together:
Authentication +Authorization +File validation +Content-Type validation +Safe storage +Safe response headers
Finding it
The upload API was visible in the frontend as a tRPC procedure:
POST /api/trpc/public.imageUpload.initiateUpload?batch=1
The name public.imageUpload.initiateUpload raised an immediate authorization question: did "public" mean publicly readable, or intentionally available to unauthenticated users? The author treated that as something to determine by testing rather than by reading the name.
The first test was the CSRF endpoint:
GET /api/auth/csrf
The application returned a CSRF token. That was notable because a CSRF token is not an authentication credential: it can show that a request came through the application's expected flow, but it does not necessarily identify or authorize a user. So the next step was to take the token, stay logged out, and call the upload initialization endpoint.
Exploitation
Step 1: initiate an upload without a session
The upload initialization request was accepted. The request, as the author presents it conceptually:
POST /api/trpc/public.imageUpload.initiateUpload?batch=1Host: target.examplex-csrf-token: <CSRF_TOKEN>Content-Type: application/json
The x-csrf-token header carries the token from /api/auth/csrf; no session cookie or authenticated identity was required. This was the first major finding: the server was willing to start an upload for an anonymous caller.
Step 2: receive a presigned S3 URL
The response contained a presigned AWS S3 upload URL. A presigned URL grants temporary permission to perform a specific operation on an AWS resource without handing over the underlying AWS credentials. The author's simplified model:
Application | | Generates presigned URL vAWS S3 | | Temporary permission vUploader
That pattern is legitimate when the server validates the user first:
Authenticated user ↓Request upload ↓Server validates user ↓Server generates restricted presigned URL ↓User uploads image
Here the first step was effectively:
Anonymous Internet user ↓Request upload permission ↓Receive production S3 presigned URL
In other words, the application itself issued a write capability to an unauthenticated requester.
Step 3: inspect the signature
The presigned URL contained AWS Signature Version 4 parameters. One stood out:
X-Amz-SignedHeaders=host
Only the host header was signed. The signature therefore did not bind the uploaded object's Content-Type. The question that followed: if the application believes it is generating an image upload, can the attacker pick a different Content-Type on the actual PUT?
Step 4: change the Content-Type
The flow appeared to expect image content. A safe implementation would allow something like:
image/pngimage/jpegimage/webp
and reject executable formats such as:
image/svg+xmltext/htmlapplication/xhtml+xml
Because the presigned request did not cryptographically bind the Content-Type, the upload could specify:
Content-Type: image/svg+xml
while still using the valid presigned URL. That gave the second primitive:
Unauthenticated user ↓Presigned PUT ↓Attacker-controlled Content-Type
Step 5: choose a minimal SVG payload
SVG was the interesting test because it is both an image format and an XML document that can carry active content. The payload used to demonstrate execution without attempting to steal anything:
<svg xmlns="http://www.w3.org/2000/svg"> <script>alert("XSS")</script></svg>
The principle applied: use the smallest payload that proves the vulnerability. No credential theft, cookie extraction or account takeover testing was performed.
Step 6: write the object to production S3
The upload was performed against the presigned URL:
PUT <presigned-upload-url>Content-Type: image/svg+xml
<SVG payload>
S3 returned:
HTTP/1.1 200 OK
This was a real write into the production asset storage. The object key was generated by the server using a UUID-style identifier, which meant the test did not demonstrate path traversal, arbitrary object naming, overwriting of existing files or predictable filename attacks. The vulnerability was specifically the unauthenticated ability to create attacker-controlled objects.
Step 7: follow the object to CloudFront
An S3 PUT returning 200 does not by itself mean XSS. The next question was how the uploaded object is delivered. The upload response provided a public asset URL on the application's CloudFront distribution, so the chain became:
S3 ↓CloudFront ↓Browser
Opening the URL in a real browser returned:
HTTP/1.1 200 OKContent-Type: image/svg+xml
The response did not include:
X-Content-Type-Options: nosniff
and did not force a download with:
Content-Disposition: attachment
The browser therefore treated the object as an SVG document.
Step 8: confirm execution
The uploaded SVG carried a simple execution marker. When the CloudFront URL was opened, the browser ran the script and displayed an alert:
alert("XSS on " + document.domain)
The proven chain was:
Attacker-controlled file ↓Stored in production infrastructure ↓Served by production CloudFront ↓Browser interprets as SVG ↓JavaScript executes
This was no longer merely an unauthenticated file upload; it was unauthenticated stored script execution on the CDN origin.
Step 9: reproduce with fresh objects
To rule out an accidental or pre-existing file, the process was repeated with fresh uploads and unique object identifiers. It was reproducible, with the same sequence:
CSRF token ↓Upload initiation ↓Presigned URL ↓SVG upload ↓CloudFront URL ↓200 image/svg+xml ↓JavaScript execution
Step 10: establish the execution origin
The script executed on the CloudFront origin:
d1rxz8nuri2eg6.cloudfront.net
not on the application origin:
gifts.tatesbakeshop.com
Those are different origins, so the author did not claim that authenticated users of the application could have their sessions stolen. The demonstrated impact was:
Attacker ↓Upload malicious SVG ↓CloudFront ↓Victim opens URL ↓JavaScript executes ↓CDN-origin context
Step 11: test escalation towards the application origin
The next question was whether CDN-origin execution could cross into the application origin. The application's image optimization path rejected SVG because SVG handling was disabled there:
Uploaded SVG ↓Next image optimizer ↓SVG rejected
No other obvious same-origin asset passthrough was exposed that would turn the CDN-origin XSS into application-origin XSS. The application's session cookies were also configured with protections including:
Host-SecureHttpOnly
so JavaScript on the CDN origin could not simply read them. This bounded the impact.
Step 12: note the CSP dependency without inflating it
The application's Content Security Policy included the upload asset infrastructure among its allowed script and resource sources. That is a dangerous architectural dependency: if an HTML or markup injection sink later appears on the application origin, an attacker-controlled upload origin that CSP explicitly trusts becomes far more useful. The author did not claim this as an existing exploit path, because the required application-origin injection was never demonstrated. Demonstrated impact was kept separate from hypothetical future impact.
Root cause
The design failed on several independent assumptions, each of which the testing disproved:
- Only legitimate users can request upload permissions. False: the initiation endpoint was reachable without an authenticated account.
- The upload URL only permits safe image content. False: the attacker controlled the
Content-Type. - Uploaded SVG will be downloaded rather than executed. False: CloudFront returned
Content-Type: image/svg+xmlwithout a download disposition. - The browser will protect users from incorrectly served content. False: without
nosniff, the response was treated as an SVG document. - XSS on the asset infrastructure automatically means application account compromise. Not demonstrated: the CDN origin was cross-origin from the application.
At the design level, the core mistake was issuing a production write capability to anonymous users. The presigned URL signed only host, so the client could freely transform a safe image upload into an executable document after receiving the grant. Delivery then compounded it: the CDN served user-controlled content inline, with a type the browser renders as a document, and without headers that would have forced a download or blocked sniffing.
Impact
An unauthenticated Internet user could obtain a production S3 upload capability, upload attacker-controlled SVG content, and have that content served by the production CloudFront infrastructure in an executable format. When a victim opens the resulting asset URL, JavaScript runs in the CDN origin's security context.
The author explicitly did not claim:
- application account takeover
- session-cookie theft
- access to other users' accounts
- arbitrary S3 object overwrite
- path traversal
- access to AWS credentials
- modification of existing assets
- access to private application data
- application-origin XSS
- customer data compromise
The demonstrated vulnerability was:
Unauthenticated production upload+Attacker-controlled executable SVG+CDN delivery+Browser JavaScript execution
with execution confined to the CDN origin. The conditions for impact are that the victim opens the attacker-supplied asset URL; the application's session cookies were configured with protections including Host-SecureHttpOnly, and no same-origin passthrough was found.
Fix
The report recommends remediation; it does not describe changes that were actually deployed.
- Require authentication. Do not issue production S3 upload grants to anonymous users unless anonymous uploads are explicitly intended. Authenticate and authorize the upload request before generating the presigned URL.
- Restrict allowed content types. Use a strict server-side allowlist such as
image/png,image/jpeg,image/webpif those are the only formats needed. Do not rely on the client to supply a safe MIME type. - Bind upload properties to the signature. Security-sensitive properties should be constrained by the server-generated signature where appropriate, so the client cannot turn a safe image into an executable document after receiving the grant.
- Add defensive response headers. Serve user-uploaded content with
X-Content-Type-Options: nosniffandContent-Disposition: attachmentwhere appropriate. A CloudFront response-headers policy can enforce this consistently. - Use a dedicated untrusted-content origin. Separate user content from the application, for example
app.example.comfor the trusted application anduploads.exampleusercontent.combacked by S3 and CloudFront for untrusted content, so the application never has to trust uploads as part of its own origin. - Review CSP dependencies. Avoid trusting user-controlled upload origins in the application's CSP; treat them as hostile.
The author stresses that blocking SVG alone is not the complete fix. It addresses this demonstration but not the underlying problem of anonymous users holding production write capability. Authorization comes first, then file-type policy, then delivery policy: security should be layered, and headers should supplement rather than replace server-side validation.
Variants to test
- Anonymous upload initiation. Remove authentication and call the initiation endpoint directly. A positive result is a presigned URL returned to a caller with no session.
- Unsigned
Content-Type. InspectX-Amz-SignedHeaderson presigned URLs. If it lists onlyhost, try a PUT with a differentContent-Typethan the application expects; a positive result is a 200 with the object stored under the chosen type. - Inline SVG delivery. Request the resulting asset URL and check the response. A positive result is
Content-Type: image/svg+xmlwith noX-Content-Type-Options: nosniffand noContent-Disposition: attachment, followed by script execution in a real browser. - Other active types. Where the server accepts them, try
text/htmlandapplication/xhtml+xmlin the same way, checking whether the browser renders the stored object as a document. - Same-origin passthrough. Look for image proxies, optimizers or asset routes on the application origin that fetch from the upload bucket. A positive result is the uploaded SVG being served from the application origin, which would raise the impact from CDN-origin to application-origin execution.
- CSP trust of the upload origin. Check whether the application's CSP allows the asset host as a script or resource source. A positive result is the upload origin appearing among the CSP's allowed script or resource sources, a latent escalation path if an injection sink exists.
- Object key control. Test whether the client can influence the object key. A positive result is a client-chosen or predictable key, opening overwrite or naming attacks that this target did not have.
- Presigned URL scope. Inspect
X-Amz-Expires,X-Amz-CredentialandX-Amz-Signatureto understand lifetime and permissions. InspectX-Amz-Expires,X-Amz-CredentialandX-Amz-Signatureto understand lifetime and permissions.
The author's reusable checklist for upload hunting, reproduced as given:
[ ] Is authentication required?[ ] Is authorization checked server-side?[ ] Can anonymous users obtain presigned URLs?[ ] Can users choose the object key?[ ] Can users overwrite existing objects?[ ] Is the filename predictable?[ ] Is the extension validated?[ ] Is MIME type validated server-side?[ ] Is Content-Type cryptographically bound?[ ] Can SVG be uploaded?[ ] Can HTML be uploaded?[ ] Can XML be uploaded?[ ] Can polyglot files be uploaded?[ ] Is the file transformed before serving?[ ] Which hostname serves the file?[ ] Is it same-origin with the application?[ ] What Content-Type is returned?[ ] Is nosniff enabled?[ ] Is Content-Disposition configured?[ ] Is CSP involved?[ ] Does the browser execute the content?[ ] Can execution reach the application origin?[ ] Can the file be used for phishing?[ ] Can existing objects be overwritten?
The closing lesson: when you find a file upload, do not stop at whether you can upload. Follow the object from creation to delivery, through create, store, transform, serve and render, and ask at each stage who authorized it, what the presigned URL actually constrained, and which origin ends up executing your code.
What happened, in plain words
Imagine a shop that lets people upload pictures of gifts. The shop keeps those pictures in a big online storage service (Amazon S3) and shows them to visitors through a delivery network (CloudFront). The researcher found that anyone on the internet, without logging in, could ask the shop for permission to upload a file. The shop would hand back a special, temporary upload link. The researcher then used that link to upload an SVG file, an image format that can also contain a script. When someone opened the link to that file, the browser ran the program. That is called stored cross-site scripting (XSS). The program ran on the delivery network's address, not on the shop's own address, and the shop's login cookies were configured with protections including Host-SecureHttpOnly. The researcher was careful to say exactly what was and was not proven.
The full chain, as the author draws it:
Unauthenticated user ↓CSRF token ↓Unauthenticated upload initiation ↓AWS S3 presigned PUT URL ↓Attacker controls Content-Type ↓Upload malicious SVG ↓Production S3 asset storage ↓CloudFront serves SVG as image/svg+xml ↓Browser renders SVG ↓JavaScript executes
This is a diagram of steps, read from top to bottom. Each arrow means "then". An unauthenticated user is someone who has not logged in. A CSRF token is a small string the site gives out to prove a request came through its own pages (explained later). Upload initiation means asking the server to start an upload. A presigned PUT URL is a temporary, signed link that allows one specific upload to S3. Content-Type is a label that tells the browser what kind of file it is. SVG is an image format that can contain code. CloudFront is the delivery network. The browser renders the SVG, and the JavaScript inside it executes.
Setup
The report does not describe any special tools, accounts or versions. The testing used ordinary web requests and a real browser to check that the code actually ran. What mattered were four properties of the target itself:
- A tRPC endpoint for upload initiation reachable without a session.
- A CSRF endpoint that issues tokens to anyone.
- A presigned S3 URL whose signature did not bind
Content-Type. - A CloudFront distribution serving uploaded objects inline.
A tRPC endpoint is a kind of web API: a URL that a website's frontend calls to ask the server to do something. A session is the state of being logged in. A CSRF endpoint is a URL that hands out CSRF tokens. A signature is a cryptographic stamp that proves the server created a link and that it has not been altered. "Bind" means the signature covers a particular detail, so changing that detail invalidates the signature. "Inline" means the browser displays the file directly instead of downloading it.
The author's starting checklist for any upload feature was:
Who can upload?What can they upload?Where is the file stored?Who controls the filename?Who controls the Content-Type?How is the file served?Which domain serves it?Can the browser execute it?
Each line is a question to ask before testing. "Who can upload?" means: does the site require a login? "What can they upload?" means: are there restrictions on file types? "Where is the file stored?" means: which storage service and bucket? "Who controls the filename?" means: can the uploader choose the name, or does the server generate it? "Who controls the Content-Type?" means: can the uploader set the label that says what kind of file it is? "How is the file served?" means: with which response headers? "Which domain serves it?" means: the address in the browser bar. "Can the browser execute it?" means: will the browser run code inside the file?
A secure implementation, in this view, needs independent controls stacked together:
Authentication +Authorization +File validation +Content-Type validation +Safe storage +Safe response headers
Authentication means proving who you are (logging in). Authorization means checking whether you are allowed to do this particular thing. File validation means checking the file's actual content. Content-Type validation means checking the label matches the content. Safe storage means storing files where they cannot harm the main site. Safe response headers means telling the browser how to treat the file when serving it. Each plus sign means "and also". If several of these are missing, an upload feature can become dangerous.
Finding it
The upload API was visible in the frontend as a tRPC procedure:
POST /api/trpc/public.imageUpload.initiateUpload?batch=1
This is an HTTP request line. POST is the method used to send data. /api/trpc/public.imageUpload.initiateUpload?batch=1 is the path and query. public.imageUpload.initiateUpload is the procedure name. batch=1 is a query parameter in the request. The name raised an immediate authorization question: did "public" mean publicly readable, or intentionally available to unauthenticated users? The author treated that as something to determine by testing rather than by reading the name.
The first test was the CSRF endpoint:
GET /api/auth/csrf
GET means "fetch this". /api/auth/csrf is the path. The application returned a CSRF token. That was notable because a CSRF token is not an authentication credential: it can show that a request came through the application's expected flow, but it does not necessarily identify or authorize a user. Think of a CSRF token like a ticket from a cloakroom: it proves you were at the cloakroom, but it does not prove who you are. So the next step was to take the token, stay logged out, and call the upload initialization endpoint.
Exploitation
Step 1: initiate an upload without a session
The upload initialization request was accepted. The request, as the author presents it conceptually:
POST /api/trpc/public.imageUpload.initiateUpload?batch=1Host: target.examplex-csrf-token: <CSRF_TOKEN>Content-Type: application/json
This is a simplified HTTP request. The first line is the method and path. Host: target.example says which server to talk to. x-csrf-token: <CSRF_TOKEN> carries the token from /api/auth/csrf. Content-Type: application/json says the body is JSON (a text format for structured data). No session cookie or authenticated identity was required. This was the first major finding: the server was willing to start an upload for an anonymous caller.
Step 2: receive a presigned S3 URL
The response contained a presigned AWS S3 upload URL. A presigned URL grants temporary permission to perform a specific operation on an AWS resource without handing over the underlying AWS credentials. Think of it like a one-time visitor pass to a storage room: it lets you put one box on one shelf for a short time, but it does not give you the keys to the building. The author's simplified model:
Application | | Generates presigned URL vAWS S3 | | Temporary permission vUploader
This diagram shows the application generating the presigned URL, then AWS S3 granting temporary permission to the uploader. The vertical bars and v are arrows pointing down.
That pattern is legitimate when the server validates the user first:
Authenticated user ↓Request upload ↓Server validates user ↓Server generates restricted presigned URL ↓User uploads image
Here the first step was effectively:
Anonymous Internet user ↓Request upload permission ↓Receive production S3 presigned URL
In other words, the application itself issued a write capability to an unauthenticated requester. "Write capability" means the ability to create or change data in storage.
Step 3: inspect the signature
The presigned URL contained AWS Signature Version 4 parameters. One stood out:
X-Amz-SignedHeaders=host
This is a parameter in the URL. X-Amz-SignedHeaders lists which HTTP headers are covered by the signature. Here only host is signed. The signature therefore did not bind the uploaded object's Content-Type. The question that followed: if the application believes it is generating an image upload, can the attacker pick a different Content-Type on the actual PUT? A PUT is the HTTP method used to upload or replace a file.
Step 4: change the Content-Type
The flow appeared to expect image content. A safe implementation would allow something like:
image/pngimage/jpegimage/webp
and reject executable formats such as:
image/svg+xmltext/htmlapplication/xhtml+xml
These are MIME types: labels that tell the browser what kind of file it is. image/png, image/jpeg and image/webp are ordinary picture formats. image/svg+xml is an image format that is also a document and can contain scripts. text/html is a web page. application/xhtml+xml is another document format. Because the presigned request did not cryptographically bind the Content-Type, the upload could specify:
Content-Type: image/svg+xml
while still using the valid presigned URL. That gave the second primitive:
Unauthenticated user ↓Presigned PUT ↓Attacker-controlled Content-Type
A primitive is a small, basic capability that can be combined with others.
Step 5: choose a minimal SVG payload
SVG was the interesting test because it is both an image format and an XML document that can carry active content. XML is a text format for structured documents. The payload used to demonstrate execution without attempting to steal anything:
<svg xmlns="http://www.w3.org/2000/svg"> <script>alert("XSS")</script></svg>
Line by line: <svg xmlns="http://www.w3.org/2000/svg"> opens an SVG document and declares its namespace. <script>alert("XSS")</script> is a script that shows a pop-up with the text XSS. </svg> closes the document. The principle applied: use the smallest payload that proves the vulnerability. No credential theft, cookie extraction or account takeover testing was performed.
Step 6: write the object to production S3
The upload was performed against the presigned URL:
PUT <presigned-upload-url>Content-Type: image/svg+xml
<SVG payload>
PUT sends the file to the presigned URL. Content-Type: image/svg+xml labels it as an SVG. <SVG payload> stands for the SVG content. S3 returned:
HTTP/1.1 200 OK
HTTP/1.1 is the protocol version. 200 OK means the request succeeded. This was a real write into the production asset storage. The object key was generated by the server using a UUID-style identifier, which meant the test did not demonstrate path traversal, arbitrary object naming, overwriting of existing files or predictable filename attacks. An object key is the name of the file in the bucket. A UUID is a long random-looking identifier. Path traversal means using ../ to escape a folder. The vulnerability was specifically the unauthenticated ability to create attacker-controlled objects.
Step 7: follow the object to CloudFront
An S3 PUT returning 200 does not by itself mean XSS. The next question was how the uploaded object is delivered. The upload response provided a public asset URL on the application's CloudFront distribution, so the chain became:
S3 ↓CloudFront ↓Browser
Opening the URL in a real browser returned:
HTTP/1.1 200 OKContent-Type: image/svg+xml
The response did not include:
X-Content-Type-Options: nosniff
and did not force a download with:
Content-Disposition: attachment
X-Content-Type-Options: nosniff tells the browser not to guess the file type. Content-Disposition: attachment tells the browser to download the file instead of displaying it. The browser therefore treated the object as an SVG document.
Step 8: confirm execution
The uploaded SVG carried a simple execution marker. When the CloudFront URL was opened, the browser ran the script and displayed an alert:
alert("XSS on " + document.domain)
alert shows a pop-up. document.domain is the current website address. The plus sign joins the two strings. The proven chain was:
Attacker-controlled file ↓Stored in production infrastructure ↓Served by production CloudFront ↓Browser interprets as SVG ↓JavaScript executes
This was no longer merely an unauthenticated file upload; it was unauthenticated stored script execution on the CDN origin. The CDN origin is the address of the delivery network, for example d1rxz8nuri2eg6.cloudfront.net.
Step 9: reproduce with fresh objects
To rule out an accidental or pre-existing file, the process was repeated with fresh uploads and unique object identifiers. It was reproducible, with the same sequence:
CSRF token ↓Upload initiation ↓Presigned URL ↓SVG upload ↓CloudFront URL ↓200 image/svg+xml ↓JavaScript execution
Step 10: establish the execution origin
The script executed on the CloudFront origin:
d1rxz8nuri2eg6.cloudfront.net
not on the application origin:
gifts.tatesbakeshop.com
Those are different origins, so the author did not claim that authenticated users of the application could have their sessions stolen. An origin is the combination of protocol, host and port, for example https://gifts.tatesbakeshop.com. Two different hosts are different origins. The demonstrated impact was:
Attacker ↓Upload malicious SVG ↓CloudFront ↓Victim opens URL ↓JavaScript executes ↓CDN-origin context
Step 11: test escalation towards the application origin
The next question was whether CDN-origin execution could cross into the application origin. The application's image optimization path rejected SVG because SVG handling was disabled there:
Uploaded SVG ↓Next image optimizer ↓SVG rejected
No other obvious same-origin asset passthrough was exposed that would turn the CDN-origin XSS into application-origin XSS. The application's session cookies were also configured with protections including:
Host-SecureHttpOnly
Host restricts the cookie to the exact host, Secure means it is only sent over HTTPS, and HttpOnly means JavaScript cannot read it. Secure means it is only sent over HTTPS. HttpOnly means JavaScript cannot read it. So JavaScript on the CDN origin could not simply read them. This bounded the impact.
Step 12: note the CSP dependency without inflating it
The application's Content Security Policy included the upload asset infrastructure among its allowed script and resource sources. CSP is a set of rules a site sends to the browser saying which sources of scripts and other resources are allowed. That is a dangerous architectural dependency: if an HTML or markup injection sink later appears on the application origin, an attacker-controlled upload origin that CSP explicitly trusts becomes far more useful. An injection sink is a place where user input is inserted into a page without proper escaping. The author did not claim this as an existing exploit path, because the required application-origin injection was never demonstrated. Demonstrated impact was kept separate from hypothetical future impact.
Root cause
The design failed on several independent assumptions, each of which the testing disproved:
- Only legitimate users can request upload permissions. False: the initiation endpoint was reachable without an authenticated account.
- The upload URL only permits safe image content. False: the attacker controlled the
Content-Type. - Uploaded SVG will be downloaded rather than executed. False: CloudFront returned
Content-Type: image/svg+xmlwithout a download disposition. - The browser will protect users from incorrectly served content. False: without
nosniff, the response was treated as an SVG document. - XSS on the asset infrastructure automatically means application account compromise. Not demonstrated: the CDN origin was cross-origin from the application.
At the design level, the core mistake was issuing a production write capability to anonymous users. The presigned URL signed only host, so the client could freely transform a safe image upload into an executable document after receiving the grant. Delivery then compounded it: the CDN served user-controlled content inline, with a type the browser renders as a document, and without headers that would have forced a download or blocked sniffing.
Impact
An unauthenticated Internet user could obtain a production S3 upload capability, upload attacker-controlled SVG content, and have that content served by the production CloudFront infrastructure in an executable format. When a victim opens the resulting asset URL, JavaScript runs in the CDN origin's security context.
The author explicitly did not claim:
- application account takeover
- session-cookie theft
- access to other users' accounts
- arbitrary S3 object overwrite
- path traversal
- access to AWS credentials
- modification of existing assets
- access to private application data
- application-origin XSS
- customer data compromise
The demonstrated vulnerability was:
Unauthenticated production upload+Attacker-controlled executable SVG+CDN delivery+Browser JavaScript execution
with execution confined to the CDN origin. The conditions for impact are that the victim opens the attacker-supplied asset URL; the application's session cookies were configured with protections including Host-SecureHttpOnly, and no same-origin passthrough was found.
Fix
- Require authentication. Do not issue production S3 upload grants to anonymous users unless anonymous uploads are explicitly intended. Authenticate and authorize the upload request before generating the presigned URL.
- Restrict allowed content types. Use a strict server-side allowlist such as
image/png,image/jpeg,image/webpif those are the only formats needed. Do not rely on the client to supply a safe MIME type. - Bind upload properties to the signature. Security-sensitive properties should be constrained by the server-generated signature where appropriate, so the client cannot turn a safe image into an executable document after receiving the grant.
- Add defensive response headers. Serve user-uploaded content with
X-Content-Type-Options: nosniffandContent-Disposition: attachmentwhere appropriate. A CloudFront response-headers policy can enforce this consistently. - Use a dedicated untrusted-content origin. Separate user content from the application, for example
app.example.comfor the trusted application anduploads.exampleusercontent.combacked by S3 and CloudFront for untrusted content, so the application never has to trust uploads as part of its own origin. - Review CSP dependencies. Avoid trusting user-controlled upload origins in the application's CSP; treat them as hostile.
The author stresses that blocking SVG alone is not the complete fix. It addresses this demonstration but not the underlying problem of anonymous users holding production write capability. Authorization comes first, then file-type policy, then delivery policy: security should be layered, and headers should supplement rather than replace server-side validation.
Variants to test
- Anonymous upload initiation. Remove authentication and call the initiation endpoint directly. A positive result is a presigned URL returned to a caller with no session.
- Unsigned
Content-Type. InspectX-Amz-SignedHeaderson presigned URLs. If it lists onlyhost, try a PUT with a differentContent-Typethan the application expects; a positive result is a 200 with the object stored under the chosen type. - Inline SVG delivery. Request the resulting asset URL and check the response. A positive result is
Content-Type: image/svg+xmlwith noX-Content-Type-Options: nosniffand noContent-Disposition: attachment, followed by script execution in a real browser. - Other active types. Where the server accepts them, try
text/htmlandapplication/xhtml+xmlin the same way, checking whether the browser renders the stored object as a document. - Same-origin passthrough. Look for image proxies, optimizers or asset routes on the application origin that fetch from the upload bucket. A positive result is the uploaded SVG being served from the application origin, which would raise the impact from CDN-origin to application-origin execution.
- CSP trust of the upload origin. Check whether the application's CSP allows the asset host as a script or resource source. A positive result is the upload origin appearing among the CSP's allowed script or resource sources, a latent escalation path if an injection sink exists.
- Object key control. Test whether the client can influence the object key. A positive result is a client-chosen or predictable key, opening overwrite or naming attacks that this target did not have.
- Presigned URL scope. Inspect
X-Amz-Expires,X-Amz-CredentialandX-Amz-Signatureto understand lifetime and permissions. InspectX-Amz-Expires,X-Amz-CredentialandX-Amz-Signatureto understand lifetime and permissions.
The author's reusable checklist for upload hunting, reproduced as given:
[ ] Is authentication required?[ ] Is authorization checked server-side?[ ] Can anonymous users obtain presigned URLs?[ ] Can users choose the object key?[ ] Can users overwrite existing objects?[ ] Is the filename predictable?[ ] Is the extension validated?[ ] Is MIME type validated server-side?[ ] Is Content-Type cryptographically bound?[ ] Can SVG be uploaded?[ ] Can HTML be uploaded?[ ] Can XML be uploaded?[ ] Can polyglot files be uploaded?[ ] Is the file transformed before serving?[ ] Which hostname serves the file?[ ] Is it same-origin with the application?[ ] What Content-Type is returned?[ ] Is nosniff enabled?[ ] Is Content-Disposition configured?[ ] Is CSP involved?[ ] Does the browser execute the content?[ ] Can execution reach the application origin?[ ] Can the file be used for phishing?[ ] Can existing objects be overwritten?
Each [ ] is a checkbox. A polyglot file is a file that is valid in more than one format. Phishing means tricking someone into trusting a link.
The closing lesson: when you find a file upload, do not stop at whether you can upload. Follow the object from creation to delivery, through create, store, transform, serve and render, and ask at each stage who authorized it, what the presigned URL actually constrained, and which origin ends up executing your code.
Glossary
- API: a set of URLs a website's frontend uses to ask the server to do things.
- Authentication: proving who you are, usually by logging in.
- Authorization: checking whether you are allowed to do a particular action.
- AWS S3: Amazon's cloud storage service for files (objects).
- Bucket: a container in S3 that holds objects.
- CloudFront: Amazon's content delivery network that serves files to users.
- Content-Disposition: a response header that tells the browser to download a file instead of displaying it.
- Content-Type: a label that tells the browser what kind of file it is.
- Cookie: a small piece of data a site stores in your browser, often used to keep you logged in.
- CSP (Content Security Policy): rules a site sends to the browser saying which sources of scripts and resources are allowed.
- CSRF token: a random string a site gives out to prove a request came through its own pages; not a login credential.
- Endpoint: a specific URL that an API exposes.
- GET: an HTTP method for fetching data.
- Host header: the part of an HTTP request that says which server you are talking to.
- HTTP: the protocol browsers and servers use to communicate.
- HttpOnly: a cookie flag that stops JavaScript from reading the cookie.
- Inline: displaying a file directly in the browser rather than downloading it.
- JavaScript: the programming language browsers run.
- MIME type: another name for Content-Type.
- nosniff: a response header value that tells the browser not to guess the file type.
- Object: a file stored in S3.
- Object key: the name of an object in a bucket.
- Origin: the combination of protocol, host and port, for example
https://app.example.com. - Path traversal: using
../in a filename to escape a folder. - Polyglot file: a file that is valid in more than one format.
- POST: an HTTP method for sending data.
- Presigned URL: a temporary, signed link that allows one specific operation on a cloud resource.
- Primitive: a small, basic capability that can be combined with others.
- PUT: an HTTP method for uploading or replacing a file.
- Response header: extra information a server sends with a response.
- Secure (cookie flag): a cookie flag that sends the cookie only over HTTPS.
- Session: the state of being logged in.
- Signature: a cryptographic stamp proving a link was created by the server and not altered.
- Stored XSS: a cross-site scripting attack where the malicious script is saved on the server and runs when someone views it.
- SVG: an image format that is also a document and can contain scripts.
- tRPC: a framework for building APIs that a frontend calls directly.
- UUID: a long random-looking identifier.
- XSS (cross-site scripting): making a browser run an attacker's script as if it came from a website.
- XML: a text format for structured documents.