Skip to content

fix(files_sharing): validate input in PublicPreviewController#getPreview#59253

Open
mvanhorn wants to merge 2 commits intonextcloud:masterfrom
mvanhorn:fix/public-preview-input-validation
Open

fix(files_sharing): validate input in PublicPreviewController#getPreview#59253
mvanhorn wants to merge 2 commits intonextcloud:masterfrom
mvanhorn:fix/public-preview-input-validation

Conversation

@mvanhorn
Copy link
Copy Markdown

Summary

Fixes two cases where PublicPreviewController::getPreview() triggers an
internal server error due to incomplete input validation:

Case A - Empty $file parameter on folder shares:
$node->get('') returns the Folder itself, then getPreview() fails because
it expects a File. Now returns 400 Bad Request early.

Case B - Non-existent file with mimeFallback=1:
When $node->get($file) throws NotFoundException, the catch block called
$file->getMimeType() on the original string parameter. Renamed the local
variable to $fileNode and added an isset() guard so the mime fallback
only runs when the file node was successfully resolved.

Fixes #59229

Return 400 Bad Request when the file parameter is empty and the shared
node is a folder, instead of passing the folder itself to getPreview
which triggers an internal server error.

Also rename the local variable to $fileNode to prevent the catch block
from calling getMimeType() on the original string parameter when
get() throws NotFoundException.

Fixes nextcloud#59229

Signed-off-by: Matt Van Horn <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
@mvanhorn mvanhorn requested a review from a team as a code owner March 27, 2026 13:14
@mvanhorn mvanhorn requested review from icewind1991, leftybournes, provokateurin and salmart-dev and removed request for a team March 27, 2026 13:14
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.

[Bug]: Improper input validation in PublicPreviewController triggers internal server error

2 participants