Repository navigation
fix: reject unresolved host paths and bound native filename scans - #152
Conversation
## Problem The host resolver treats every resolution error as a possible new file. The native bridge scans a new filename before checking its available buffer capacity. ## Solution Allow the missing-file fallback only for NotFound. Refuse other errors from resolution and the final metadata check. Check the joined filename capacity before reading its bytes. Public interfaces and the event layout stay unchanged. ## Tests The invalid-name regression failed on the original resolver. The guard-page bridge test failed before the scan-order fix. Both pass after the changes. The policy suite passed with default and all features. The controlled bridge passed with AddressSanitizer and UndefinedBehaviorSanitizer. The deterministic suite passed 121 cases and skipped eight Linux-only cases. Formatting, workspace clippy with the repository allowances, policy builds, and strict policy documentation passed. The full workspace tests are still running. Signed native kernel tests and Linux execution did not run.
|
Assessment: Approve Focused, correct hardening of two path-validation seams with matching regression tests. The Review Categories
Nicely scoped change with tests that reproduce the defects before the fix. |
|
Investigated the failed macOS Rust job on unchanged head The only failed test was The failed-job retry passed on the same head: 3.991 seconds and 1.723 seconds, ratio 2.32. The full workflow and CI Gate now pass: https://github.com/strands-agents/box/actions/runs/39870890815/attempts/2 . No code, timing threshold, or test selection changed. This clears the failed check and establishes an intermittent timing failure; it does not establish a permanent fix for runner-sensitive benchmark timing. Automated review comments and human approval remain separate. |
I don't quite understand the problem |
|
@ferdingler The description was too abstract. Here is the concrete case: Suppose an application requests a file with a 4,096-character name inside an allowed directory. The operating system rejects the name as too long. Box previously treated that error as “the file does not exist” and approved the path for creation. The fix distinguishes “file not found” from “the filesystem could not check this path.” Box permits a new filename only when the filesystem specifically reports The regression demonstrates incorrect path approval. It does not demonstrate a successful write to that invalid filename. I updated the PR description with this example and explained the separate macOS filename-length check. |
|
Re-reviewed at The "reconcile native bridge regressions with main" commit is a rebase/merge that pulls in main (e.g. My two earlier suggestions are still open and still apply (both non-blocking): a comment in Assessment: Approve — unchanged. |
|
Re-reviewed at The "docs: clarify native path lookup and filename scan guards" commit is docs-only and addresses both of my earlier non-blocking suggestions:
The security-relevant logic in Assessment: Approve. |
Human readable section
Problem: Suppose an application requests a file with a 4,096-character name inside an allowed directory. The operating system rejects the name as too long. Box previously treated that error as “the file does not exist” and approved the path for creation. The regression demonstrates incorrect path approval. It does not demonstrate a successful write to that invalid filename.
The macOS code that reads filesystem events has a separate problem. It scanned filename bytes before checking the supplied length. A malformed length could make that scan read beyond the available memory.
Solution: Box now permits a new filename only when the filesystem specifically reports
NotFound. Other errors stop path approval. The macOS event code checks the filename length before it scans or copies the bytes.Trade-off: File creation still works when the filename is valid and the file does not exist. Other filesystem errors stop approval. A separate process can still change a path between the check and the later operation.
Description
PathResolver::approve_hostchecks whether an existing path can be resolved or a new filename is absent. It now rejects resolution and metadata errors other thanNotFound. This resolver also serves callers outside the macOS event code.The macOS function
new_pathcombines a directory path and a filename. It now rejects a filename that exceeds the remaining path capacity before inspecting its bytes.The public API, configuration, event layout, and policy actions stay unchanged.
The tests reproduce invalid-name approval and an oversized filename scan before the fixes. The corrected event code also passes AddressSanitizer and UndefinedBehaviorSanitizer, tools that detect memory errors and undefined behavior. The memory-access test uses synthetic event data. It does not establish that a workload can cause Apple to supply a malformed event.
Prepared with Codex assistance at Kevin's request. Codex reviewed the diff. Independent human review remains pending.
Related Issues
None. This is a focused path-validation change.
Type of Change
Bug fix
Testing
Conflict repair validation
Updated to
bb4a11aby merging currentmain. The bridge keeps both filename-bound checks and permission-event checks.The all-feature policy suite passed on Linux, with seven existing ignored tests. Native macOS bridge checks passed normally and with AddressSanitizer and UndefinedBehaviorSanitizer. The native test used exactly the candidate's two C source files, verified by SHA-256. Formatting and policy lint passed with CONTRIBUTING's documented workspace allowances. Bare strict lint reports existing vendored-shell warnings.
Independent review found no actionable issues. Hosted checks are queued for this revision. The earlier results below retain their original revision and scope.
Local platform: macOS 27.0.1 ARM64, Rust 1.98.1. Tested source:
f0ed0d7.cargo test -p strands-box-policywith default features and--all-featurestest-native-filesystem --test bridge-fsanitize=address,undefinedbash test-integ/run.shagainst the local buildRUSTDOCFLAGS="-D warnings" cargo doc -p strands-box-policy --all-features --no-depscargo fmt --allandjust clippyjust checkscripts/test-all.sh box-examplesThe invalid-name regression failed against the original resolver. The guard-page bridge test terminated before the scan-order fix and passed afterward. The symbolic-link loop test is a compatibility control. Signed native kernel tests and Linux execution did not run.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsThe full workspace run failed in unchanged egress tests while clients wrote large request bodies. All 15 tests passed when the same test binary ran serially. This does not make the original workspace run green. The literal strict clippy command above was not used; CONTRIBUTING prescribes
just clippywith vendored-code allowances. GitHub checks and automated review are queued.Checklist
Kevin confirmed the author ownership checklist item. No repository documentation change is required for this correction behind existing interfaces.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.