Skip to content

fix(secure-view): allow server-side file reads in SecureViewWrapper#5587

Merged
elzody merged 1 commit intomainfrom
fix/secure-view-template-creation-blocked
Apr 24, 2026
Merged

fix(secure-view): allow server-side file reads in SecureViewWrapper#5587
elzody merged 1 commit intomainfrom
fix/secure-view-template-creation-blocked

Conversation

@chrip
Copy link
Copy Markdown
Contributor

@chrip chrip commented Apr 23, 2026

Problem

SecureViewWrapper::checkFileAccess() was blocking all non-WOPI fopen() and
file_get_contents() calls on watermarked files, including server-side operations
that never expose file content to the client.

The most visible symptom: creating a new file from a template fails with
"Unable to create new file from template" when Secure View is enabled for the
user's group. TemplateManager::createFromTemplate() reads the template file
server-side via fopen(), which was incorrectly treated as a download attempt.

Stack trace from the field:

OCP\Files\ForbiddenException: Download blocked due the secure view policy
SecureViewWrapper.php::checkFileAccess
Files/View.php::fopen
Files/Node/File.php::fopen
Files/Template/TemplateManager.php::createFromTemplate
files/Controller/TemplateController.php::create

Relation to #5577

This is a companion fix to #5577, which addressed a related Secure View regression
where shouldSecure() called fopen() internally, causing a recursive
ForbiddenException during delete/trash operations. Both issues stem from
SecureViewWrapper wrapping too broadly and intercepting legitimate server-side
file operations.

Fix

Server-side operations (template creation, background jobs, CLI) are either
non-GET or carry no HTTP context at all.
checkFileAccess() now checks the HTTP method. Only GET requests are blocked, which covers
all real download vectors (WebDAV, public shares, ZIP folder downloads, preview
thumbnails) while leaving server-side reads untouched.

…rapper

SecureViewWrapper::checkFileAccess() was blocking all non-WOPI fopen()
and file_get_contents() calls on watermarked files, including server-side
reads that never expose content to the user (e.g. TemplateManager reading
a template file to copy it). Add isDirectFileServingRequest() to restrict
the block to actual download endpoints (WebDAV, public shares, previews).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
Copy link
Copy Markdown
Collaborator

@elzody elzody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable way to resolve this. I don't think the failing test is related; I will restart the workflow and it will likely pass. I'll also make a note of it to check for flakiness there in the future.

@elzody
Copy link
Copy Markdown
Collaborator

elzody commented Apr 24, 2026

/backport to stable33 please

@elzody
Copy link
Copy Markdown
Collaborator

elzody commented Apr 24, 2026

/backport to stable32 please

@elzody elzody merged commit 6e20eee into main Apr 24, 2026
84 of 86 checks passed
@elzody elzody deleted the fix/secure-view-template-creation-blocked branch April 24, 2026 20:30
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.

2 participants