Repository navigation
fix: refuse translated and platform metadata addresses in the SSRF guard - #240
Conversation
is_ip_blocked checked the IPv4 address inside IPv4-mapped, IPv4-compatible, 6to4, and Teredo addresses, but not inside the NAT64 well-known prefix 64:ff9b::/96 or the IPv4-translated prefix ::ffff:0:0:0/96. It also had no entry for 0.0.0.0/8, Azure WireServer 168.63.129.16, or the Alibaba Cloud metadata address 100.100.100.200. So check_url_safe and SafeResolver accepted an address such as 64:ff9b::a9fe:a9fe, which carries 169.254.169.254. The guard now applies the IPv4 checks to the address inside the NAT64 and IPv4-translated prefixes, refuses the whole RFC 8215 local-use prefix 64:ff9b:1::/48, and 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. allowed_urls behaves as before. Tests: check_url_safe_blocks_translated_and_platform_metadata_addresses fails without the change and passes with it. check_url_safe_allows_public_destinations_behind_nat64_and_shared_space pins the addresses that stay allowed. cargo test: 2081 passed, 0 failed. cargo fmt --check is clean, and clippy warnings are unchanged from main.
…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.
…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.
| || v4.is_link_local() | ||
| || v4.is_unspecified() | ||
| || v4.octets()[..2] == [169, 254] | ||
| // 0.0.0.0/8 "this network": Linux routes 0.x.y.z to the local host. |
There was a problem hiding this comment.
The localhost-routing claim is inaccurate for Box’s Amazon Linux 2023 baseline. Since Linux 5.3, nonzero addresses in 0.0.0.0/8 are treated as ordinary network destinations. Could we replace that explanation with “Block 0.0.0.0/8 under the default network policy”? That states the intended restriction without relying on the incorrect routing claim.
There was a problem hiding this comment.
You're right, thanks. Since Linux 5.3, nonzero 0.0.0.0/8 addresses are ordinary unicast destinations, so the comment gives the wrong reason. The block still stands: 0/8 is reserved and not globally reachable, and 0.0.0.0 itself was already refused by is_unspecified(). Shell has no policy layer, so I worded the comment as "reserved and not globally reachable, so curl refuses it by default; allowed_urls can still permit it". The fix is in #244, since this PR is merged. Box's copy gets the same comment in strands-agents/box#393.
…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.
…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.
Human readable section
Problem:
curlrefuses requests to addresses an agent must never reach, such as cloud metadata services, so the agent cannot read the host's credentials. The 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, andcurlsent it. Two platform metadata addresses outside169.254.0.0/16also went through.Solution: The 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. Public addresses, including public addresses written in these IPv6 forms, still work. README and SECURITY.md now list exactly what the check covers.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 SSRF guard misses some IPv6 encodings of IPv4 addresses and some platform metadata addresses.
is_ip_blockedalready checks the IPv4 address inside IPv4-mapped, IPv4-compatible, 6to4 and Teredo addresses, but not inside two other encodings:64:ff9b::/96::ffff:0:0:0/96It also has no entry for
0.0.0.0/8, Azure WireServer168.63.129.16, or the Alibaba Cloud metadata address100.100.100.200. Socheck_url_safe(URL literals) andSafeResolver(DNS answers) both accept, for example,64:ff9b::a9fe:a9fe, which carries169.254.169.254.This change:
/96and IPv4-translated prefixes64:ff9b:1::/48, because it is never globally routed and its embedding offset is chosen by the operator0.0.0.0/8,168.63.129.16and100.100.100.200What stays allowed:
64:ff9b::808:808.100.64.0.0/10. Shared address space is not a metadata range, so only the Alibaba address is refused.allowed_urls, which behaves as before.README and SECURITY.md now list what the guard covers.
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. It checks both the URL literal and the address a hostname resolves to.
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
None.
Documentation PR
None. README.md and SECURITY.md are updated in this PR.
Type of Change
Bug fix
Testing
check_url_safe_blocks_translated_and_platform_metadata_addressescovers NAT64 (/96, also in dotted form), RFC 8215, IPv4-translated, WireServer, Alibaba and0.0.0.0/8. It fails onmainand passes with this change.check_url_safe_allows_public_destinations_behind_nat64_and_shared_spacepins the addresses that stay allowed.cargo xtask check --rust-onlypasses.cargo test: 2081 passed, 0 failed.cargo fmt --all -- --checkis clean.cargo clippy --workspace --all-targetsreports the same warnings asmain.Not run: the Python and Node binding suites (this PR does not touch them), a live NAT64 translator, and requests to real metadata services.
I ran the relevant test suites for the bindings I touched (
cargo test --workspace --all-targets,pytest tests/python,npm test)If I touched Rust, I ran
cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.