Honor dirId when creating files through a folder share - #58
Draft
kubrickfr wants to merge 1 commit into
Draft
Conversation
getDir() only looked at dirId on the logged-in branch. With a share token, getNodeByToken() returns the share root and dirId was silently ignored, so /ajax/new created the file in the share root and reported the share root as parentId regardless of the requested target folder. Resolve dirId inside the share with getFirstNodeById(), the same way getFile() resolves a file inside a shared folder, and refuse ids that do not resolve to a folder within the share. The guard that the resolved node is a folder also replaces the fatal error that a file-share token used to cause in getNonExistingName(). create() now maps NotFoundException and ForbiddenException from getDir() to its documented JSON error responses instead of letting them escape as a 500, which makes the previously dead "folder was not found" branch meaningful. Covered by new unit tests for the share-token create path and by two end-to-end tests that exercise an anonymous visitor creating a file in a subfolder of an editable folder share. Co-Authored-By: Claude Fable 5 <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.
What happens today
getDir()only readsdirIdon the logged-in branch. As soon as a share token is present,getNodeByToken()returns the share root anddirIdis never looked at again.POST /ajax/newtherefore always creates the file in the share root — and reports the share root asparentId, so the client is told the wrong location too.Before the security fix in 4.3.6 the logged-in-with-token case crashed with a 500; since 4.3.6 it returns HTTP 200 with the file silently placed in the wrong folder. (The 4.3.6 reordering of
getDir()was done for parity withgetFile(), butgetFile()'s descend-into-the-share step was not ported along with it.)Two smaller pre-existing issues sit next to it:
/ajax/newreachedgetNonExistingName()on aFileand died with a fatal error (500).create()never caught anythinggetDir()throws, so its"The required folder was not found"error branch was dead code — every failure surfaced as a 500 instead of the endpoint's documented JSON error shape.The fix
getDir()now resolvesdirIdinside the share withFolder::getFirstNodeById(), exactly the waygetFile()resolves a file inside a shared folder (so an id outside the share subtree yields not-found, and adirIdequal to the share root id keeps working).Folder, which also fixes the file-share-token fatal.create()mapsNotFoundException/ForbiddenExceptionfromgetDir()to its JSON error responses, making the previously dead error branch meaningful.Tests
dirId,dirIdoutside the share, file-share token, and a token without create permission.dirId(asserting both the reportedparentIdand the file's physical location over WebDAV), and adirIdpointing outside the share is rejected without creating anything. Supporting this,E2ETestCasegains adavMkcol()helper andcreateLinkShare()accepts share permissions.Full suite results: unit 112/112 green (19 pre-existing skips untouched here), e2e 25/25 green against Nextcloud 33.0.8.
Note: #59 re-enables the 19 skipped unit tests; the two branches touch neighbouring test code, so whichever merges second may need a trivial rebase.
🤖 Generated with Claude Code