Skip to content
Back to skills

Secure File Upload

ASecurity

Hardens upload endpoints by checking type, size, name and storage location, blocking path traversal, executable content and image bombs.

  • 3 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added November 15, 2026
ai-agentsrustphp

Works with

  • cli

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill secure-file-upload --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Secure File Upload?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Secure File Upload
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-secure-file-upload/badge)](https://www.skillsdirectory.com/skills/workspace-templates-secure-file-upload)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: secure-file-upload
description: Hardens upload endpoints by checking type, size, name and storage location, blocking path traversal, executable content and image bombs.
---

# Secure file upload

Never trust the filename, the extension or the Content-Type header from the client.

## Steps

1. Find every upload handler (multipart parsers, presigned URL generators, import jobs) and follow a file from request to final location and later download.
2. Size: set a hard limit at the parser and at the proxy, and stream to storage instead of reading the whole file into memory. Limit the number of files per request.
3. Type: allow a short list of extensions, then verify the content with magic bytes (file signature) or a library, and make sure both agree. For images, re-encode with a trusted library; this strips embedded scripts and metadata, and caps pixel dimensions to stop decompression bombs.
4. Name: discard the original name. Generate a random one (UUID) and keep the original only as display metadata, escaped on output. Reject names with `..`, slashes, null bytes or reserved Windows names.
5. Location: store outside the web root, or in object storage with a private bucket. Resolve the final path and confirm it starts with the base directory. Never write with execute permission.
6. Serving: send `Content-Disposition: attachment` for non-images, set `X-Content-Type-Options: nosniff`, and use a separate domain for user files where possible. Check authorization on download.
7. Archives: when unzipping, check each entry path against the destination and cap total expanded size.
8. Consider malware scanning for files shared between users.

## Rules

- A blocklist of "bad extensions" is not a defence.
- Add tests: a `.php` file renamed `.jpg`, `../../x` as the name, an oversized file, an empty file.

## Report

Handlers reviewed, issues fixed with `path:line`, limits chosen, and tests added.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.