GHSA-8hw4-7qjr-3wxg: XSS
Summary
SingleBase64Image::uploadFiles — the uploader bound to image-typed fields via withFiles() — only verifies that the submitted value starts with the string data:image. The MIME subtype and the base64-decoded bytes are never inspected or validated. A related bug in FileNameGenerator causes the stored file to receive an extensionless filename, because mimecontenttype() returns false when given a data URI instead of a filesystem path.
The combination allows an authenticated admin to store a file of arbitrary type on the configured disk under a name without a recognizable extension.
Details
php // src/app/Library/Uploaders/SingleBase64Image.php if (Str::startsWith($value, 'data:image')) { // MIME subtype and decoded bytes are not validated $base64Image = Str::after($value, ';base64,'); $finalPath = $this->getPath() . $this->getFileName($value); Storage::disk($this->getDisk())->put($finalPath, base64decode($base64Image)); return $finalPath; }
// src/app/Library/Uploaders/Support/FileNameGenerator.php private function getExtensionFromFile(string|UploadedFile $file): string { return isa($file, UploadedFile::class, true) ? $file->extension() : Str::after(mimecontenttype($file), '/'); // returns false on data URIs → empty string }
The stored filename ends with a trailing dot and no extension.
Impact
An authenticated admin submitting a malicious payload to a Backpack image field stored with withFiles() can write arbitrary file content to the configured storage disk. Depending on server configuration and how stored files are served, this may lead to stored XSS or other unintended behavior when the file is later accessed.
Fix
The fix validates the declared MIME subtype against an allowlist, decodes the base64 payload, and verifies the actual file bytes with finfo before storing. The extension is derived from the detected MIME type rather than the data URI string. Applied in SingleBase64Image::uploadFiles and uploadRepeatableFiles; FileNameGenerator::getExtensionFromFile now rejects inputs that produce an empty extension.
Setting X-Content-Type-Options: nosniff on admin responses is a useful defense-in-depth complement.
Affected versions
- >= 6.0.0, < 6.8.14 - >= 7.0.0, < 7.0.38
Patched versions
- 6.8.14 - 7.0.38
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/backpack/crudto a version that resolves this vulnerability.Fixed in 7.0.38 - Upgrade
Upgrade
composer/backpack/crudto a version that resolves this vulnerability.Fixed in 6.8.14 - Upgrade
Upgrade
Backpack SingleBase64Image / FileNameGeneratorto a version that resolves this vulnerability.Fixed in 6.8.14 - Upgrade
Upgrade
Backpack SingleBase64Image / FileNameGeneratorto a version that resolves this vulnerability.Fixed in 7.0.38 - Compensating control
Set the response header "X-Content-Type-Options: nosniff" on admin responses as defense-in-depth.
Event History
Frequently Asked Questions
Who can exploit this issue?
An authenticated administrator who can submit data to an image-typed field configured with withFiles() can exploit it.
What does an attacker need to provide?
The submitted value only needs to begin with data:image and include base64 data. The MIME subtype and decoded file contents are not validated, allowing arbitrary file bytes to be stored on the configured disk.
How are uploaded files stored?
The related filename-generation issue can cause the uploaded file to be saved without a recognizable extension because mime_content_type() is given a data URI rather than a filesystem path.