Skip to content

Fix for delete confirmation text - #2

Merged
dundee merged 1 commit into
dundee:masterfrom
petasittek:master
Dec 28, 2020
Merged

dundee merged 1 commit into
dundee:masterfrom
petasittek:master

Conversation

@petasittek

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Dec 28, 2020

Copy link
Copy Markdown

Codecov Report

Merging #2 (50f7b3e) into master (764a662) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master       #2   +/-   ##
=======================================
  Coverage   77.91%   77.91%           
=======================================
  Files           5        5           
  Lines         249      249           
=======================================
  Hits          194      194           
  Misses         42       42           
  Partials       13       13           
Impacted Files Coverage Δ
cli.go 81.16% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 764a662...50f7b3e. Read the comment docs.

@dundee dundee left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dundee
dundee merged commit 86a9cce into dundee:master Dec 28, 2020
zoza1982 added a commit to zoza1982/gdu that referenced this pull request Oct 23, 2025
Fix critical bugs causing panic when navigating back to parent directories
in incremental caching mode:

Bug #1: ParentDir marker methods called unsafely
- ParentDir is a marker object where most methods panic by design
- Code called GetName() on ParentDir objects causing crashes
- Added type assertion checks before calling any ParentDir methods

Bug dundee#2: AnalyzePath tried to manipulate ParentDir markers
- AnalyzePath called GetFiles() and AddFile() on ParentDir markers
- Added defensive check to detect ParentDir and skip manipulation
- When ParentDir detected, treat as new top directory instead

Changes:
- tui/tui.go: Use type assertion to safely detect and handle ParentDir
- tui/actions.go: Add ParentDir check in AnalyzePath before method calls
- tui/parentdir_navigation_test.go: Comprehensive tests for regression prevention

All tests pass including new ParentDir navigation tests.

Fixes navigation flow:
1. User enters subdirectory (works)
2. User selects ".." to go back (now works - was crashing)
3. Can navigate up/down directory tree without panics
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