Repository navigation
fix(box): skip hard-link scans when Linux mount and filename checks pass - #381
Conversation
## Problem Counting hard-link names beside a configured tool does not cover additional paths created by filesystem mounts. The optional count also had no time budget. Skipping writable-directory scans on that evidence can miss a protected file. ## Solution Check the current write or mutation target against the retained program and parent-directory descriptors. Permit the shortcut only on one complete ext4, XFS, or tmpfs mount, without another mount of that device or nested mounts in the counted or writable paths. Require the mount table to remain unchanged across the descriptor-based name count. Bound all optional inspection with the existing 30-second cooperative budget. Errors, uncertainty, other filesystem layouts, and macOS retain the existing recursive scan. Preserve launch checks and update the affected documentation. No external interface changes. ## Tests The 25 command unit tests pass. The mount module has 25 passes; its existing namespace fixture is blocked by this host's unchanged nsfs parser defect. The 12 new Linux unit tests detect 13 focused mutations in a standalone harness. The supported-filesystem, duplicate-mount, nested-mount, descriptor-identity, stable-table, inspection-error, and deadline tests cover the added guards. Builds with all features and without default features pass. Clippy passes with the repository's vendored-code allowances, formatting passes, and all 27 site manifest tests pass. Cargo.lock is unchanged. Twenty-five actual Linux compatibility cases pass for echo, Bun, and Rustup running Cargo, including unsafe-link refusals and hosted directory mutations. Those runs use an isolated copy with the existing nsfs parser prerequisite; that unrelated repair is not included here. Six macOS Bun/Cargo runtime cases confirm successful ordinary execution and retained unreadable/unsafe-link refusals. No new mounted-path escape reproduction was performed. Full local suite qualification is incomplete: Linux repeats the nsfs startup blocker; the macOS library reports 797 passes and seven boundary-test failures that refuse /private/tmp. Hosted CI must qualify the final PR revision.
## Problem Late Core messages overwrite the native workload screen. Boxy continues to consume feature/allow-multilink-commands while the command alias scan on main awaits #381. ## Solution Apply merged commit 1e94f57 without changes to this feature branch. The workload keeps its terminal streams. Core retains later diagnostics and prints them after the workload exits. ## Tests - Builds with all features and no default features, Clippy, and formatting pass. - The workspace suite reports 4,766 passed, 2 failed, and 17 ignored. Both failures reproduce on unchanged 53a6c04: the same-folder hard-link refusal test and the tool grammar exit-status test. - Deterministic containment reports 129 passed and 12 Linux-only skips. - The diagnostics unit test and all three terminal integration tests pass. Each fails under its relevant deliberate mutation and passes after restoration. - The local Linux cross-check requires the absent x86_64-linux-gnu-gcc compiler. The merged patch passed Linux CI on its original base.
|
Assessment: Request Changes Reviewed head 4f92080. Since 1d07dfd, the only changes are a merge from Assumptions and rules checked that held
The fallback-on-any-doubt design is careful, and the mount-table parsing has good unit coverage. |
Inspect mounts only for directory targets and retain direct identity checks for files and missing paths. Require shortcut use on independently qualified Linux fixtures, and test incomplete scans separately from file checks. Align the implementation guidance and user documentation with the guarded Linux shortcut and the unchanged macOS scan fallback.
|
Assessment: Comment Reviewed head a9bb66e. a9bb66e resolves all three earlier findings, and I found nothing new in the directory-only gate or in the test rework. The remaining merge gate is not a code change: a maintainer must explicitly approve the changed safety premise, as root Checks that held on a9bb66e
|
|
Counting hard links alone can miss another writable path to a tool program. Linux can display the same folder at both I pushed the mount checks and a follow-up directly to this PR. Box now checks the mount layout before skipping a directory scan. If it cannot verify the layout, it uses the existing scan. Changes to a single file keep their direct checks without inspecting mounts. The trade-off is that fewer Linux filesystem setups can skip scanning. macOS keeps its existing scans. An unreadable subdirectory can therefore still prevent startup where scanning remains necessary. The full Linux and macOS workspace checks passed. The Linux log confirms the shortcut test ran without skipping; all 828 Box library tests passed. Separate tests cover incomplete-scan refusals and protected files. The automated reviewer also reports that disabling the shortcut makes the positive test fail. The complete macOS sandbox-enforcement suite was not rerun; the saved evidence for that suite is stale. Runtime checks of the first guard commit matched 25 expected Linux outcomes and six macOS outcomes, including Bun and Cargo. The Linux runs needed a separate fix for how Box reads the host’s mount information; that fix is not included here. I confirmed the gap by reading the code. Tests with simulated mount information check the guard’s decisions; they do not demonstrate a sandbox escape. |
kevin-orellana
left a comment
There was a problem hiding this comment.
Approved. I approve the guarded Linux approach: Box may skip a writable-directory scan only after verifying both the program's hard-link names and the filesystem mount layout. If those checks cannot establish the required conditions, Box keeps the existing scan. macOS keeps its existing directory scans.
This approval covers a9bb66e, including the regression-test and documentation fixes. The Linux and macOS workspace checks passed. As documented above, the full signed macOS sandbox-enforcement suite was not rerun; this approval does not claim fresh qualification from that suite.
Problem
Strands Box scans writable directories before starting a workload to ensure they contain no hard link to a configured tool program. A hard link is another filename for the same file: writing through either name changes the program. This check applies when the user running Box can write the program and it has multiple hard links.
The program is selected by the first item in the
commandarray under[tool.<name>]inbox.toml. Even when all its hard-link names are in its own protected directory, Box scans the workload's writable directories. An unreadable subdirectory or a directory that changes during inspection can therefore prevent workload startup. Strands Shell and Monty, Box's shell and Python interpreters, repeat the check before requested directory changes and reject the request if inspection is incomplete.Solution
On Linux, skip the recursive scan for a program when Box can establish that all its hard-link names are in its own protected directory and the filesystem's mount layout exposes no additional path to it in the directory being checked. A mount can expose the same files at another path without increasing their hard-link counts, so counting filenames alone is insufficient.
For example, a tool installation can keep
bunandbunxas hard links in a protected tools directory. On a supported mount layout, an unrelated unreadable subdirectory in the writable workspace no longer prevents startup. This requires no package list, executable copies, or newbox.tomlsetting.The optional inspection applies only to directory targets. Files, missing paths, symbolic links, and metadata lookup errors retain the existing direct file-identity checks.
Before each skipped scan, Box requires all of the following:
/).Each optional inspection has a 30-second budget, checked between filesystem calls. It cannot interrupt a blocked call. An unmet condition, error, or timeout returns to the existing recursive scan. macOS retains that scan for directory targets.
The trade-off is that only these Linux layouts can avoid scanning. Where scanning remains necessary, an unreadable directory can still prevent workload startup or cause Box to reject a requested directory change.
The protection boundary remains workload writes to configured programs; updates by unrelated host programs remain outside it. Write grants cannot overwrite the program, change its symbolic-link routes, or replace an enclosing directory. Before each launch, Box verifies the program's identity, link count, owner, group, and mode. Strands Shell and Monty apply the same protections when they perform file operations in Box's trusted process. Configuration keys and error messages do not change. The implementation guidance in
crates/box/AGENTS.mdand the user and design documentation now describe the guarded shortcut.Tests
Local follow-up checks cover commit
a9bb66e:cargo test -p strands-box --all-features --locked --lib run::commands -- --show-output --test-threads=1: 26 test bodies completed, one explicitly skipped, no failures. The development host has an unsupported namespace-filesystem mount record, so this run does not prove positive shortcut use or a forced-false mutation failure.justfilelint allowances and no diagnostics in changed code. Formatting passed.cargo test -p strands-box --test site_manifest --locked --all-features: 27 passed.GitHub checks for
a9bb66epassed the full Linux workspace suite, including all 828 Box library tests. The captured output confirms that the positive shortcut test executed without any of its explicit skip messages. The full macOS workspace suite and its separate native-startup checks also passed. Linux and macOS deterministic containment tests, lint, packaging, the site-manifest check, and the final CI gate passed. The workflow skipped its conditionalVerdictjob as expected. GitHub tested merge0f9ba5f, which combines this head withmainatfbe415c.macOS qualification limit: this workflow did not run the full sandbox-enforcement suite with signed components. Its informational check of saved evidence from an earlier run reported that evidence as stale. That step permits failure, so the overall workflow passed. The current macOS results cover the workspace suite, one native bridge test, and three startup tests without the native-filesystem feature; they do not establish fresh full signed-native qualification.
Automated review of
a9bb66efound all three earlier findings addressed and no new code defect. The reviewer also reports that forcing the shortcut to return false makes the positive test fail on a supported Linux/ext4 runner. That mutation result is reviewer-reported; the direct GitHub test log independently establishes the normal positive result. Formal maintainer approval remains separate.The command tests now separate shortcut use on eligible Linux hosts, refusal after an incomplete directory scan, and direct identity checks for files and missing paths. The shortcut test independently checks whether the host supports its fixture, then requires the shortcut to run. Unsupported hosts report an explicit skip; a skip is not evidence that the shortcut ran.
Tests with simulated mount records cover additional mounts, unsupported filesystems, mismatched identities, changing mount tables, and inspection deadlines. The mount-path concern was identified by source review. These tests do not demonstrate a sandbox escape.
Earlier runtime checks of guard commit
1d07dfdmatched all 25 expected Linux outcomes and six expected macOS outcomes, including Bun and Rustup/Cargo. The Linux runs used a separate repair for an existing filesystem-layout parser failure on the development host; that repair is not included in this PR. The macOS runs required no parser repair. These results cover the guard commit, not the subsequent directory-only optimization.Earlier local broad-suite attempts of guard commit
1d07dfdwere not clean passes. Linux tests encountered the existing mount-table parser failure. The native macOS run stopped after 995 passes, nine failures, and four ignored tests; seven failures involved existing profile fixtures, and two were startup-marker timeouts without a confirmed cause. Hosted results are recorded separately.Type of Change
Bug fix
Related Issues
Follows #347.
cargo test -p strands-box --all-features --lib)cargo fmt --allandcargo clippyfor the changed packages with--all-featuresChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.