Skip to content

fix(sharing): load mind maps from subfolders of public shares - #400

Merged
AndyScherzinger merged 2 commits into
mainfrom
fix/public-subfolder-load
Oct 19, 2026
Merged

AndyScherzinger merged 2 commits into
mainfrom
fix/public-subfolder-load

Conversation

@AndyScherzinger

@AndyScherzinger AndyScherzinger commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Fixes #145

Opening a mind map from a subfolder of a public folder share showed "Load file fail!File not found", and closing the alert closed the viewer.

PublicFileHandlingController::load() built the path as trim($dir.$filename). The frontend sends dir as the file's folder without a trailing slash (dirname() of its path), so /Subfolder and Test 2.km became /SubfolderTest 2.km. At the share root dir is /, which is why files there opened. The logged-in endpoint already joins with a slash, and saving was not affected because the frontend builds the save path itself.

  • The folder and file name are joined with one slash (rtrim($dir, '/') . '/' . $filename), so the share root still resolves to /name.km.
  • A path outside of the share makes Folder::get() throw NotPermittedException. The controller only caught NotFoundException, so such a request ended in a server error page. It now gets the same 404 "File not found". The public save endpoint had the same gap and gets the same fix. Nothing was ever written outside the share; it only answered with a server error.

Testing:

  • PHPUnit: new tests for loading from a subfolder, and for loading and saving a path outside the share. They fail on the old code, and all 8 tests pass with the fix.
  • Nextcloud 32, 35 and 36, a public folder share with mind maps at the root and three subfolder levels, including folder names with spaces: every file loads (200), and in Firefox the subfolder mind maps open from the share without the alert.

Path traversal check, on Nextcloud 32, 35 and 36, with the owner's file next to the shared folder as the target:

  • Load, escape attempts: these all return 404.
    • dir: /../, ../, .., /.., /Subfolder/../.., /./../, /%2e%2e/, /..\, /../../../../etc
    • filename: ../x, ..%2Fx, /../x, ..\x, .., ../../../../etc/passwd
  • Load, paths inside the share: dir ./, /./, ., empty or // load the file inside the share, because Folder::get() normalizes them. Any .. is refused, even one that would stay inside (/Subfolder/..). A filename of . or / resolves to the shared folder itself and returns 400 ("not a file").
  • Save: the same escape paths return 404, and the file outside the share stays unchanged.

A backport to stable-0.1 follows.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

The public load endpoint joined the folder and the file name without a
separator, so a mind map in a subfolder of a public folder share was
looked up as /Subfoldernotes.km and failed with "File not found". Join
them with a slash, as the logged-in endpoint does.

A path outside of the share made Folder::get() throw
NotPermittedException, which ended in a server error; answer it with
"File not found" too.

Fixes #145

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@nextcloud-command nextcloud-command added the AI assisted This PR contains AI-assisted commits label Oct 19, 2026
@AndyScherzinger AndyScherzinger added this to the v0.2.0 milestone Oct 19, 2026
Saving to a path outside of a public folder share made Folder::get()
throw NotPermittedException, which ended in a server error. Nothing was
written, but answer it with "File not found" like the load endpoint.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger AndyScherzinger added the bug Something isn't working label Oct 19, 2026
@AndyScherzinger
AndyScherzinger merged commit f46f6a9 into main Oct 19, 2026
8 checks passed
@AndyScherzinger
AndyScherzinger deleted the fix/public-subfolder-load branch October 19, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI assisted This PR contains AI-assisted commits bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open in Public Share Subfolder -> 404 Not Found

2 participants