Repository navigation
Added a little check to hide snap packages - #6
Merged
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6 +/- ##
==========================================
- Coverage 86.94% 86.46% -0.49%
==========================================
Files 6 6
Lines 360 362 +2
==========================================
Hits 313 313
- Misses 29 30 +1
- Partials 18 19 +1
Continue to review full report at Codecov.
|
dundee
requested changes
Jan 4, 2021
dundee
left a comment
Owner
There was a problem hiding this comment.
Thanks for your contribution! One suggestion in comments.
Owner
|
Thank you! |
dundee
added a commit
that referenced
this pull request
Sep 14, 2026
* Add Web UI user actions (delete, reveal) on top of read-only Treemap PR Restores the delete/reveal endpoints, the loopback-only action security check, and the frontend workflow (delete confirmation modal, O/D shortcuts) that were split out of the read-only + Treemap PR per review feedback (#651). Rebase onto master once that PR merges so this becomes a standalone actions-only PR. * Harden web UI action requests: per-run token + fetch-metadata checks The X-GDU-Action header used to be a hardcoded "1", so it added no real protection beyond the loopback check. Generate a random token per server run (crypto/rand) instead, serve it to the frontend only over the local-only status endpoint/SSE stream, and require an exact constant-time match on delete/reveal requests. Also reject action requests whose Sec-Fetch-Site/Origin headers don't match this server's own origin, so a page on another site or another browser tab cannot trigger a mutating request even via a same-origin loopback connection. * Deliver the action token via the served URL, not the status API Serving the action token in /api/v1/status meant any local user who could reach the port (not just the one who launched gdu) could read it with a plain curl request and forge delete/reveal calls, defeating the token's purpose entirely. Deliver it the way Jupyter Notebook does instead: generate it once at startup, append it as a query parameter to the URL that's printed to this process's own terminal and opened in the browser, and have the frontend read it from its own location once at load. The read-only endpoints (status, nodes, tree, devices, events) are untouched and stay exactly as unauthenticated as before - only the one piece of data that must stay private moves off the open API. Also set Referrer-Policy: no-referrer on the SPA response so the token-bearing URL can't leak via the Referer header if the page ever gains an outbound link. * Restore refreshNode/setLoadError lost in rebase onto merged Treemap master, rebuild dist Rebasing the actions branch onto master (which now has the squashed Treemap PR #651) silently dropped refreshNode/setLoadError/clearTree wiring during the 3-way merge of model.tsx, since master's version of that file diverged from the pre-split branch it was cherry-picked against. TreeMapView depends on both for post-delete refresh, so typecheck caught the gap immediately. Also rebuilds the frontend bundle so dist/ matches the merged source. * fix after manual tests * fix test cov * applyed option #3 #659 (comment) * Issue #2 fixed: all routes reject DNS-rebinding hosts while allowing literal IPs and the configured --web-listen hostname. * Issue #3 fixed: delete now rechecks the parent with Lstat; changed/symlink parents return 409. Regression test confirms outside files remain untouched. * Issue #4 fixed: scanned roots under the multi-path virtual root can no longer be deleted. Regression test added. * Issue #5 fixed: relative and flag-like reveal paths are rejected before launcher arguments are constructed. Regression test added. * Issue #6 fixed: reveal request bodies are limited to 1 MiB before JSON decoding. Regression test added. * Issue #7 fixed: action token and delete-confirm preference survive reload via sessionStorage; token is stripped before React loads. Embedded bundle rebuilt. * Issue #8 fixed: documented GDU_ALLOW_DELETE_WITH_FILTER=1, its risk, and intentional Reveal behavior under --no-delete. * fix(webui): re-check that a path resolves inside its scanned root The parent Lstat check added for review issue #3 only catches a symlink in the immediate parent. os.Lstat declines to follow the final component of a path but still resolves every component above it, so swapping a *grandparent* resolves straight through to a real directory, reports IsDir, and passes. The attacker needs nothing beyond what the existing test already assumes - write access to the scanned root - so the guard was bypassed just by aiming one level deeper. TestDeleteEndpointRejectsSwappedAncestor covers that shape: before this change it returns 204 and deletes the file outside the tree. Both nodes and their scanned root are now fully resolved with EvalSymlinks and re-checked for containment, which catches a swap at any depth. Resolving both sides keeps a root legitimately reached through a symlink (macOS /tmp) from looking like an escape. A path that no longer resolves is allowed through, since os.RemoveAll is a no-op on it and deletion should stay idempotent when the item was removed in another window. This narrows the window to the microseconds between check and removal rather than closing it; doing that needs openat-style traversal in pkg/remove, which the terminal UI shares and which is worth its own change. Also takes the virtual-root lookup's read under the lock its three neighbours already use. Not reachable now that deleting a scanned root is refused - that was its only trigger - but it is the odd one out. * refactor(webui): share the archive type check and name reveal consistently isArchiveDescendant and isArchiveRoot each switched over the same two synthetic node types; a third archive type would have had to be added in both places. Extracted as isArchiveType. openPath, the revealPath field and handleReveal were three names for one operation, so the function becomes revealInFileManager. Its comment now also records why the absolute-path guard exists (report files are untrusted input) and why "--" is not used instead (explorer does not honour it). browserCommand and revealCommand are deliberately left separate: they differ on Windows, where a URL goes to rundll32 and a path goes to explorer, so merging them would mean parameterising the one case that differs. * fix(webui): harden token storage and drop the Backspace delete binding The inline script in index.html stored the token before stripping it from the URL, so a sessionStorage throw (private-mode browser, storage disabled by policy) skipped the strip and left the token sitting in the address bar - precisely what the script exists to prevent. The strip now runs regardless, and the store is wrapped. The same wrapping is applied to the four accesses in model.tsx so a throw costs the actions rather than the whole app. A tab with no token now says so instead of firing a request that can only come back as a bare 403 with nothing pointing at the cause. Backspace is no longer a delete shortcut. Every desktop file manager binds it to "go up one level", so a user reaching for it here would expect to navigate, not to destroy the selected item; D and Delete are unchanged, and the help modal already listed only those two. Also extracts the useLatest hook duplicated between model.tsx and TreeMapView.tsx, and covers the skip-confirmation preference surviving a reload, which had no test. * docs: record the web UI scope of --no-delete and --trash-command CONTRIBUTING asks for configuration.md and gdu.1.md to follow a behaviour or flag change. This feature widened two flags without either being updated: --no-delete now also hides the web UI's delete action and makes the server reject the request, and --trash-command now also backs the web UI's "Move to Trash". The filter restriction is stated per frontend rather than as one rule: the terminal UI gates on time filters, while the web UI gates on any active filter, file-type filters included, because SetTimeFilter and the type filters both set FilteringFiles. Saying "file or time filters" for both read as parity that does not exist. * chore(webui): rebuild embedded frontend assets * fix(webui): resolve the containing directory, not the node, before delete TestDeleteNodeEndpointPropagatesRemovalError failed on Linux with 409 where it expected 500. Resolving the node itself needs search permission on the directory holding it, so the chmod-0 parent the test sets up made EvalSymlinks fail with EACCES, and an ordinary permission-denied removal was reported as a relocation instead of being left to os.RemoveAll. The same mistake was stricter than os.RemoveAll in the other direction: RemoveAll unlinks a final-component symlink rather than following it, so a link merely pointing outside the scanned tree was refused even though removing it only unlinks the link, which lives inside the tree. That made ordinary symlinks undeletable from the web UI - covered now by TestDeleteEndpointAllowsSymlinkPointingOutside, which fails with 409 before this change. Resolving the containing directory instead mirrors exactly what RemoveAll resolves, and still rejects an ancestor swapped at any depth: both existing symlink tests continue to pass. Verified on Linux in a container as a non-root user, since Docker's default root bypasses the permission check the test relies on. --------- Co-authored-by: Daniel Milde <[email protected]>
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.
With this check, if you have snapd installed you won't have dozens of snap mounts cluttering the UI.