'image.png', 'tmp_name' => $imagePath, 'size' => filesize($imagePath), 'error' => UPLOAD_ERR_OK, ], false); $traversalUpload ->file_name('../' . basename($outsideFile)) ->upload_to($uploadRoot . '/') ->run(); assertUploadSecurity(!$traversalUpload->was_uploaded, 'Path traversal destinations must be rejected.'); assertUploadSecurity(!file_exists($outsideFile), 'Path traversal must not create files outside the upload folder.'); $linkedDirectory = $uploadRoot . '/linked'; assertUploadSecurity(symlink(dirname($uploadRoot), $linkedDirectory), 'The upload symlink test could not be created.'); $symlinkFile = dirname($uploadRoot) . '/plugi-upload-symlink-' . bin2hex(random_bytes(8)) . '.png'; $symlinkUpload = new Uploader([ 'name' => 'image.png', 'tmp_name' => $imagePath, 'size' => filesize($imagePath), 'error' => UPLOAD_ERR_OK, ], false); $symlinkUpload ->file_name('linked/' . basename($symlinkFile)) ->upload_to($uploadRoot . '/') ->run(); assertUploadSecurity(!$symlinkUpload->was_uploaded, 'Symlinked destination folders must be rejected.'); assertUploadSecurity(!file_exists($symlinkFile), 'Symlinked destinations must not create files outside the upload folder.'); assertUploadSecurity(unlink($linkedDirectory), 'The upload symlink test could not be removed.'); $scriptUpload = new Uploader([ 'name' => 'payload.php', 'tmp_name' => __FILE__, 'size' => filesize(__FILE__), 'error' => UPLOAD_ERR_OK, ], false); $scriptUpload->MIME_allowed = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp']; $scriptUpload ->file_name('payload.jpg') ->upload_to($uploadRoot . '/') ->mime_check() ->run(); assertUploadSecurity(!$scriptUpload->was_uploaded, 'Non-image uploads must be rejected when image MIME validation is enabled.'); $uploadRules = file_get_contents(dirname(__DIR__, 2) . '/uploads/.htaccess'); assertUploadSecurity(strpos($uploadRules, 'Require all denied') !== false, 'Uploaded PHP scripts must be denied by the Apache upload rules.'); assertUploadSecurity(rmdir($uploadRoot), 'The upload security test folder could not be removed.'); echo "Upload security checks passed.\n";