Skip to content

feat(browser-policy): resolve and pin aliased local workspace roots once at start-up - #308

Merged
Hona merged 6 commits into
devfrom
browser-ui/sec-alias-root
Nov 21, 2026
Merged

Hona merged 6 commits into
devfrom
browser-ui/sec-alias-root

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Restores all six local workspace features (Reveal across Files/Review/Location card/Home/Settings/drafts, Open in, reply link right-click menu, inline video, legacy file:// HTML previews, and Files/Review drag-out) when a workspace is opened through a local symlink or NTFS junction alias, lifting #294's known limitation while closing all READER-12 findings in notes/review-rd294.md.

Specification & Fixes (Including All Five First-Read Findings)

  1. One process-wide immutable lazy pin table, fail-closed at cap (features/open-in/src/lib.rs, apps/desktop/src/workspace/system/open_in.rs, apps/desktop/src/session/meta/open.rs, apps/desktop/src/shell/tabs/actions.rs, features/files/src/{host,links}.rs, apps/desktop/src/surfaces/{files/mod,browser/mod}.rs):
    • Moved pins out of per-window OpenIn into one process-wide PINNED_ROOTS: OnceLock<Mutex<HashMap<String, Option<String>>>> shared across all windows (keyed by normalized raw path, created lazily on first use / App::open / set_draft_dir, immutable for the life of the process; restart to re-pin; fails closed returning None past MAX_PINNED_ROOTS = 4096, never falling open to live re-resolution).
    • Draft-session reply links (features/files/src/links.rs:242-265) and set_draft_dir route through the exact same process-wide pin table (FilesHost::draft_physical_directory).
    • Parked sidecar tabs (browser_file_roots) use pinned_sidecar_root so switching to a remote server does not falsely drop their pinned root.
    • verify_within_root and verify_local_path remain strictly non-alias (O_NOFOLLOW / FILE_FLAG_OPEN_REPARSE_POINT).
  2. Block $HOME AND every ancestor of $HOME, plus cache resolved $HOME once (crates/browser-policy/src/workspace_root.rs, lib.rs):
    • Added "/var/home" to is_broad_root_lex, and updated is_home_broad_lex to reject any lex that is a proper prefix/ancestor of home_lex (case-folded on Windows/macOS) ΓÇö blocking /var/home, /export/home, D:\Profiles, etc.
    • Added resolve_local_home(raw_home) backed by a process-wide OnceLock<Mutex<...>> cache so $HOME is walked at most once instead of once per root.
  3. Engine stays strictly non-alias; handle_path::pin_root resolves before touching (apps/browser-engine/src/preview/handle_path.rs):
    • apps/browser-engine/src/engine.rs::safe_roots stays strictly on browser_policy::is_safe_local_workspace_root (desktop always sends the pinned physical root; engine never resolves aliases itself).
    • Reordered preview/handle_path.rs::pin_root to call browser_policy::resolve_local_root(workspace) (local reparse metadata / openat(O_NOFOLLOW), zero SMB/autofs) before os::pin_dir(Path::new(&verified.path)), and uses cached resolve_local_home.
  4. macOS APFS canonical casing (crates/browser-policy/src/local_fs/unix.rs):
    • resolve_root_open and verify_path_open use fcntl(fd, F_GETPATH) (failing closed on macOS; /proc/self/fd/<fd> on Linux) and is_home_broad_lex folds case on Windows and macOS.
  5. Zero boot syscall regression (lazy pinning):
    • Removed all eager boot/list pinning from boot.rs, incoming.rs, recent_page.rs, projects.rs, peer.rs, and cost.rs.

Coverage of the Two Refused Ancestry Cases from #294

  • Linux /home -> /var/home (Fedora Silverblue / Kinoite / Atomic / Bazzite / ostree): YES ΓÇö covered for workspaces. Opening /home/<user>/<repo> resolves once via readlinkat + is_local_mount + /proc/self/fd to /var/home/<user>/<repo> across all 6 workspace features; $HOME, its system subfolders, AND /var/home (ancestor of $HOME) remain blocked. Arbitrary unpinned outside-workspace links written as /home/... remain refused by strictly non-alias verify_local_path (O_NOFOLLOW); /var/home/... works.
  • Windows volume or Dev Drive mounted at a folder (C:\DevDrive -> \??\Volume{GUID}\): NO ΓÇö intentionally fail-closed. Without a drive letter there is no non-reparse DOS <drive>:\ path to pin (GetFinalPathNameByHandleW(VOLUME_NAME_DOS) returns either reparse-crossed \\?\C:\DevDrive\... or ERROR_PATH_NOT_FOUND, \\?\Volume{GUID}\... is rejected across safe_local_reveal_path/file:///SHOpenFolderAndSelectItems/editors, and allowing mount points in non-alias walks weakens the strict no-reparse boundary). Workaround: assign a drive letter (Windows's default for Dev Drives).

200-Project Scratch-Home Start-Up Benchmark (Windows, 3 Interleaved Runs Each)

Measured via --launch-trace --launch-trace-io on a scratch home with 200 local project directories + 200 sessions (proof/browser-ui/followup-alias/boot200-bench.json):

Arm (median [minΓÇômax]) proj200 UI file.open calls proj200 UI I/O (┬╡s) Total UI I/O calls Total UI I/O (┬╡s) All-thread I/O calls
Floor (0 projects) 0 [0ΓÇô0] 0 ┬╡s [0ΓÇô0] 4,369 [4,369ΓÇô4,370] 77,589 ┬╡s [71,687ΓÇô86,493] 4,413 [4,413ΓÇô4,414]
Before (eager f71a9c27, 200 projects) 200 [200ΓÇô200] 2,524 ┬╡s [2,344ΓÇô2,783] 5,969 [5,969ΓÇô5,970] (+1,600) 86,775 ┬╡s [83,892ΓÇô106,591] (+9,186 ┬╡s) 6,013 [6,013ΓÇô6,014]
After (lazy f222621a, 200 projects) 0 [0ΓÇô0] 0 ┬╡s [0ΓÇô0] 4,369 [4,369ΓÇô4,369] (+0 vs floor) 81,620 ┬╡s [69,469ΓÇô89,850] (inside floor spread) 4,413 [4,413ΓÇô4,413] (+0 vs floor)

Driven Proof (Windows Live + Target Checks)

Case Result
Workspace opened via NTFS junction ws-alias -> workspace Lazily pinned on App::open to physical workspace; good.mp4 loads (clip-*), reply menu on inside.md offers Open file + Reveal (revealing physical workspace\inside.md)
Hostile junction inside aliased workspace (junc-outside/page.html, junc-outside/clip.mp4) Blocked: 0 outside target opens, 0 /api/fs/read/ fallback reads
Mid-session re-point attack: delete & re-point ws-alias -> outside AFTER App::open pins workspace Subsequent video click (secret.mp4) and Reveal stay pinned to original workspace: 0 outside\ opens, 0 secret.mp4 opens, Reveal still targets workspace\inside.md
Hostile initial alias ws-evil-win -> C:\Windows Refused (hostileInitialAliasToWindowsRefused: true)
Hostile initial alias ws-evil-home-parent -> parent of $HOME (fake-profiles when USERPROFILE = fake-profiles\alice) Refused (hostileInitialAliasToHomeParentRefused: true)
#281 oc-preview:// engine suite (engine-security-proof.ts) ALL_PASS (15/15 broad roots refused, cross-OS /remote/work remote preview 200/206 ok, Cloud Filter hydrated/dehydrated 200 ok + junction blocked + verified cleanup)
  • Compile checks: scripts/guardrails.ps1 (5/5), browser-policy aarch64-apple-darwin & x86_64-unknown-linux-gnu, Windows check --workspace, scripts/web.ps1 -Check (1041 files / 48 crates), build --manifest-path apps/browser-engine/Cargo.toml, build -p opencode-desktop ΓÇö all 0 errors, 0 warnings.

Merge of dev (head 83b1aa6a, dev 9e3fa56c)

Proof (proof/browser-ui/followup-alias/results.json, debug build at this head before the last dev merge)

Aliased workspace: Play control shown for good.mp4, Open file + Reveal on the physical root, inner junctions blocked, mid-session re-point attack opens nothing outside; hostile alias to C:\Windows: no menu items and no Play control for good.mp4; hostile alias to the parent of $HOME: refused.

Hona added 3 commits November 21, 2026 05:03
…nce at start-up

Restores local workspace features (reveal, Open in, reply link menu, inline video, HTML
previews, drag-out) when a workspace is opened through a symlink or NTFS junction alias
(such as macOS workspace symlinks, Fedora Silverblue `/home -> /var/home`, or Windows
directory junctions), closing all three findings from the alias-resolver review:

- `crates/browser-policy/src/local_fs/{mod,windows,unix}.rs` & `workspace_root.rs`:
  - Add `resolve_local_root` (`FSCTL_GET_REPARSE_POINT` on Windows; `openat(O_NOFOLLOW)` +
    `readlinkat` + kernel `fcntl(F_GETPATH)` / `/proc/self/fd` canonical path on Unix, zero
    SMB/autofs touches, bounded 8-hop chains) and `resolve_safe_local_workspace_root`, which
    enforces the broad/system/home block on both raw and kernel-canonical physical paths
    case-insensitively on Windows and macOS (and against canonicalized `home`), returning the
    resolved physical root.
  - Keep `verify_within_root` and `verify_local_path` strictly non-alias so re-pointing an
    alias after start-up can never move the workspace.
- `features/open-in/src/lib.rs`, `apps/desktop/src/workspace/system/open_in.rs`,
  `apps/desktop/src/surfaces/browser/mod.rs`, `apps/desktop/src/surfaces/files/{mod,reply}.rs`,
  `features/files/src/{host,links,ops}.rs`, `apps/desktop/src/shell/view/location_card.rs`:
  - Cache/pin each local workspace's resolved physical root once per window (`OpenIn::pinned_local_root`)
    and pass ONLY that pinned physical root — never the raw alias — to `browser_file_roots`,
    HTML preview links, local video confinement, reply menus, Open in, Reveal, and drag-out.
- `apps/browser-engine/src/engine.rs`:
  - Resolve and pin local `file_roots` once in `safe_roots` via
    `browser_policy::resolve_safe_local_workspace_root`.
…eys, and close macOS F_GETPATH & engine pin_root home gaps
Hona added a commit that referenced this pull request Nov 20, 2026
…310)

- Update UP-095-UI evidence to reflect that the 4 #294 findings remained
  present from 0.0.0-dev-440 through published 0.0.0-dev-449 (b62e698)
- Refresh open browser PR security-review states (#296 4th read, #301 3rd
  read, #303 2nd read, #307 updated after 1st read, #308 1st read)
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR test build retired — merged into dev. Install or auto-update OpenCode (Rune) from https://anoma.ly/release/opencode/desktop-rune/dev/macos-arm64-dmg.

Hona added 3 commits November 21, 2026 06:06
…l-closed pin table, home-ancestor block, cached home, pre-pin_dir resolve, draft pins)

Per READER-12's first read of #308 (notes/review-rd294.md):
1. Move workspace root pins from per-window `OpenIn` to one process-wide immutable
   `PINNED_ROOTS` table (`OnceLock<Mutex<HashMap<String, Option<String>>>>`) shared across all
   windows; fail closed (`None`) past `MAX_PINNED_ROOTS = 4096` (never fall open to live alias
   re-resolution) and document key, lazy lifecycle, immutability, and restart-to-repin in one
   comment.
2. Add `/var/home` to `is_broad_root_lex` and block any proper ancestor of `home_lex` in
   `is_home_broad_lex` (closing `/var/home`, `/export/home`, `D:\Profiles` parent-of-home
   aliases).
3. Reorder `apps/browser-engine/src/preview/handle_path.rs::pin_root` to resolve `workspace`
   via `browser_policy::resolve_local_root` BEFORE calling `os::pin_dir` (zero UNC/autofs touch
   before refusal).
4. Revert `apps/browser-engine/src/engine.rs::safe_roots` back to strict non-alias
   `is_safe_local_workspace_root` (engine receives pinned physical roots from desktop and never
   resolves aliases itself), fix parked-sidecar `browser_file_roots` (`pinned_sidecar_root`), and
   route draft-session links (`features/files/src/links.rs:242-251`, `set_draft_dir`) through the
   exact same process-wide pin table.
5. Cache resolved `$HOME` once per process (`browser_policy::resolve_local_home`) and remove all
   eager boot/list pinning (`boot.rs`, `incoming.rs`, `recent_page.rs`, `projects.rs`, `peer.rs`,
   `cost.rs`), pinning lazily on first use / `App::open` / `set_draft_dir` (eliminating +1,600
   UI-thread `file.open` syscalls at 200-project boot: 5,969 -> 4,369 = exact 0-project floor).
# Conflicts:
#	apps/desktop/src/surfaces/files/reply.rs
#	features/files/src/links.rs
#	features/files/src/ops.rs
# Conflicts:
#	crates/browser-policy/src/local_fs/unix.rs
@Hona
Hona merged commit a32190a into dev Nov 21, 2026
7 checks passed
@Hona
Hona deleted the browser-ui/sec-alias-root branch November 21, 2026 02:37
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.

1 participant