Repository navigation
fix(shell): refuse translated and platform metadata addresses before transport - #393
Conversation
|
Assessment: Approve The Assumptions and rules checked that held
Good regression tests: the Monty test checks that the proxy is never contacted, not only that an error comes back. |
|
Assessment: Approve (re-review at The Checked and held: the README's metadata and private-range claims match |
|
Assessment: Approve (re-review at The code has not changed since my first review: Checked and held: the README and |
51930dc to
9d31dee
Compare
|
Assessment: Approve (re-review at The new commit changes only docs and fixes all three open threads. The code ( Checked and held:
|
|
Assessment: Approve (re-review at
Checked and held:
|
c8bdfaf to
3df6136
Compare
|
Assessment: Approve (re-review at This head looks like a rebase of Checked and held: |
|
Assessment: Approve (re-review at The last two commits change only docs and fix my open Checked and held:
|
|
Assessment: Approve (re-review at This commit fixes my Checked and held: each encoding the new lines name refuses the addresses they list. I probed these on this head and each one returned |
|
This also blocks some public destinations, so “public IPv4 addresses stay allowed” is too broad. A translator can map an address in Could we clarify that the allowance applies to I checked this through Shell and Python with a test gateway. The old address check let the request through; the new one blocked it before sending. |
32cf550 to
a575580
Compare
|
@kevin-orellana Good catch, thanks for testing it through Shell and Python. The allowance for a public IPv4 address applies only to |
|
Assessment: Approve (re-review at This commit answers @kevin-orellana's Checked and held:
|
…transport ## Problem The Shell `curl` and the Monty `fetch` call the vendored `check_url_safe` before they send a request to the gateway. Its `is_ip_blocked` did not read the IPv4 address inside a NAT64 (`64:ff9b::/96`) or IPv4-translated (`::ffff:0:0:0/96`) address. It also did not refuse `0.0.0.0/8`, Azure WireServer `168.63.129.16`, or the Alibaba Cloud metadata address `100.100.100.200`. So a literal such as `http://[64:ff9b::a9fe:a9fe]/`, which carries `169.254.169.254`, passed this check. Only authored policy could then refuse it. The example `metadata_addresses` forbids did not name the Azure or Alibaba addresses, so a box that uses an example policy permitted them. ## Solution `is_ip_blocked` in `crates/shell` now applies its IPv4 checks to the address inside the NAT64 and IPv4-translated prefixes. It refuses all of the RFC 8215 local-use prefix `64:ff9b:1::/48`, and it refuses `0.0.0.0/8`, `168.63.129.16`, and `100.100.100.200`. A NAT64 address that carries a public IPv4 address, and the rest of `100.64.0.0/10`, stay allowed. This is an upstream bug. The same change is proposed upstream in strands-agents/shell#240, and `crates/shell/UPSTREAM.md` records the divergence. The four example policies and `docs/user/security.md` add `168.63.129.16` and `100.100.100.200` to `metadata_addresses`. `docs/design/egress.md` lists them. The vendored README and SECURITY.md state the new coverage. A comment in the Monty `fetch` no longer says that the gateway has a compiled floor. No interface changes. ## Tests - `vfs_kernel.rs::url_safety_tests::check_url_safe_blocks_translated_and_platform_metadata_addresses` refuses nine literals. It fails without the change. - `check_url_safe_allows_public_destinations_behind_nat64_and_shared_space` pins the addresses that stay allowed. - `run::broker::python::fetch::tests::a_fetch_to_a_translated_or_platform_metadata_literal_is_refused_before_transport` shows that four literals are refused and no request reaches the proxy. I removed the vendored change and the test failed at `[64:ff9b::a9fe:a9fe]`. I restored the change and the test passed. - `shipped_examples` in `strands-box` and `strands-box-policy` pass, so each edited example policy still loads. - `cargo test --workspace --all-features`: 4884 passed, 0 failed, 17 ignored. The `just clippy` flags report no warnings. `cargo fmt --all --check` is clean. These tests did not run: a live NAT64 translator, and requests to real metadata services. The Shell `curl` path has no new Box-level test. It calls the same `check_url_safe` that the vendored unit tests cover.
…cy.md metadata rule
… drop a ticket ID from a test comment
… allowance to 64:ff9b::/96
a575580 to
7a5c604
Compare
|
Assessment: Approve (re-review at This commit fixes my Checked and held: the "unconditional in Box" claim matches |
Human readable section
Problem: Before Box sends a Shell
curlor Montyfetchrequest to the gateway, it checks the URL against a list of addresses an agent must never reach, such as cloud metadata services. That check missed some ways to write those addresses. For example,http://[64:ff9b::a9fe:a9fe]/is the metadata address169.254.169.254written in an IPv6 form, and it passed. Two platform metadata addresses outside169.254.0.0/16also passed. Only the operator's policy could then stop the request.Solution: Box's copy of the Shell check now reads the IPv4 address inside these IPv6 forms and refuses it when it is blocked. It also refuses the two metadata addresses and
0.0.0.0/8. The example policies and docs add the same two metadata addresses. The same fix is upstream: strands-agents/shell#240 merged, and strands-agents/shell#244 corrects one code comment. So Box and upstream stay the same.Trade-off: The check still lists the addresses it refuses, so a new metadata endpoint or IPv6 form needs another change. A NAT64 network that uses its own prefix is still not covered. A rule that allows only globally reachable addresses would end this, but it changes behaviour and is left for a separate change.
Description
The Shell
curland the Montyfetchrun the vendoredcheck_url_safebefore they send a request to the gateway. That check missed IPv6 encodings that #227 already taught the policy layer to read:64:ff9b::/96::ffff:0:0:0/96It also did not refuse
0.0.0.0/8, Azure WireServer168.63.129.16, or the Alibaba Cloud metadata address100.100.100.200. Sohttp://[64:ff9b::a9fe:a9fe]/, which carries169.254.169.254, passed the check, and only authored policy stood behind it. The examplemetadata_addressesforbids did not name the Azure or Alibaba addresses either.Decisions
crates/shell, notcrates/box. It's an upstream bug inis_ip_blocked, so it's recorded inUPSTREAM.md. The same change merged upstream in fix: refuse translated and platform metadata addresses in the SSRF guard shell#240 (def7ab7), with a comment fix in docs: correct the reason for refusing 0.0.0.0/8 in is_ip_blocked shell#244, so the vendor switch can take the upstream version and drop thisUPSTREAM.mdentry.64:ff9b:1::/48(RFC 8215) is refused whole, even when a translator maps it to a public IPv4 address such as8.8.8.8. It is never globally routed, and its embedding offset is chosen by the network. Only a64:ff9b::/96address that carries a public IPv4 address stays allowed.0.0.0.0/8is refused because it is reserved and not globally reachable. It is not refused because of how an OS routes it: since Linux 5.3, nonzero0/8addresses are ordinary unicast destinations. This vendored copy has noallowed_urls, so the refusal is unconditional in Box. Upstream'sallowed_urlsarrives with the vendor move.100.64.0.0/10. The rest of that shared address space is not a metadata range, and refusing it would break internal services.docs/user/security.mdgain the two addresses. This keeps them in line with "metadata protection is policy": the gateway still compiles no list.fetch.rsis corrected. It said the gateway has a compiled floor for DNS-resolved destinations; authored policy decides those.Not covered here
64:ff9b::/96) is still not unwrapped. This is the same documented limit as feat(policy)!: split the pinned address into ip4 and ip6 #227.Checks CI cannot perform: no live NAT64 translator and no real metadata service were used.
Background: what the SSRF guard does
The Shell's
curlruns this check before any request leaves the host. The agent controls the URL, but the host sends the request. So without the check, a misled agent could make the host:The check refuses loopback, private, link-local and metadata addresses. In Box it checks the URL literal only. The gateway decides each resolved address by policy.
Follow-up: the list keeps growing
The guard lists the addresses it refuses. So each new IPv6 encoding of an IPv4 address, and each cloud metadata endpoint outside
169.254.0.0/16, is a new gap. This PR closes the known gaps, not that pattern.A lasting fix would invert the rule: allow only globally reachable addresses (IANA special-purpose registries) and refuse the rest unless
allowed_urlsgrants them. All IPv4-in-IPv6 encodings would be unwrapped in one helper. Only the metadata endpoints that sit on public addresses, such as168.63.129.16, would still need to be named. That is a behaviour change: internal services in special ranges would need anallowed_urlsentry. So it needs maintainer agreement and is left for a separate change.Related Issues
#227 (policy-layer fold), strands-agents/shell#240 (upstream change)
Type of Change
Bug fix
Testing
check_url_safe_blocks_translated_and_platform_metadata_addressesfails without the change and passes with it.a_fetch_to_a_translated_or_platform_metadata_literal_is_refused_before_transportfails at[64:ff9b::a9fe:a9fe]with the vendored change removed, and passes with it restored. It asserts that no request reaches the proxy.shipped_examples(strands-box,strands-box-policy) pass, so every edited example policy still loads.cargo test --workspace --all-features: 4884 passed, 0 failed, 17 ignored.I ran the relevant suites (
just check, orcargo test --workspace --all-features)If I touched Rust, I ran
cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.