Skip to content

fix(box): refuse credential stores beneath the Shell and Monty floor - #434

Open
priyasingh2111 wants to merge 7 commits into
mainfrom
feature/broker-credential-store-floor
Open

priyasingh2111 wants to merge 7 commits into
mainfrom
feature/broker-credential-store-floor

Conversation

@priyasingh2111

@priyasingh2111 priyasingh2111 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Human readable section

Problem: Box keeps an agent away from credential files such as SSH keys and AWS config, but that protection only covered the agent's own sandbox. A request through Box's built-in shell or Python (zsh -c ..., python3 -c ...) went around it. So a broad policy like "allow reading everything under the home" let a prompt-injected agent read ~/.ssh/id_rsa, or plant a line in ~/.aws/config that the AWS CLI later runs as the operator, outside any box.

Solution: The built-in shell and Python now apply the same credential-file protection as the sandbox, from the same list of protected locations (~/.ssh, ~/.aws, ~/.gnupg, ~/.netrc, ~/.docker, ~/.kube, gcloud, keychains, browser profiles). A store stays off limits however broad the policy is, unless a policy rule names the path inside that store: for example permit fs:read when { context.input.path == "~/.aws/config" } or like "~/.aws/*". A pattern with a wildcard above the store, such as "~/*" or "~/.aw*", never opens it. Box prints each such rule at startup, and the policy still decides each access. The agent's own [agent.filesystem] entries no longer have any say over the shell and Python: they decide only what the agent's sandbox reaches.

Why a policy rule and not a box.toml entry: an earlier commit in this PR let an [agent.filesystem] entry that names a store open it to the shell and Python too, to match the sandbox. That tied two things together: to let the shell read ~/.aws under policy, the operator also had to give the agent's own sandbox direct access to ~/.aws, with no policy decision in the path. The last commit removes that coupling and uses the rule the ticket suggested instead.

Before and after: the sandbox and Shell/Monty side by side

Situation Agent / tool sandbox Shell / Monty before Shell / Monty after
A broad rule over the home (read = ["~"], or a policy like "~/*") Refused at startup Stores readable and writable ❌ Store paths refused ✅
A policy rule names a path inside a store (path == "~/.aws/config" or like "~/.aws/*") Not affected Allowed, like any path Opened for exactly the paths the rule names; policy still decides; printed at startup ✅
An [agent.filesystem] entry names a store (read = ["~/.aws"]) Granted, announced at startup Ignored Still ignored: it opens the sandbox only ✅ no coupling
An fs:read rule vs an fs:write rule — No distinction fs:read opens reads only, fs:write opens changes only ✅
A rule that only appears under ! or in unless, or a forbid — — Opens nothing ✅
Changing a directory that holds a store (for example renaming ~/.config) No grant can cover it Allowed ❌ Refused ✅
Another spelling of a store (~/.AWS, ~/.awſ) Same file to the kernel, so refused Allowed ❌ Refused ✅
A store created after the box starts Refused by its path Allowed ❌ Refused ✅
Moving a file out of a store a rule opened for writes — Allowed ❌ Refused ✅

Trade-off: A policy that relied on a broad rule to reach a store through the shell or Python now gets a refusal until a rule names the path inside the store. This floor is now the one floor a permit can lift, so it no longer sits fully beneath policy: once a rule names a store path, a second, broader permit can also decide that path without the naming rule's other conditions (for example a temporal budget or an unless clause). Write a forbid for a file that must stay closed. An fs:write rule opens every kind of change on the paths it names, because the floor sees "a change", not which verb. Only the listed stores are covered; a broad rule still reaches everything else under the home. A script that walks the home and inspects every entry gets a refusal on each store. Each request costs one disk lookup per store spelling (about 70 µs per read in a debug build).

What we tested:

