A team stores user uploads in S3 and serves them from the main domain. A tester uploaded an HTML file that ran JavaScript. What do you do?
AdvancedScenarioVulnerability Management and OWASP
Answer
Situation read → Stored XSS through file upload, running in the main app's origin, so it can read session data.
What I'd do →
- Serve user content from a separate, cookieless domain (for example
usercontent-example.com), so scripts cannot reach app cookies or storage. - Set
Content-Disposition: attachmentand the correctContent-Typeon objects; addX-Content-Type-Options: nosniff. - Validate file types by content (magic bytes), not by extension, and limit allowed types.
- Scan uploads for malware (S3 malware protection in GuardDuty, or ClamAV in a Lambda).
- Use presigned URLs with short expiry for private files.
Why → Origin isolation is the strongest fix; that is why large providers host user content on separate domains.
Interview tip → Mention the separate-domain pattern; it shows real-world experience.
More on Vulnerability Management and OWASP
A pentest report shows SQL injection in a search endpoint of a Java service. How do you handle it end to end?BeginnerA scanner reports 4,000 open CVEs across 300 images. The team can fix maybe 100 a month. How do you prioritise?IntermediateA user reports they can see another customer's invoice by changing the ID in the URL. What do you do?BeginnerA webhook feature lets users enter a URL, and a pentester used it to read the cloud metadata endpoint. How do you fix it?AdvancedA team still runs Log4j 2.14 in an internal service and says it is not internet-facing. How do you respond?IntermediateA security review finds passwords stored as unsalted MD5 hashes. How do you migrate without forcing every user to reset?Advanced