abdian/laravel-upload-guard

GitHub: abdian/laravel-upload-guard

Laravel Upload Guard 是一款 Laravel 文件上传安全扩展,通过结构化字节解析而非简单的正则匹配,深度拦截恶意 Web Shell、伪造文件、恶意 PDF/SVG、Office 宏及 zip 炸弹等威胁。

Stars: 0 | Forks: 0

# 🛡️ Laravel Upload Guard **为 Laravel 提供的失败即封闭的文件上传验证。** 这是一层深度防御机制,用于检测并拦截常见的恶意上传 —— polyglot web shell、恶意 PDF 和 SVG、zip 炸弹、Office 宏以及伪造的 MIME 类型 —— 它使用结构化解析和内容净化,而不仅仅是 regex。 *它不是杀毒软件,也不是唯一的安全边界 —— 请参阅[局限性](#limitations--not-a-security-boundary)。* [![最新版本](https://img.shields.io/packagist/v/abdian/laravel-upload-guard.svg?style=flat-square)](https://packagist.org/packages/abdian/laravel-upload-guard) [![总下载量](https://img.shields.io/packagist/dt/abdian/laravel-upload-guard.svg?style=flat-square)](https://packagist.org/packages/abdian/laravel-upload-guard) [![测试](https://img.shields.io/github/actions/workflow/status/abdian/laravel-upload-guard/tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/abdian/laravel-upload-guard/actions/workflows/tests.yml) [![PHP 版本](https://img.shields.io/packagist/php-v/abdian/laravel-upload-guard.svg?style=flat-square)](https://packagist.org/packages/abdian/laravel-upload-guard) [![许可证](https://img.shields.io/packagist/l/abdian/laravel-upload-guard.svg?style=flat-square)](LICENSE)
``` // One rule. Fail-closed by default. $request->validate([ 'file' => 'required|safeguard', ]); ``` ## 为什么需要? Laravel 内置的 `mimes` / `mimetypes` 规则信任**客户端声明**的类型 和粗糙的扩展名映射表。攻击者可以上传重命名为 `avatar.jpg` 的 `shell.php`,或是附带在图像数据之后的真实 JPEG(一种 *polyglot* web shell)、携带 `