Skip to content

Conversation

@TTMTT
Copy link

@TTMTT TTMTT commented Oct 21, 2025

This PR hardens the upload() and rename() functions to fix the critical security vulnerabilities discussed in Issue #408.

1. Rename Vulnerability (Vulnerability 2):
The rename() method now validates the new file extension against the allowFileTypes config list. This directly prevents renaming a file like image.jpg to shell.php.

2. Disguised Upload Vulnerability:
The upload() method has been significantly hardened and no longer trusts the file extension alone. The new validation logic includes:

  • MIME Type Validation: Uses finfo_file to get the true MIME type.
  • PHP Payload Scanning: Scans file content for PHP tags (e.g., <?php) if PHP is not an explicitly allowed extension.
  • Magic Byte Validation: Validates file headers for common types (images, PDFs, Zip, etc.) to ensure the content matches the extension.

This patch blocks the reported RCE vectors by ensuring only genuinely safe and allowed files can be uploaded or renamed.

…mai#408)

This PR hardens the `upload()` and `rename()` functions to fix the critical security vulnerabilities discussed in Issue alexusmai#408.

**1. Rename Vulnerability (Vulnerability 2):**
The `rename()` method now validates the new file extension against the `allowFileTypes` config list. This directly prevents renaming a file like `image.jpg` to `shell.php`.

**2. Disguised Upload Vulnerability:**
The `upload()` method has been significantly hardened and no longer trusts the file extension alone. The new validation logic includes:

* **MIME Type Validation:** Uses `finfo_file` to get the true MIME type.
* **PHP Payload Scanning:** Scans file content for PHP tags (e.g., `<?php`) if PHP is not an explicitly allowed extension.
* **Magic Byte Validation:** Validates file headers for common types (images, PDFs, Zip, etc.) to ensure the content matches the extension.

This patch blocks the reported RCE vectors by ensuring only genuinely safe and allowed files can be uploaded or renamed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant