fix(SecureViewService): handle fopen() returning false for non-existent paths#5577
Open
fix(SecureViewService): handle fopen() returning false for non-existent paths#5577
Conversation
…nt paths When shouldSecure() is called with tryOpen=true on a path that does not exist yet (e.g. a rename target or a files_versions snapshot path), the underlying fopen() call returns false. Calling fclose(false) on that value throws a TypeError in PHP 8, which propagates as an uncaught exception and aborts the entire DAV operation with HTTP 500. To reproduce: enable Secure View watermarking for a group, add your user to that group, then rename or overwrite any Office document. The rename fails immediately with HTTP 500 and the following error appears in nextcloud.log: fclose(): Argument #1 ($stream) must be of type resource, bool given in …/richdocuments/lib/Service/SecureViewService.php:37 Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
shouldSecure()is called withtryOpen=trueon a path that does notexist yet — such as a rename target or a
files_versionssnapshot path —the underlying
fopen()call returnsfalse. In PHP 8, the subsequentfclose(false)throws aTypeErrorthat propagates as an uncaughtexception, aborting the entire DAV operation with HTTP 500.
This causes all rename and file-overwrite operations to fail silently
for users when Secure View watermarking is active.
Error in nextcloud.log (searchable)
Stack trace for rename (MOVE):
Stack trace for file overwrite / version snapshot (PUT):
How to reproduce
occ config:app:set files watermark_enabled --value="yes"occ config:app:set files watermark_allGroups --value="yes"occ config:app:set files watermark_allGroupsList --value="admin".docxor.pdf, then rename it → HTTP 500 / TypeError in logFix
When
fopen()returnsfalse(file does not exist yet), returntrue(assume the target path will be in a secure context). This causes
checkSourceAndTargetto evaluatesource=true && !target=!true=falseand allow the operation instead of throwing
ForbiddenException.This is safe because:
checkFileAccessalways passestryOpen=falseand is completely unaffectedrename()andcopy()operate within the same storage mount, so thetarget inherits the same watermark conditions as the source
falseinstead causesForbiddenExceptionon every renamewhen Secure View is active — equally broken, just differently
Checklist