$_FILES’ type Is Not Safe¶
<?php
// curl -F "avatar=
@shell
.php;type=image/png"
if (isset($_FILE['upload']['type'])) {
print $_FILE['upload']['type'];
}
$_FILES[‘avatar’][‘type’] in PHP is a string the attacker typed.🔐
main/rfc1867.c reads the Content-Type header of the multipart part, cuts it at the first “;” and hands it to you. No sniffing. No validation. NOTHING reads the bytes on disk.
curl -F “avatar=
@shell
.php;type=image/png” and your check sees image/png.
finfo_file() on tmp_name is the one that actually opens the file.
See Also¶
Mastering PHP File Uploads: A Deep Dive into the `$_FILES Array <https://www.w3tutorials.net/blog/php-files-array-http-file-upload-variables/>`_
$_FILES type is an external string [Try me]
PHP Features¶
Last updated: 18 August 2026