---
title: "Check every uploaded file · Agent Wranglers"
url: https://agentwranglers.se/playbook/application-security/requests-files-and-caches/safe-file-uploads
id: APS-43
level: Required
risk: takeover
updated: 2026-10-27
build: a2a6bdfed830
tokens: 950
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Check every uploaded file

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Requests, files and caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: APS-43
- Level: Required
- Chapter: [Requests, files and caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches.md)
- Rule: Accept only the file types you need, check them by content, limit their size, and store them where they cannot run.
- Check: On the test copy, the agent uploads a harmless HTML file renamed to `.jpg`, a file twice the size limit and a file named `../../marker.txt`. All are refused, or stored under a random name that never runs. Fetching a stored upload returns `nosniff`, and `attachment` unless it is an image.
- Risk: An account or system taken over
- How: Read the first bytes to find the type, and don't trust the name or the browser's type. Set a size limit per type, such as 10 MB for images, in the web server and in the app. Give every file a random name. Store it outside the web folder or on a separate domain. Serve it with `X-Content-Type-Options: nosniff` and `Content-Disposition: attachment` unless it is a known image. Treat SVG as active content, because it can hold scripts. See also [confirm every upload on the server](https://agentwranglers.se/playbook/files-and-media/uploads/confirm-uploads.md) and [scan files for malware before anyone opens them](https://agentwranglers.se/playbook/files-and-media/uploads/scan-uploads.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### HTTP example

```http
HTTP/2 200
content-type: application/octet-stream
content-disposition: attachment; filename="upload.bin"
x-content-type-options: nosniff
```

## Sources

- [OWASP File Upload Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html)

## Related rules

- APP-24 [Check files in the browser before they upload](https://agentwranglers.se/playbook/app-ui/forms/file-upload-field.md) in Web app interface
- MED-41 [Upload straight to storage with a signed address](https://agentwranglers.se/playbook/files-and-media/uploads/presigned-uploads.md) in Files and media
- MED-43 [Confirm every upload on the server](https://agentwranglers.se/playbook/files-and-media/uploads/confirm-uploads.md) in Files and media
- MED-3 [Serve user files from their own domain](https://agentwranglers.se/playbook/files-and-media/uploads/user-content-domain.md) in Files and media
- MED-44 [Scan files for malware before anyone opens them](https://agentwranglers.se/playbook/files-and-media/uploads/scan-uploads.md) in Files and media

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/application-security/requests-files-and-caches/safe-file-uploads">Agent Wranglers application security playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Treat data from other APIs as untrusted](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/third-party-api-data.md)
- Next: [Keep file paths inside their folder](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/block-path-traversal.md)
- [Requests, files and caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches.md)
