create([ 'uploaded_by' => $uploader->id, 'folder_id' => $folderId, 'name' => $name !== null && $name !== '' ? $name : pathinfo($originalName, PATHINFO_FILENAME), 'description' => $description, 'original_name' => $originalName, 'path' => $path, 'disk' => $disk, 'mime_type' => $mimeType, 'size' => $size, 'checksum' => $checksum, ]); $this->activity->log($action, $uploader, $file); return $file; } /** * An uploader picks original_name freely — it is validated for length * and nothing else — and it is echoed back in the Content-Disposition * header of every download, preview and thumbnail response. A CR or LF * in a header value is header injection; PHP's header() refuses to * emit one, so today that fails closed as a 500 rather than a split * response, but a filename should not be able to break the response at * all. Strip the whole C0/C1 control range once, here, rather than * hoping each of the five emission sites remembers to. */ public static function sanitizeFilename(string $name): string { $clean = preg_replace('/[\x00-\x1F\x7F]/u', '', $name) ?? $name; $clean = trim($clean); return $clean === '' ? 'file' : $clean; } }