Quick revision
The short answer
Storing uploads on local disk and serving them back with the client's content type creates stored XSS through HTML or SVG rendered inline on our domain, path traversal, disk exhaustion, malware distribution from our own domain, and files lost whenever an instance is replaced. The platform answer is one shared upload component: object storage with generated keys instead of user filenames, central size limits and malware scanning, and downloads served from a separate domain with Content-Disposition: attachment, a safe content type and X-Content-Type-Options: nosniff.
What to remember
In this answer, we saw why local storage with client content types is risky: HTML or SVG served inline gives stored XSS on our origin, user filenames enable path traversal, uploads can fill the application's disk, unscanned files spread malware, and ephemeral, per-instance disks lose files. The platform approach is to store every file in object storage under generated keys, scan and size-limit centrally through a quarantine step, serve downloads from a separate domain with Content-Disposition: attachment, a safe content type and nosniff, and give teams a shared upload component so nobody rebuilds this alone.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Storing uploads on local disk and serving them back with the client's content type creates stored XSS through HTML or SVG rendered inline on our domain, path traversal, disk exhaustion, malware distribution from our own domain, and files lost whenever an instance is replaced. The platform answer is one shared upload component: object storage with generated keys instead of user filenames, central size limits and malware scanning, and downloads served from a separate domain with Content-Disposition: attachment, a safe content type and X-Content-Type-Options: nosniff.
Why this question is asked
Upload handling is a classic place where each team writes something that works in the demo and is dangerous in production. When a security review finds the same pattern in several services, fixing each one separately is slow and the pattern will come back in the next service. Interviewers ask this scenario to see whether we can name the concrete risks, explain why each happens, and then set a platform-wide approach that makes the safe way the easy way. In this answer, we will walk through each risk with an example, then design the standard storage, download and scanning approach, and finish with a migration plan for the services already affected.
1A Quick Recap of How Browsers Treat a Download
When a browser receives a response, two headers decide what happens. Content-Type says what the bytes are, for example image/png or text/html. Content-Disposition says whether to show it inline in the page or to save it as a file (attachment). If the type is text/html and the disposition is inline, the browser renders it as a page, runs its scripts, and treats it as coming from our origin, the scheme plus host plus port of the URL.
That last point is the key. Scripts from our origin can read our cookies (unless marked HttpOnly), call our APIs with the user's session and read the responses. So a file served inline from www.example.com has the same power as our own front-end code. Browsers may also sniff content, guessing the type from the bytes when the declared type looks wrong, which can turn an "image" into HTML.
2The Risks in the Current Design
The first and most serious risk is stored XSS, cross-site scripting where the malicious script is stored on our server. An attacker uploads profile.html, or an SVG image (SVG is XML and can contain script tags), and the service stores the client's content type text/html or image/svg+xml. When a victim opens the file link, the script runs on our origin with the victim's session and can, for example, change their email address through our API.
Path traversal is next. If the service builds the disk path from the original filename, a name like ../../app/config/application.yml can overwrite files outside the upload directory, and a download endpoint that takes a filename parameter can be tricked into reading /etc/passwd or the application's secrets.
Local disk also brings availability and durability problems. Disk exhaustion happens when uploads fill the volume that the application, its logs and its temp files share; at that point the service stops working for everyone, not just for uploads. Lost files happen when the instance is replaced by autoscaling, a deploy or a hardware failure, because local disks are usually ephemeral, and with several instances each one only has the files uploaded to it, so downloads fail half the time behind a load balancer.
Finally, malware distribution: without scanning, our domain becomes a free host for malicious files, with our reputation attached. Browsers and email filters may then flag our domain, which can hurt the whole product.
| Risk | Cause | Impact |
|---|---|---|
| Stored XSS | HTML or SVG served inline with client type | account takeover on our origin |
| Path traversal | paths built from user filenames | overwrite or read server files |
| Disk exhaustion | uploads on the app's own volume | whole service down |
| Malware distribution | no scanning | users infected, domain blocklisted |
| Lost files | ephemeral, per-instance disks | missing data after deploys |
3Standard 1: Object Storage With Generated Keys
The platform stores every upload in object storage, never on instance disks. That alone removes disk exhaustion of the application volume and lost files, because object storage is shared by all instances and replicated by the provider. Each file is stored under a key we generate, such as tenant-42/2026/11/9b1e4c.../original, and the original filename is kept only as a metadata field in the database after cleaning. Because the key never contains user input, path traversal on write is impossible, and download endpoints look files up by an id we issued, not by a path the client sends.
4Standard 2: Safe Downloads From a Separate Domain
Downloads are where XSS is stopped. Every file is served with three protections. First, Content-Disposition: attachment, so the browser saves the file instead of rendering it. Second, a safe Content-Type: the type we detected and allow-listed, never the client's claim, and application/octet-stream for anything not on the list. Third, X-Content-Type-Options: nosniff, which tells the browser not to guess a different type from the bytes.
As a last line of defence, files are served from a separate domain, for example example-usercontent.net, not a subdomain of our main site. Even if a file is rendered inline by mistake, for example an image preview we chose to allow, any script in it runs on an origin that has no cookies and no access to our APIs. The Content-Security-Policy: sandbox header adds another layer by treating the response as a sandboxed document. Big platforms use exactly this split between the application domain and the user-content domain.
5Standard 3: Central Scanning and Limits
Malware scanning and size limits belong to the platform, not to each team. Uploads land in a quarantine bucket. A scanning service picks up each new object, checks the real file type against the feature's allow list, runs antivirus scanning, and moves clean files to the serving bucket or marks them rejected. Size limits are enforced at upload time (in the gateway and in the signed upload request) and per tenant through quotas, so one customer cannot fill storage for everyone.
The reason to centralise is that scanners need signature updates, alerting and capacity planning. Thirty teams each running their own scanner means thirty that fall behind on updates.
- Upload to quarantinegenerated key, size limit enforced
- Detect type and scanmagic bytes vs allow list, antivirus
- Clean and allowed?YesMove to serving bucket, READYNoMark REJECTED, delete later
- Serve via user-content domainattachment, safe type, nosniff
4 steps in order. Play them, or step through them one at a time.
6Making It the Easy Way: A Shared Component and a Migration Plan
None of this sticks unless using it is easier than rewriting it. So the platform offers a shared upload component: a small service or library with a start-upload call that returns a pre-signed URL or accepts a stream, a status callback when scanning finishes, and a download call that returns a short-lived signed link on the user-content domain with the right headers already set. Teams describe their feature's allowed types and sizes in configuration; they do not write storage, scanning or header code.
For the services already affected, we act by risk. First, within days, we change the download responses of every affected service to attachment, octet-stream and nosniff, which stops the XSS even before files move. Then we migrate existing files into the platform storage, rescanning each one, rewriting references in the database, and keeping old download URLs working through redirects. Finally, we add a check to code review and to the platform's security tests that flags new code writing uploads to local paths.
7Follow-up questions
Why is SVG dangerous when it is just an image?
SVG is an XML document that browsers render as a page when opened directly, and it may contain script elements and event handlers. Served inline as image/svg+xml from our origin, the script runs with our origin's privileges. Embedded with an img tag, scripts do not run, but users can still open the file URL directly. So we treat SVG like HTML: attachment only, or convert it to a raster image, or sanitise it with a strict library.
Is a subdomain like files.example.com enough as a separate domain?
Not fully. A subdomain shares the registrable domain, so cookies set for .example.com are sent to it, and some browser protections treat same-site requests more permissively. A completely separate registrable domain, such as example-usercontent.net, gives real isolation.
What do you do about files uploaded before scanning existed?
Rescan them during migration. We move existing files through the same quarantine and scanning pipeline, mark anything infected or of a disallowed type, notify the owning team, and decide with security whether to delete or block downloads. Until a file is rescanned, it is served only as an attachment from the user-content domain.
8Conclusion
In this answer, we saw why local storage with client content types is risky: HTML or SVG served inline gives stored XSS on our origin, user filenames enable path traversal, uploads can fill the application's disk, unscanned files spread malware, and ephemeral, per-instance disks lose files. The platform approach is to store every file in object storage under generated keys, scan and size-limit centrally through a quarantine step, serve downloads from a separate domain with Content-Disposition: attachment, a safe content type and nosniff, and give teams a shared upload component so nobody rebuilds this alone.
Open with
I see five risks. The worst is stored XSS: if someone uploads an HTML file or an SVG with a script, and we serve it inline with the content type they gave us, it runs on our origin with the victim's session.
Then, if they want more
Second, if paths are built from the original filename, there is path traversal on upload and download. Third, uploads share the instance disk, so they can fill it and take the service down. Fourth, nothing is scanned, so our domain can distribute malware and get blocklisted.
And fifth, local disks are ephemeral and per instance, so files disappear after deploys or are only on one of several instances. For the platform, I would first stop the bleeding: change every download to Content-Disposition attachment, a safe content type such as octet-stream unless allow-listed, and X-Content-Type-Options nosniff.
Then standardise: all uploads go to object storage under generated keys, never the user filename, which is kept only as metadata. Files land in quarantine, a central service detects the real type and scans for malware before anything is servable, and size limits and tenant quotas are enforced at upload. Downloads come from a separate user-content domain with no cookies.
Finally, I would provide this as a shared upload component, so teams configure allowed types and sizes instead of reimplementing it, and migrate existing files with a rescan.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A security review found that several services accept uploads, store them on local disk...": https://scrivio-interview-library.netlify.app/spring-boot/web-other/d8dc6fa1bf/