Repository navigation
feat(browser-policy): resolve and pin aliased local workspace roots once at start-up - #308
Merged
Merged
Conversation
…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`.
…and sessions load at start-up
…eys, and close macOS F_GETPATH & engine pin_root home gaps
|
PR test build retired — merged into |
…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
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.
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 innotes/review-rd294.md.Specification & Fixes (Including All Five First-Read Findings)
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):OpenIninto one process-widePINNED_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 returningNonepastMAX_PINNED_ROOTS = 4096, never falling open to live re-resolution).features/files/src/links.rs:242-265) andset_draft_dirroute through the exact same process-wide pin table (FilesHost::draft_physical_directory).browser_file_roots) usepinned_sidecar_rootso switching to a remote server does not falsely drop their pinned root.verify_within_rootandverify_local_pathremain strictly non-alias (O_NOFOLLOW/FILE_FLAG_OPEN_REPARSE_POINT).$HOMEAND every ancestor of$HOME, plus cache resolved$HOMEonce (crates/browser-policy/src/workspace_root.rs,lib.rs):"/var/home"tois_broad_root_lex, and updatedis_home_broad_lexto reject anylexthat is a proper prefix/ancestor ofhome_lex(case-folded on Windows/macOS) ΓÇö blocking/var/home,/export/home,D:\Profiles, etc.resolve_local_home(raw_home)backed by a process-wideOnceLock<Mutex<...>>cache so$HOMEis walked at most once instead of once per root.handle_path::pin_rootresolves before touching (apps/browser-engine/src/preview/handle_path.rs):apps/browser-engine/src/engine.rs::safe_rootsstays strictly onbrowser_policy::is_safe_local_workspace_root(desktop always sends the pinned physical root; engine never resolves aliases itself).preview/handle_path.rs::pin_rootto callbrowser_policy::resolve_local_root(workspace)(local reparse metadata /openat(O_NOFOLLOW), zero SMB/autofs) beforeos::pin_dir(Path::new(&verified.path)), and uses cachedresolve_local_home.crates/browser-policy/src/local_fs/unix.rs):resolve_root_openandverify_path_openusefcntl(fd, F_GETPATH)(failing closed on macOS;/proc/self/fd/<fd>on Linux) andis_home_broad_lexfolds case on Windows and macOS.boot.rs,incoming.rs,recent_page.rs,projects.rs,peer.rs, andcost.rs.Coverage of the Two Refused Ancestry Cases from
#294/home -> /var/home(Fedora Silverblue / Kinoite / Atomic / Bazzite / ostree): YES ΓÇö covered for workspaces. Opening/home/<user>/<repo>resolves once viareadlinkat+is_local_mount+/proc/self/fdto/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-aliasverify_local_path(O_NOFOLLOW);/var/home/...works.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\...orERROR_PATH_NOT_FOUND,\\?\Volume{GUID}\...is rejected acrosssafe_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-ioon a scratch home with 200 local project directories + 200 sessions (proof/browser-ui/followup-alias/boot200-bench.json):[minΓÇômax])proj200UIfile.opencallsproj200UI I/O (┬╡s)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]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]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)
ws-alias -> workspaceApp::opento physicalworkspace;good.mp4loads (clip-*), reply menu oninside.mdoffers Open file + Reveal (revealing physicalworkspace\inside.md)junc-outside/page.html,junc-outside/clip.mp4)/api/fs/read/fallback readsws-alias -> outsideAFTERApp::openpins workspacesecret.mp4) and Reveal stay pinned to originalworkspace: 0outside\opens, 0secret.mp4opens, Reveal still targetsworkspace\inside.mdws-evil-win -> C:\WindowshostileInitialAliasToWindowsRefused: true)ws-evil-home-parent -> parent of $HOME(fake-profileswhenUSERPROFILE = fake-profiles\alice)hostileInitialAliasToHomeParentRefused: true)#281oc-preview://engine suite (engine-security-proof.ts)ALL_PASS(15/15 broad roots refused, cross-OS/remote/workremote preview 200/206 ok, Cloud Filter hydrated/dehydrated 200 ok + junction blocked + verified cleanup)scripts/guardrails.ps1(5/5),browser-policyaarch64-apple-darwin&x86_64-unknown-linux-gnu, Windowscheck --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(head83b1aa6a,dev9e3fa56c)apps/desktop/src/surfaces/files/reply.rsreconciled with fix(files): require click-to-load for all inline reply videos #307's click-to-load videos:video(display): a localLink::Insidevideo needspinned_local_root; a workspace whose aliased root was refused at start-up shows no Play control. Remote sessions keep fix(files): require click-to-load for all inline reply videos #307's lexical check;Link::Outsidekeeps fix(files): require click-to-load for all inline reply videos #307's lexical pre-check.load_video(Play click): a localLink::Insidevideo resolves underpinned_local_rootbeforevideo::source(verify_within_root);Link::Outsidestays strictverify_local_path.features/files/src/{links,ops}.rs: feat(browser): route previews via oc-preview://, harden PreviewFetch, and ban raw file:// unconditionally #303'soc-preview://route (open_workspace_preview) replaces this branch'sfile://page tab; the physical-root reclassification of aliased links stays.crates/browser-policy/src/local_fs/unix.rs: feat(browser): native 500 ms guarded app-link review bar and confirmed OS scheme handoff (PR B) #315/fix(browser-policy,open-in): confine plugin file opens, harden OS hand-off and mailto, limit third-party Links:Open to http(s) #338's case-insensitive-volume check (is_case_insensitive_volume) is kept inverify_within_root.location_card::reveal_targetshowsrune.files.root.refused("This folder is reached through a link that couldn't be checked at start-up, so its file links and Reveal are turned off. Restart OpenCode to try again.") instead of a generic failure; a missing folder still gets its own message.\vs/, 8.3 short names on Windows) pin separately and count separately against the fail-closed cap.Proof (
proof/browser-ui/followup-alias/results.json, debug build at this head before the lastdevmerge)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 toC:\Windows: no menu items and no Play control forgood.mp4; hostile alias to the parent of$HOME: refused.