Test Setup Result
a_home_wide_permit_reaches_no_credential_store_through_either_interpreter The finding's ~/* policy; read ~/.ssh/id_rsa and append to ~/.aws/config through zsh and python3 Key not returned, config unchanged, an ordinary file still reads ✅
a_store_a_read_permit_names_reads_and_stays_unwritable The ~/* policy plus permit fs:read when path like "~/.aws/*" ~/.aws/config reads, a write is refused, ~/.ssh stays refused, the rule is printed at startup ✅
an_agent_entry_naming_a_store_opens_it_to_neither_interpreter The ~/* policy and read = ["~/.aws"] in box.toml Shell and Python are still refused ✅
a_write_permit_cannot_move_a_store_file_out_through_either_interpreter An fs:write rule on ~/.aws/sso/cache/*; move a token into the home Refused, the token stays put; a rename inside what the rule names works ✅
an_absent_store_cannot_be_created_under_a_spelling_that_folds_to_its_name ~/.aws absent; mkdir ~/.awſ and write a config into it Refused, nothing planted ✅
a_prepared_directory_cannot_be_renamed_onto_an_absent_store Rename a prepared directory onto .aws, .AWS, .awſ Refused ✅
a_declared_home_granted_to_the_agent_keeps_its_stores_from_the_interpreters env.HOME is its own directory with read and write granted The sandbox reaches that home's .aws; Shell and Python are refused ✅
a_parent_of_a_lifted_store_cannot_be_moved_out_through_either_interpreter A rule opens the Chrome profile; move the parent Google elsewhere Refused through the shell and Python ✅
reach.rs credential_store_tests (22 unit tests) Exact file vs pattern, read vs write, wildcards above a store, !/unless/forbid, a reload, letter case, Unicode spellings, links, enclosing directories, a declared home, disclosure All pass ✅
policy/tests/path_permits.rs (5 tests) Which rules name a path, a reload, and a 500 KB path against a many-wildcard pattern All pass; the long match finishes well under a second ✅
macOS full suites strands-box and strands-box-policy, --all-features, plus fmt, clippy, cargo doc -D warnings Pass; the one failure was the known MCP timing test modern_cancellation_releases_active_capacity, which passes alone ✅
Linux (local Ubuntu VM) Credential floor e2e, box_shell, box_filesystem, box unit tests, policy suites Pass ✅. box_shell_cwd and box_installation fail identically on unmodified main in that VM, because its image links pwd, ln, and env to a multi-call binary; CI runs them ✅

Details

The sandbox refuses any grant that encloses a credential store (~/.ssh, ~/.aws, ~/.gnupg, keychains, browser profiles), but the hosted Strands Shell and Monty never consulted that list. With a broad policy such as permit fs:read when path like "~/*", a prompt-injected workload could read ~/.ssh/id_rsa through the python3 or zsh alias, or append credential_process to ~/.aws/config, which the AWS CLI later runs as the operator outside any box.

What changes for an operator

  • Shell and Monty refuse a path at or inside a credential store, whatever policy permits, and refuse a change to a directory that holds one.
  • A permit lifts that refusal for the paths its own context.input.path literal or like pattern matches, when the text before its first wildcard sits inside the store (or the literal is the store itself). Only comparisons in a when clause count, outside every !; unless, if, and forbid open nothing. fs:read opens reads, fs:write opens changes; fs:delete or fs:move alone opens nothing.
  • Box prints each such rule on stderr at startup (strands-box: policy: … opens ~/.aws/config in the credential store ~/.aws to the Shell and Python (fs:read)), and prints a rule a policy reload adds before it first opens anything.
  • [agent.filesystem] entries affect the agent's sandbox only.
  • A Shell or Monty rename that would carry store content out of the store, or move a directory that holds a store, is refused.
  • A store matches by folded spelling and by its on-disk identity at decision time (letter case, the non-ASCII letters case-insensitive APFS treats as ASCII, stores created or linked after startup). A rule must spell the path exactly as the store is named.

Interfaces and decisions this depends on

  • strands-box-containment: one additive pub use, credential_store_anchors(home), so the grant check and the new floor read one store list.
  • strands-box-policy: one additive façade type, PathPermit, and PolicyEngine::path_permits(), which lists the paths the installed permits name and follows a reload. Matching is linear in the path length.
  • Root AGENTS.md: "Policy is the only authorizer" now states this one floor a permit can lift; the "Filesystem reach" paragraph goes back to "the agent's filesystem lists govern its sandbox alone".
  • The decision entry no-credential-floor-sits-beneath-the-interpreters is rewritten in place (anchor kept) and records why the box.toml coupling, an interpreter-only key, a forbid, and a warning each lost.
  • No CLI, box.toml key, record, protocol, alias, policy action, or environment name moves.

One existing test changed, and why. box_shell.rs::a_matching_leaf_reads_and_writes_announced_credentials_and_the_main_workload_does_not declared [tool.wc] and [tool.touch]. The Shell implements both commands, so its own builtins read and wrote ~/.aws in the trusted process, and the test passed through this defect. It now uses cksum and dd, which really run in their own leaf sandboxes.

Residuals, stated in the docs rather than closed

  • A lifted path skips the naming rule's other conditions when a broader permit also matches it (crates/box/AGENTS.md).
  • An fs:write rule opens every change on its paths, because approve_mutation does not carry the verb.
  • A write entry on a store lets the agent's own system calls move the store's files elsewhere, where a broad rule then reads them through the interpreters.
  • The fold table is not a full Unicode fold; a sweep of every code point on case-insensitive APFS found 11 that compare equal to ASCII, and the table maps all of them. Linux case-folding directories were not measured.
  • The floor covers only the listed stores.

Related Issues

Closes the gap recorded in docs/design/decisions.md#no-credential-floor-sits-beneath-the-interpreters.

Type of Change

Bug fix

Testing

On macOS 26.6 arm64 and in a local Ubuntu 26.10 arm64 VM, on the final commit:

  • cargo test -p strands-box --all-features and cargo test -p strands-box-policy with and without --all-features.

  • cargo fmt --check, cargo clippy --all-targets (with and without --all-features for the policy crate), and RUSTDOCFLAGS="-D warnings" cargo doc -p strands-box-policy: clean, no warnings in the changed crates.

  • A feature-critic review before the commit; its findings (a backtracking like matcher, the reload disclosure, and doc gaps) are fixed in the same commit.

  • Linux: box_shell_cwd and box_installation fail with the same test names on unmodified main in that VM (its pwd, ln, and env are links to a multi-call binary); everything else passes.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)

  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@priyasingh2111
priyasingh2111 marked this pull request as ready for review November 12, 2026 23:11
Comment thread crates/box/src/run/broker/reach.rs Resolved
Comment thread AGENTS.md Outdated

The agent's filesystem lists govern its sandbox alone. Each tool gets its reach from its own
`[tool.<name>]` table. An absent filesystem section grants no direct reach. These grants bypass
The agent's filesystem lists govern its sandbox, with one exception: a `read` or `write` entry that

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important (blocks merge until a maintainer records approval): This PR changes frozen surfaces and governance files, and the record does not show the explicit approval that the root AGENTS.md requires.

Rules: The root AGENTS.md says:

  • "Get the user's explicit approval before writing code that changes … An interface … Additions, renames, and narrowings count", and the frozen surfaces include "each mechanism crate's pub use set".
  • "An agent cannot approve its own change."
  • "Edit this file only when the user explicitly asks."
  • From the Decisions section: "Record an entry in docs/design/decisions.md only after the user decides it."

This PR:

  • adds credential_store_anchors to the strands-box-containment pub use set (19 → 20 names);
  • narrows what policy can permit through Shell and Monty, which is a premise-level change to "Filesystem reach";
  • rewrites this paragraph of the root AGENTS.md;
  • replaces the no-credential-floor-sits-beneath-the-interpreters decision with a new one under the same anchor.

The description names each of these, which is what the contract asks for. It does not say who approved them.

Suggestion: Have a maintainer approve each of the four on the PR, for example in a comment or with the api/needs-review label, before merge. Then the decision rewrite and the AGENTS.md edit carry a recorded decision rather than the author's own.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The approval request above was posted before 4ccdbea, and it now describes a design this PR no longer has. Its item 2 says an [agent.filesystem] entry opens a store. After 4ccdbea, only a permit that names a path inside the store opens it, and an agent entry opens nothing (an_agent_entry_naming_a_store_opens_it_to_neither_interpreter). An approval given for that list would cover the old design. This is the current set that needs a maintainer's approval:

  1. The strands-box-containment pub use set gains credential_store_anchors (19 → 20).
  2. The strands-box-policy façade gains PathPermit (60 → 61 with --all-features) and PolicyEngine::path_permits. crates/policy/AGENTS.md says: "This crate is interface-frozen: the pub use façade… An operator's policy file is their source code."
  3. A foundational premise changes. The root AGENTS.md premise "Policy is the only authorizer… Deny-only floors stay beneath policy" now has an exception. Under it, a permit's literal text lifts a floor, even when that permit doesn't decide the request. crates/box/AGENTS.md records the residual: "A lifted path skips the naming rule's other conditions." The "Filesystem reach" paragraph is also rewritten.
  4. The no-credential-floor-sits-beneath-the-interpreters decision is rewritten again, for the permit-based design.
  5. A behavior change for Shell and Monty: stores are refused even under a home-wide permit, unless a permit names a path inside the store. Box also prints a new strands-box: policy: … opens … to the Shell and Python stderr line.

The root AGENTS.md says: "Get the user's explicit approval before writing code that changes… A foundational premise", and "An agent cannot approve its own change." Could the maintainer approve against this list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated for the current design (4ccdbea and 182fa1e): the exception is now a policy rule that names a path inside the store, not a box.toml entry. Could a maintainer confirm these?

  1. The new pub use export credential_store_anchors in strands-box-containment (19 → 20 names).
  2. The new policy API PathPermit and PolicyEngine::path_permits() in strands-box-policy (60 → 61 names with --all-features).
  3. The root AGENTS.md premise "deny-only floors stay beneath policy" now has one exception: a permit that names a path inside a credential store, with no wildcard above it, lifts the Shell and Monty floor for that path. The "Filesystem reach" paragraph goes back to "the agent's filesystem lists govern its sandbox alone".
  4. The rewrite of the decision no-credential-floor-sits-beneath-the-interpreters, with its anchor kept.
  5. The behavior change: Shell and Monty refuse credential stores even under a home-wide permit, unless a permit names the path, and Box prints each such rule at startup.

cc @ferdingler

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

The floor works for the operator home: it is deny-only, it sits beneath policy, and it reads one store list. Two problems remain. The floor is stricter than the sandbox for a declared env.HOME and gives the operator a remedy they can't configure, and the frozen-surface changes need a recorded maintainer approval.

Review details
  • Correctness: The interpreters refuse stores under a declared agent home, but config refuses the one entry that would lift that refusal. See the inline comment on reach.rs.
  • Contract: There are frozen-surface and governance edits (pub use, a policy narrowing, root AGENTS.md, the decision rewrite) with no recorded approval. See the inline comment on AGENTS.md.
  • Verification: On Linux x86_64, the 16 credential_store_tests and the floors.rs anchor test pass. I did not run the end-to-end suite.

Assumptions and rules checked that held

  • Policy is still the only authorizer: lifting the floor never permits anything, and every access still goes to policy.
  • Stores come from one list owner, containment::credential_store_anchors. Box keeps no list of its own.
  • Every symlink, data-volume, and case-variant (fold) route into an operator-home store canonicalizes to the store and is refused.
  • A rename out of a write entry is refused, both for a file and for the whole store directory. A rename of a prepared directory onto an absent store is refused under every folded spelling.
  • Reading a store's content always needs a read grant, so cp and cat through Shell or Monty can't leak a write-only store.
  • No hard-link operation exists in Shell or Monty, so rename is the only relocation path.
  • Picking the matching grant by first match can't depend on entry order, because config refuses nested entries of one operation (require_no_overlap).
  • An entry for an absent path, or a deny entry that encloses a granted store, is refused at config, so neither reaches with_credential_store_grants.
  • A refused Locate while searching PATH falls through to the next directory, and a refused glob entry is dropped, so neither aborts a command.

The box_shell.rs change from wc/touch to cksum/dd is a sharp catch: the old test passed only because Shell builtins read ~/.aws in the trusted process.

Comment thread crates/box/src/run/broker/reach.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 07973aa)

07973aa fixes the declared-home finding. Its change to the encloses check opens a new path: renaming a parent directory moves a granted store's content outside its write entry (inline comment on reach.rs:530). The approval thread on AGENTS.md:72 is still open, and the PR still records no maintainer approval.

Checked in this commit and held
  • A declared-home lift covers only stores outside the operator home. shared and canonical_home are both canonicalized, so when the two homes are the same, the filter leaves nothing.
  • The lift applies only to subtree entries. A read_file/write_file entry can't enclose a store.
  • An operator-home store stays refused when an entry encloses the declared home.
  • An entry that encloses an operator-home store is still refused at config, so no lift reaches one.
  • A rename of a file or directory inside a lifted declared-home store to outside it is still refused.

I verified this with temporary unit-test probes on Linux x86_64 and removed them afterwards. I did not run the end-to-end suite.

@priyasingh2111
priyasingh2111 force-pushed the feature/broker-credential-store-floor branch from 07973aa to bd7cf9c Compare November 13, 2026 21:10
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of bd7cf9c)

bd7cf9c closes the parent-directory rename path from my last review. The one blocker left is the recorded maintainer approval for the frozen-surface and governance edits; the thread on AGENTS.md:72 is still open. I left one non-blocking note on reach.rs:570: a rename stays inside its entry but is still refused, and the docs give a remedy for it that doesn't work.

Checked in this commit and held
  • Both rename entry points, Shell approve_rename and Monty's rename effect, call refuse_store_relocation with the approved source, so neither interpreter bypasses the new branch.
  • A source that holds a granted store is refused for every destination, including one the host does not back (None).
  • A source with no store inside it is not judged, so ordinary renames are unchanged.
  • stores_inside is shared by the encloses check and the relocation check. The two can't drift apart.
  • An existing store under another spelling (case fold, data volume, symlinked store) is found by its canonical path, but only when the source is a real directory.
  • Deleting a parent that holds only granted stores is a write those grants already cover, so it is consistent with the sandbox.
  • Copying a granted store's content elsewhere needs its read grant. That matches the existing rule that a read grant lets the agent copy.

Verification: the 19 credential_store_tests pass on Linux x86_64, plus temporary probes that I removed. I did not run the end-to-end suite.

Comment thread crates/box/src/run/broker/reach.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of fdd4533, which squashes the branch onto main)

fdd4533 resolves my last non-blocking note (reply on that thread), and I found no new correctness problems. One blocker remains. The PR edits frozen surfaces and governance files: the containment pub use set, a policy narrowing, the root AGENTS.md "Filesystem reach" paragraph, and the rewrite of no-credential-floor-sits-beneath-the-interpreters. The PR record still shows no maintainer approval for these edits, and the root AGENTS.md requires one ("An agent cannot approve its own change"). See the open thread on AGENTS.md:72.

Checked in this commit and held
  • Counting only existing stores on the rename source loses no store content. An absent anchor has nothing in it, and the destination side still refuses renames onto absent stores.
  • Only a granted store can reach refuse_store_relocation this way. A parent that holds an ungranted store, existing or not, is still refused earlier by the encloses check, which still counts absent anchors.
  • A granted store that is a symlink to a target outside its parent keeps its floor after the parent is renamed, because credential_store_paths holds the canonical target from startup. I checked this with a temporary probe on Linux.
  • A source that is a file, or a directory with no store under it, is allowed whatever the destination, just as on main.
  • A store that exists under another spelling (case fold, U+017F) is found because each spelling is canonicalized. The source is compared as the approved, canonical path.
  • Each new refusal message is documented with its remedy in shell.md, monty.md, and security.md, and the remedy works.

Verification: the 19 credential_store_tests pass on Linux x86_64, plus a temporary probe that I removed. I did not run the end-to-end suite.

Comment thread crates/box/src/run/broker/reach.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 4ccdbea)

4ccdbea moves what lifts the floor from [agent.filesystem] entries to permit rules that name a path inside a store. I found two blockers:

  • A rename leak. An in-store rename can move write-only content onto a read-lifted path, where the workload can read it. See the inline comment on reach.rs:501. At fdd4533 this rename was refused.
  • A stale approval request. The open request on the AGENTS.md thread describes the superseded design. It also leaves out two new items: the PathPermit and PolicyEngine::path_permits additions to the policy façade, and the exception added to the root premise "Policy is the only authorizer". The reply on that thread gives the current list.
Checked in this commit and held
  • Only a comparison in a when clause counts, through && and ||. Comparisons in unless, under !, in if, or in a rule with no action constraint lift nothing, so they fail closed.
  • A pattern with a wildcard above the store (~/*, ~/.aw*) lifts nothing. A literal that names the store itself lifts only the store directory, not its contents.
  • An fs:read permit lifts only reads and an fs:write permit only changes. An fs:delete or fs:move permit lifts nothing.
  • The lift matches the canonical approved path. credential_store_anchors includes each store's resolved spelling, so a symlinked store opens only when the canonical path is named. That is consistent with how the resolver treats symlinks.
  • PathPermit::matches takes the leftmost match for each middle literal and checks the last literal as a suffix. That is exact for *-only patterns, and its cost is linear in the path.
  • The schema has one principal (Agent), so ignoring a rule's principal scope opens nothing extra.
  • The lift reads path_permits from the live engine, so a reload adds or removes lifts. A lift is disclosed before its first use.
  • A rename out of the store, onto an absent store, or of a directory that holds an existing lifted store is still refused.

Verification: the 22 credential_store_tests and the 5 crates/policy/tests/path_permits.rs tests pass on Linux x86_64. I confirmed the rename finding with a temporary unit test and removed it afterwards. I did not run the end-to-end suite.

The sandbox refuses every grant that encloses a credential store (`~/.ssh`, `~/.aws`, keychains,
browser profiles), but the hosted Strands Shell and Monty never consulted that list. With a policy
such as `permit fs:read when path like "~/*"`, a prompt-injected workload read `~/.ssh/id_rsa`
through the `python3` or `zsh` alias, and appended `credential_process` to `~/.aws/config`, which
the AWS CLI later ran as the operator outside any box. `decisions.md` recorded the gap and named
the fix: a deny-only floor beneath policy that carries the sandbox's credential list.

- `containment` exports `credential_store_anchors(home)`: every spelling of each
  `credential_store` row under a home (as written, through symbolic links, and on the macOS data
  volume). `credential_store_path` now reads it, so the grant check and the new floor read one
  store list. This is one additive `pub use` name (20 exports); the user approved it.
- `Reach::refuse_forbidden` refuses a path at or inside a store under the operator home or the
  agent's home, and a change to a directory that holds a store. A store matches by folded spelling
  (`folded` maps each letter whose Unicode case fold is ASCII, such as U+017F, which APFS treats as
  `s`) and by the on-disk identity each store spelling has at decision time, so a store created or
  linked after startup counts too. A missing path inside a store gets the same refusal, so the
  message does not disclose whether the store exists.
- An `[agent.filesystem]` entry that names a store or a path inside it lifts the floor for that path:
  `read`/`read_file` for reads, `write`/`write_file` for changes. Policy still decides each access. A
  `deny` entry inside the store stays refused. `Reach::refuse_store_relocation` refuses a Shell or
  Monty rename that carries store content outside the `write` entry that opened it.
- New refusal strings: "resolves into a credential store, ...", "contains a credential store, ...",
  and "would move credential-store content outside ...". No CLI, `box.toml` key, record, protocol,
  alias, policy action, or environment name moved. The behaviour change narrows what a policy
  permits through the interpreters. The user decided it, and the decision entry
  `no-credential-floor-sits-beneath-the-interpreters` is rewritten in place (anchor kept). The root
  `AGENTS.md` "Filesystem reach" rule now states the store exception, with the user's approval.
- `box_shell.rs::a_matching_leaf_reads_and_writes_announced_credentials_and_the_main_workload_does_not`
  used `[tool.wc]` and `[tool.touch]`. The Shell implements both, so `bare_names` skips those tools
  and the Shell's own builtins read and wrote `~/.aws` in the trusted process: the test passed
  through this defect. It now uses `cksum` and `dd`, which run in their own leaf sandboxes.
- Residuals, stated in the docs rather than closed: a `write` entry on a store also lets the
  agent's own system calls move the store's files elsewhere, where the interpreters can read them;
  the fold table is not a full Unicode fold; the floor covers only the listed stores, so a broad
  permit still reaches everything else; a script that inspects each entry of the home gets a
  refusal on each store.
- Docs: decisions, policy, shell, monty, containment, architecture, and limitations design pages;
  security, shell (exit statuses), shell-policy, monty, and config user pages; containment README
  and AGENTS.md; box AGENTS.md; root AGENTS.md.

macOS 26.6 arm64:
- `reach.rs::credential_store_tests` (16): home-wide refusal; read, write, and file entries; list and
  metadata entries lift nothing; a linked store; an enclosing directory; a declared `env.HOME`;
  letter case on an absent store; Unicode spellings that fold to a store name; a store linked after
  startup; missing paths; `deny` inside a store; a rename out of a `write` entry. Each fix was
  removed in turn and its test failed.
- `floors.rs::the_credential_store_anchors_carry_every_spelling_of_each_store`.
- `box_credential_store_floor.rs` (5, end to end through the real aliases):
  `a_home_wide_permit_reaches_no_credential_store_through_either_interpreter` (the finding's
  policy: key not returned, config not appended, ordinary file still reads),
  `a_store_named_by_a_read_entry_reads_and_stays_unwritable`,
  `a_write_entry_cannot_move_a_store_file_out_through_either_interpreter`, and
  `an_absent_store_cannot_be_created_under_a_spelling_that_folds_to_its_name`, and
  `a_prepared_directory_cannot_be_renamed_onto_an_absent_store`. Each fails with its fix removed,
  which reproduces the attack.
- A `stat` of every code point from U+0080 to U+10FFFF on case-insensitive APFS: only U+00DF,
  U+017F, U+1E9E, U+212A, and U+FB00 to U+FB06 compare equal to ASCII, and `folded` maps all eleven.
- Each request now costs one `stat` per store spelling (about 70 microseconds a read in a debug
  build); only a change to a directory also resolves each store.
- `cargo test -p strands-box --all-features --lib`: 944 passed, 1 ignored. `box_shell` 72,
  `box_filesystem` 24, `box_shell_cwd` 15, `box_protected_state` 4, `site_manifest`,
  `documented_commands`, `documented_inputs`: passed. `cargo test -p strands-box-containment
  --all-features`: 331 passed.
- A full `cargo test --workspace --all-features --no-fail-fast` before the last fixes: 5087 passed,
  1 failed (`runtime_mcp_catalog_scaling`, a timing ratio that matched `origin/main` in a 5-run A/B).
  The deterministic suite's `SH-NEG-CURL-403` and `CN-L-03` failed once on a DNS lookup inside the
  box, then passed on this branch and on the base commit.
- clippy: no owned warnings. fmt: clean.
- Not run: Linux (not compiled on this host), and the full workspace suite after the last fixes.
@priyasingh2111
priyasingh2111 force-pushed the feature/broker-credential-store-floor branch from 4ccdbea to 3d816f2 Compare November 17, 2026 06:10
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 3d816f2)

3d816f2 rebases 4ccdbea onto main at 1ccd68a. The PR's own code is unchanged. The only edit in reach.rs is the file_watching: false fixture field that main's #430 needs, and host.rs differs only by the rebase. The two blockers from my last review still stand:

  • Rename leak (reach.rs:501). I re-ran the probe on this commit and it still reproduces. With a write-only permit on ~/.aws/sso/cache/* and a read/write permit on ~/.aws/config, refuse_store_relocation(token.json → config) returns Ok(()). After the move, read(".aws/config") returns the token.
  • Maintainer approval. The approval thread on AGENTS.md still shows no maintainer approval against the current list of five changes.
Checked in this commit and held

Verification: the 22 credential_store_tests pass on Linux x86_64 at 3d816f2, plus the temporary rename probe, which I removed. I did not run the end-to-end suite.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes (re-review of 182fa1e). The code is ready. The one remaining blocker is the maintainer approval.

182fa1e closes the rename leak inside a store (my reply is on the reach.rs thread), and I found no new correctness problems. The approval request on the AGENTS.md thread now lists the current five changes. A maintainer still has to approve them before merge, as the root AGENTS.md requires ("An agent cannot approve its own change").

Checked in this commit and held
  • A file renamed onto a read-lifted path is refused unless a read permit also covers the source. So fs:write alone never makes content readable, whether the source and destination come from one rule or from two.
  • A directory rename inside a store is refused while any fs:read permit opens a path in that store, because no single path check can cover a directory. With no read permit in the store, it is still allowed, and nothing becomes readable.
  • A symlink source is treated as a file, not a directory. The move carries the link, and each later read is judged at the link's canonical target.
  • The new branch runs only after the destination passes the existing same-store check, so renames out of the store and parent-directory moves are refused as before.
  • A read permit that names the store under another spelling (data volume, letter case) lifts no read at all, so it can't hide an exposure from the directory check.
  • Copying or redirecting the content still needs a read lift on the source, so rename is the only path this check needs to cover.
  • shell.md, monty.md, and security.md each document the new refusal with a remedy that works.

Verification: all 25 credential_store_tests pass on Linux x86_64. That is the 24 committed tests, including the 2 new ones, plus a temporary probe that I removed. I did not run the end-to-end suite.

yesyayen added a commit that referenced this pull request Nov 19, 2026
… in the interpreters

## Problem

Strands Shell and Monty refused a change at a `reads` or `deny` path of a secret source, inside it, or above it. To do that, `ConfiguredCommands` matched each mutation against those paths by spelling, by on-disk identity, by a case-folded spelling for a path that is absent, and against each symbolic link on the way. The review of this pull request asked to take that out (comments 4621726643 and 4621802834):

- It is a second path matcher behind the interpreters' hook, with case folding, links, and absent paths, and `limitations.md` still listed gaps in it (two Unicode forms of one name, and each read).
- A floor beneath policy is the place for this. An open pull request (#434) builds that floor for the well-known credential stores, for reads and for changes. A vault at another path is the job of the operator's policy.

## Solution

Remove `ConfiguredCommands::source_paths` and `source_links`, the three checks in `mutation_refusal` that used them, `CommandMutationRefusal::SourcePath`, its reason text in `run/broker/reach.rs`, and `folded`. `ConfiguredCommands::load` and `of_secret_sources` hold the programs alone, as before this pull request.

What stays is the sandbox side, with no changed line:

- Box refuses a grant of the agent, a tool, or a local MCP server that reaches a `reads` or `deny` path, and a write grant over the folder of a symbolic link on the way to one (`filesystem::require_outside_source_paths`), before a source program starts.
- Each sandbox denies those paths.
- The interpreters still refuse a change to the program of a source.

Stated limit: with a declared source, Strands Shell and Monty do not refuse a read or a change of a `reads` or `deny` path, or a change of a symbolic link on the way to one. Policy decides, as it does on `main` for any path. `docs/user/config.md` ("What Box protects"), `docs/design/limitations.md`, and `docs/design/credentials.md` say so, with what an operator can do today: a path condition on each `fs:*` permit and a `forbid` rule for the paths of the vault. This change adds no folder to the credential store list of `containment`.

Interface: the refusal "is at, inside, or above a path that a secret source keeps from each workload, or a link on the way to one" no longer exists. The design page `team/designs/0006-secret-providers.md` said "These protections must also cover the hosted Shell and Python paths". That sentence now says what Box does.

## Tests

Linux x86_64 (an Amazon Linux 2023 container), on the tree of this commit:

- `cargo fmt --all --check`, `cargo build --workspace --all-features --locked`, and `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` pass. The clippy gate refuses dead code, so it proves that each item with no caller left is gone.
- The five doc guard targets pass: `site_manifest`, `documented_inputs`, `four_inputs`, `documented_commands`, `credential_method_scope` (38 tests).
- `cargo test -p strands-box --all-features --lib`: 1,199 passed, 5 failed, 1 ignored. The commit below this one: 1,202 passed, the same 5 failed, 1 ignored. By name, the difference is the three removed tests and one test that has a new name. The 5 failures are the same on `main` in this container: two `kernel::tests::fallback` tests, `a_leafs_shebang_resolves_past_the_alias_directory`, and two `native_enforcement::probe` tests.
- `strands-box-credentials`: 297 and 33 passed. `strands-box-telemetry`: 107 passed, and `the_vault_attaches_a_credential_on_an_ipv6_address` fails here and on `main`, because the container has no IPv6 loopback.

macOS (arm64, Rust 1.96.0), on the tree of this commit: `box_credentials` 38 passed and 1 ignored, `mcp_schema_generation` 27 passed, `run_config` 26 passed. The unit tests of `run::secret_sources`, `run::credential`, `record::config`, and `command` passed (360), and those of `run::commands`, `run::broker::reach`, `run::contain::boundary`, and `record::config::filesystem` passed (164). A secret source loads on macOS only, so these binary tests cover all three commits of this series.

Removed with the code: `a_path_of_a_secret_source_cannot_change_through_an_interpreter`, `a_link_on_the_way_to_a_path_of_a_secret_source_cannot_change_through_an_interpreter`, `an_absent_path_of_a_secret_source_cannot_change_under_another_case`.

Two tests now pin the stated limit, so they fail when a floor in `Reach` refuses one of these paths:

- `reach.rs::the_interpreters_leave_a_path_of_a_secret_source_to_policy` (it was `a_path_of_a_secret_source_refuses_mutation_and_names_its_reason`). A change at a `reads` path, inside it, at an absent `deny` path, and above it passes the reachable paths check, and a change to the program of the same source is refused. An undo patch that puts a stand-in floor under the interpreters makes it fail.
- `box_credentials.rs::a_tool_cannot_see_a_path_of_a_secret_source_and_policy_decides_the_shell` (macOS, a real sandbox; it was `a_tool_cannot_see_and_the_shell_cannot_change_a_path_of_a_secret_source`). A tool cannot see a file under a `reads` path. With a permit for `fs:write`, the Shell changes that file. A `forbid` rule keeps a file under the `reads` path of a second source.

The sandbox side still refuses, and these tests pass unchanged: `filesystem::tests::a_grant_that_reaches_a_path_of_a_secret_source_is_refused`, `a_grant_that_reaches_a_path_of_a_secret_source_through_a_link_is_refused`, `a_grant_that_reaches_an_absent_path_of_a_secret_source_is_refused`, `a_credential_store_of_a_secret_source_is_refused_when_named_exactly`, `boundary::tests::each_boundary_refuses_each_path_of_a_secret_source`, `secret_sources::tests::a_grant_over_a_path_of_a_source_is_refused_and_starts_no_program`, and on macOS `box_credentials.rs::a_grant_over_a_path_of_a_secret_source_is_refused`.

Three undo patches on this tree, one for each protection that stays in this series, each made its tests fail: the name rule finds no owner of a variable (3 tests), the source programs are left out of the protected files (4 tests), and a grant is not judged against the `reads` and `deny` paths (7 tests).

Not run: the full workspace suite, the Linux sandbox suites, and a real `op` or `aws`.

@leo237 leo237 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: Comment. I probed the floor adversarially and found no bypass at 182fa1e. Four things need follow-up. The branch is stale and conflicts with main in the files this floor lives in. The floor misses credential stores that environment variables relocate. A write lift on ~/.aws/config reopens the documented credential_process RCE through the interpreters. A few tests are missing. The earlier bot findings (declared home, parent rename, rename leak) are fixed, and I don't repeat them here. The governance approval thread on AGENTS.md is still the maintainers' to close.

What I tried that holds (no action needed)

  • Wildcard or .. above a store. like "~/.aws/../*" passes names_in_store because its fixed text starts with ~/.aws/. It still lifts nothing outside the store, because store_lift checks the canonical spelled path against the store prefix again. "~/.aw?", "~/*" and "~/.aw*" lift nothing.
  • Disjunctions. In path == "~/.aws/config" || path like "~/*", only the in-store literal lifts. if/then/else, ! and unless lift nothing, so they fail closed.
  • Symlinks. A link planted into a store, a store linked elsewhere, and a store linked after startup are all caught, because approve_host canonicalizes and has_ancestor_among reads identities at decision time. A link the Shell creates has to pass a read lift on its target.
  • Leaks inside a store after 182fa1e. A file rename onto a read-lifted path, a symlink to write-only content, and a directory rename while any fs:read permit opens the store are all refused. Monty has no hard-link or copy primitive, and the Shell has no hard-link pair operation.
  • SetTimes from main (#471) falls into the _ => true arm of mutates, so after the rebase touch on a store counts as a change.
  • matches_pattern: taking the leftmost match for each middle literal and checking ends_with for the last one is correct for Cedar *. pattern_elements merges runs of single-character literals, so fixed_text sees the whole prefix.
  • A poisoned policy lock gives no permits, and no policy gives no lift. Both fail closed.

Findings

  1. Stale against main (must rebase before merge). The merge base is 1ccd68a, 103 commits behind main. git merge-tree reports conflicts in crates/box/src/run/broker/reach.rs, crates/box/src/run/broker/host.rs, crates/policy/src/lib.rs, crates/policy/AGENTS.md, crates/policy/README.md and docs/design/policy.md. Two changes on main touch this design and need a look on the rebased head:

    • #617 adds log-only mode. In a log-only box this floor is the only thing between the workload and ~/.aws. A test that a store stays refused with PolicyEngine::log_only on would pin that.
    • #193 adds Linux filesystem operations. Please check that every new FsOperation or pair operation reaches approve_mutation or approve_rename.

    The CI results below are for the stale head.

  2. Stores that environment variables relocate are not covered (inline on reach.rs:167).

  3. A write lift on ~/.aws/config reopens the credential_process RCE that limitations.md documents, now through the Shell or Monty (inline on host.rs:133). This is not a regression: a home-wide permit already allowed it before this PR. But this PR adds the supported way to grant it, so the disclosure should say what that means.

  4. The store list is incomplete. This PR reuses the sandbox's 12 rows from forbidden-paths.json, which is the right call for consistency. Neither floor names these common stores: ~/.azure, ~/.config/gh, ~/.git-credentials, ~/.npmrc, ~/.pypirc, ~/.cargo/credentials.toml, ~/.terraform.d/credentials.tfrc.json, ~/.vault-token, ~/.pgpass, ~/.password-store and ~/.local/share/keyrings. decisions.md already says that the floor covers only the listed stores. A follow-up issue to widen the shared list would be worth filing, ideally making it operator-extensible.

  5. Test gaps (inline on the integration test): no single-file store through rename or write, no false-positive check for sibling prefixes, and no relative-path or cd route.

  6. Docs and message accuracy (nits, inline).

Tests run locally (Linux x86_64, glibc 2.26): cargo fmt --all --check passes, and cargo test -p strands-box-policy --all-features --test path_permits passes 5/5. I didn't run the strands-box unit or integration suites locally, so for those I relied on CI. At 182fa1e every check is green: Rust unit tests on macos-latest, ubuntu-24.04 and ubuntu-24.04-arm, Lint, Containment Deterministic on all three, and CodeQL. That is CI on the pre-rebase head.

roots.push(canonical);
}
}
let mut credential_stores: Vec<PathBuf> = Vec::new();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important (non-blocking): stores that environment variables relocate are not covered. The anchors come only from the operator home and the agent's home, through credential_store_anchors(home). An operator can set AWS_SHARED_CREDENTIALS_FILE or AWS_CONFIG_FILE (for example ~/work/aws/credentials), KUBECONFIG, DOCKER_CONFIG, GOOGLE_APPLICATION_CREDENTIALS, CLOUDSDK_CONFIG or GNUPGHOME. Real credentials then live at a path this floor doesn't name. Chrome under a non-default XDG_CONFIG_HOME is the same case.

Concrete case: set AWS_SHARED_CREDENTIALS_FILE=~/work/creds/aws and use the home-wide permit from credential_store_tests::HOME_WIDE. Then cat ~/work/creds/aws through the Shell is allowed.

The sandbox floor has the same gap, so this is consistent and not a regression. It's still the most likely way a real operator's secrets reach the interpreters. Two options:

  • Derive extra anchors from the operator's environment at startup, inside containment::credential_store_anchors, so both floors gain them together.
  • Name the gap in a sentence in security.md and decisions.md.

Either is fine for this PR. A follow-up issue for the first would be good.

thread: Option<std::thread::JoinHandle<()>>,
}

/// Disclose on stderr each `permit` that opens a credential store to the interpreters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important (non-blocking): an fs:write lift on ~/.aws/config hands the workload the trusted process. limitations.md:59 documents that write access to ~/.aws plus any aws:// route is remote code execution in the box's trusted process, through credential_process. With this PR, permit(... fs:write ...) when { context.input.path like "~/.aws/*" } becomes the supported way to lift the floor. After that, printf '[default]\ncredential_process = /tmp/x\n' > ~/.aws/config through the Shell gets exactly that RCE.

The disclosure line here reads like any other store permit. Two suggestions:

  • When an fs:write store permit covers ~/.aws/config or the ~/.aws directory and the record declares an aws:// route, refuse it at startup, or print a distinct line that names the RCE.
  • Add the interpreter route to the limitations.md row, which today covers only the agent's own write access.

This isn't a regression, since a home-wide permit already allowed it before this PR. But the PR's docs present the write lift as the safe, deliberate path.

if in_store && self.store_lift(approved, mutates).is_none() {
return Err(Refused::new(reported_as, CREDENTIAL_STORE));
}
if mutates

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: stores_inside(approved, false) counts absent anchors. On a fresh home, mkdir ~/.config is therefore refused with contains a credential store, so no policy may change this directory, and so is mkdir -p ~/.config/myapp when ~/.config doesn't exist yet. No store exists there.

I think counting absent anchors is right, because it stops the workload from planting a ~/.config symlink that would redirect where a later gcloud writes its credentials. But the message misleads, and a missing ~/.config breaks a lot of tools. Two options:

  • A separate reason for the absent case, such as would change where a credential store is created.
  • Allow a plain CreateDir of a real directory, since Symlink and Rename are the operations that redirect.

A test that pins whichever you choose would help.

.chars()
.flat_map(char::escape_default)
.collect();
let line = format!(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: spelling goes through escape_default, but permit.rule() and store reach the operator's stderr raw, and the @id annotation behind rule() can hold \n or ESC. Policy is operator-authored, so the risk is low. Escaping all three would stop a reloaded rule from forging a strands-box: line or emitting terminal control sequences.

const NOTES: &str = "ordinary-notes";

fn plant(home: &Path) {
for store in [".ssh", ".aws"] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test gaps worth closing. The logic looks right to me; these tests would pin it.

  1. A single-file store. plant creates only .ssh and .aws, which are both directories. ~/.netrc is a file anchor. It takes the fixed == store && spelling == store branch of names_in_store, and the same-store check in refuse_store_relocation behaves differently for it. Cover reading, writing and renaming ~/.netrc out through both interpreters.
  2. No false positives on sibling prefixes. The comparison is component-wise today, but nothing pins that. Under HOME_WIDE, ~/.aws-backup/x, ~/.sshrc, ~/.netrc.bak and ~/.config/gcloud-old/x should all stay readable and writable.
  3. Relative-path and cd routes through the Shell. Cover cd ~/.aws && cat credentials and cat ~/notes/../.aws/config. I expect absolute() plus canonicalization to refuse both, but only the absolute spelling is tested end to end.
  4. After the rebase (summary item 1): a store stays refused under PolicyEngine::log_only.

Comment thread docs/user/security.md
```

The second rule protects credential stores, such as `~/.ssh`, `~/.aws`, a keychain, or a browser
profile, under the operator's home: the stores the agent's own grants can never enclose. Strands Shell

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: "under the operator's home" is narrower than the code. Reach::over_with_floor also anchors the stores under a declared [agent] env.HOME, which a_declared_home_carries_its_own_stores tests. Suggest "under the operator's home and the agent's declared home".

Comment thread docs/user/security.md
it, as in `context.input.path == "~/.aws"`. `box run` prints each such rule at startup. Your
`[agent.filesystem]` lists don't lift this refusal: they decide what the agent's own system calls
reach, and Strands Shell and Monty stay refused unless a `permit` names the path. Box refuses a
store under every spelling the file system treats as the same name, including one created after the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: "under every spelling the file system treats as the same name" understates the refusal on Linux. folded applies on every platform, so case-sensitive ext4 also refuses ~/.KUBE and ~/.Aws/config, and a_store_is_refused_in_every_letter_case_whether_or_not_it_exists asserts this on Linux. Failing closed is fine, but the text should say "in any letter case, on every file system". Otherwise a Linux user whose ~/.AWS is refused won't know why.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants