Skip to content

add Treemap feature for web UI - #651

Merged
dundee merged 8 commits into
dundee:masterfrom
mikhail-angelov:feat/add-maptree-to-webui
Sep 4, 2026
Merged

dundee merged 8 commits into
dundee:masterfrom
mikhail-angelov:feat/add-maptree-to-webui

Conversation

@mikhail-angelov

@mikhail-angelov mikhail-angelov commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

This is feature proposal for Web UI
Maybe it will be useful to add Treemap feature for web ui
I allow users to see folders/files sizes as graphical representation, not just sorted list and delete or reveal selected file/folder
this is ui proposal:
image
image

@codecov

codecov Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.28%. Comparing base (c636c61) to head (c0e1ea8).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
webui/tree.go 96.55% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #651      +/-   ##
==========================================
+ Coverage   89.96%   90.28%   +0.32%     
==========================================
  Files          72       72              
  Lines        6445     6495      +50     
==========================================
+ Hits         5798     5864      +66     
+ Misses        646      630      -16     
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread webui/server.go Resolved
Move delete/reveal endpoints, the loopback-action security check, and
their frontend wiring to the separate feat/webui-actions branch per
review feedback (#651), so this PR only adds the read-only
tree API and treemap view.
@mikhail-angelov
mikhail-angelov force-pushed the feat/add-maptree-to-webui branch from 4cf6998 to 5e169fd Compare September 3, 2026 12:42
@dundee
dundee merged commit 0dd3ecb into dundee:master Sep 4, 2026
10 checks passed
@dundee

dundee commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Nice, thanks!

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]>
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