Skip to content

fix(shell): refuse translated and platform metadata addresses before transport - #393

Merged
priyasingh2111 merged 9 commits into
mainfrom
feature/shell-ssrf-nat64-platform-metadata
Nov 12, 2026
Merged

priyasingh2111 merged 9 commits into
mainfrom
feature/shell-ssrf-nat64-platform-metadata

Conversation

@priyasingh2111

@priyasingh2111 priyasingh2111 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Human readable section

Problem: Before Box sends a Shell curl or Monty fetch request 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 address 169.254.169.254 written in an IPv6 form, and it passed. Two platform metadata addresses outside 169.254.0.0/16 also 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 curl and the Monty fetch run the vendored check_url_safe before they send a request to the gateway. That check missed IPv6 encodings that #227 already taught the policy layer to read:

  • NAT64 64:ff9b::/96
  • IPv4-translated ::ffff:0:0:0/96

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 http://[64:ff9b::a9fe:a9fe]/, which carries 169.254.169.254, passed the check, and only authored policy stood behind it. The example metadata_addresses forbids did not name the Azure or Alibaba addresses either.

Decisions

  • The fix goes in crates/shell, not crates/box. It's an upstream bug in is_ip_blocked, so it's recorded in UPSTREAM.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 this UPSTREAM.md entry.
  • 64:ff9b:1::/48 (RFC 8215) is refused whole, even when a translator maps it to a public IPv4 address such as 8.8.8.8. It is never globally routed, and its embedding offset is chosen by the network. Only a 64:ff9b::/96 address that carries a public IPv4 address stays allowed.
  • 0.0.0.0/8 is refused because it is reserved and not globally reachable. It is not refused because of how an OS routes it: since Linux 5.3, nonzero 0/8 addresses are ordinary unicast destinations. This vendored copy has no allowed_urls, so the refusal is unconditional in Box. Upstream's allowed_urls arrives with the vendor move.
  • Only the Alibaba address is refused in 100.64.0.0/10. The rest of that shared address space is not a metadata range, and refusing it would break internal services.
  • Example policies and docs/user/security.md gain the two addresses. This keeps them in line with "metadata protection is policy": the gateway still compiles no list.
  • A stale comment in fetch.rs is corrected. It said the gateway has a compiled floor for DNS-resolved destinations; authored policy decides those.

Not covered here

Checks CI cannot perform: no live NAT64 translator and no real metadata service were used.

Background: what the SSRF guard does

The Shell's curl runs 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:

  • read a cloud metadata service and take the instance's credentials
  • reach internal services that are not exposed to the internet
  • reach local services on the machine

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_urls grants them. All IPv4-in-IPv6 encodings would be unwrapped in one helper. Only the metadata endpoints that sit on public addresses, such as 168.63.129.16, would still need to be named. That is a behaviour change: internal services in special ranges would need an allowed_urls entry. 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_addresses fails without the change and passes with it.

  • a_fetch_to_a_translated_or_platform_metadata_literal_is_refused_before_transport fails 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, 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.

Comment thread docs/user/security.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve

The is_ip_blocked change is correct for every case I tested, and its unwrapping matches the policy-layer fold in crates/policy/src/address.rs::embedded_v4. I have one non-blocking docs comment.

Assumptions and rules checked that held
  • NAT64 64:ff9b::/96 and SIIT ::ffff:0:0:0/96 literals are unwrapped and refused when they carry an internal address ([64:ff9b::a9fe:a9fe], [::ffff:0:168.63.129.16], [64:ff9b::100.100.100.200]). A public address inside them stays allowed ([64:ff9b::808:808]).
  • Shortened IPv4 forms from outside the repository are normalized by url before the check and still refused (http://168.63.33040/, http://0x64.0x64.0x64.0xc8/).
  • The new branches leave the 6to4, Teredo, mapped, and compatible handling unchanged. [2002:a83f:8110::] is still refused through the recursive call.
  • [64:ff9b::1:a9fe:a9fe] (inside 64:ff9b::/32 but outside /96 and /48) is allowed. This matches the policy layer, which also reads no ip4 from it.
  • Previously valid input: 0.0.0.0/8 is now refused, while 100.64.0.1 and 100.100.100.201 stay allowed, as the PR describes.
  • In Box, a DNS name that DNS64 resolves to 64:ff9b::a83f:8110 skips the literal floor, but policy reads it as ip4 == "168.63.129.16", so the updated example forbid catches it.
  • Vendored-code rules (root AGENTS.md, "Vendored code"): the upstream bug is recorded in UPSTREAM.md, the modified SECURITY.md has its provenance header, and the floor stays deny-only beneath policy.
  • Every committed example policy that had 169.254.* was updated, and url_safety_tests pass locally (6/6).

Good regression tests: the Monty test checks that the proxy is never contacted, not only that an error comes back.

Comment thread crates/shell/README.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at fa4d421)

The is_ip_blocked logic and its tests are the same as in my earlier review, and url_safety_tests pass again (6/6). The new commit only rewrites the Shell README network line. I left one non-blocking comment on that line, because it promises more NAT64 coverage than the code gives. My earlier docs/user/policy.md suggestion is still open.

Checked and held: the README's metadata and private-range claims match is_ip_blocked for the well-known NAT64, IPv4-translated, mapped, 6to4, and Teredo forms. The SECURITY.md list matches the code exactly.

Comment thread crates/shell/README.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 51930dc)

The code has not changed since my first review: is_ip_blocked and its tests are the same, and url_safety_tests pass (6/6). The last two commits only change docs. I left one non-blocking comment: the Shell README and SECURITY.md now describe more coverage than the code gives, for NAT64 prefixes and for "other" metadata addresses. My earlier docs/user/policy.md suggestion is still open.

Checked and held: the README and SECURITY.md claims for RFC1918, loopback, link-local, 0.0.0.0/8, and the mapped, translated, 64:ff9b::/96, 64:ff9b:1::/48, 6to4, and Teredo forms all match is_ip_blocked.

@priyasingh2111
priyasingh2111 force-pushed the feature/shell-ssrf-nat64-platform-metadata branch from 51930dc to 9d31dee Compare November 10, 2026 23:08
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 9d31dee)

The new commit changes only docs and fixes all three open threads. The code (is_ip_blocked and its tests) is the same as in my first review, and url_safety_tests pass (6/6). I have no new findings.

Checked and held:

  • docs/user/policy.md metadata_addresses now has the same body as docs/user/security.md and the example policies.
  • Each encoding the README and SECURITY.md now name (IPv4-mapped, IPv4-compatible, IPv4-translated, 6to4, Teredo, 64:ff9b::/96, all of 64:ff9b:1::/48) has a matching branch in is_ip_blocked.
  • "Two cloud metadata addresses outside 169.254.0.0/16" matches the two literals in the code.
  • SECURITY.md now states the limit for a NAT64 network with its own prefix, which matches the earlier probe ([2001:db8:64::a9fe:a9fe] → allowed).

Comment thread docs/user/monty.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at c8bdfaf)

is_ip_blocked has not changed; this commit only drops a ticket ID from a test comment, and url_safety_tests pass. The new Box doc lines in monty.md, egress.md, and linux-enforcement.md describe the wider refusal. I left one non-blocking comment because they say every IPv6 encoding is refused, which is the scope the Shell README fix narrowed in the last round.

Checked and held:

@priyasingh2111
priyasingh2111 force-pushed the feature/shell-ssrf-nat64-platform-metadata branch from c8bdfaf to 3df6136 Compare November 11, 2026 01:12
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 3df6136)

This head looks like a rebase of c8bdfaf: same commit message and author date, and the PR diff covers the same 14 files with the same content. After the rebase, url_safety_tests (6/6) and a_fetch_to_a_translated_or_platform_metadata_literal_is_refused_before_transport pass. My non-blocking docs/user/monty.md:168 thread still applies: that line, linux-enforcement.md:228, and egress.md:205-206 still say every IPv6 encoding is refused. I have no new findings.

Checked and held: is_ip_blocked, the Shell README and SECURITY.md scope, and the policy.md metadata_addresses rule all match what I verified at 9d31dee.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 32cf550)

The last two commits change only docs and fix my open monty.md thread. is_ip_blocked has not changed, and url_safety_tests pass (6/6). I have no new findings.

Checked and held:

  • Each encoding named in monty.md:168, linux-enforcement.md:228, and egress.md:45 is refused when it carries a blocked address: mapped, compatible, translated, 6to4, Teredo, 64:ff9b::/96, and all of 64:ff9b:1::/48. I probed each one on this head.
  • The stated own-prefix NAT64 gap matches the code ([2001:db8:64::a9fe:a9fe] is allowed).
  • "One of two cloud metadata addresses outside 169.254.0.0/16" matches the two literals in the code.
  • The Shell README, SECURITY.md, and every metadata_addresses rule (in policy.md, security.md, and the example policies) still match each other.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 8da89f9)

This commit fixes my docs/user/monty.md:168 thread in all three files. is_ip_blocked has not changed. I have no new findings.

Checked and held: each encoding the new lines name refuses the addresses they list. I probed these on this head and each one returned Err: IPv4-compatible [::168.63.129.16] and [::100.100.100.200], 6to4 [2002:6464:64c8::], Teredo carrying 168.63.129.16 and 100.100.100.200, and mapped [::ffff:0.1.2.3]. The own-prefix NAT64 limit stated in monty.md and egress.md matches crates/shell/SECURITY.md. The "wording tidy in the next commit" mentioned in the thread reply is not on this head yet.

@kevin-orellana

Copy link
Copy Markdown
Collaborator

This also blocks some public destinations, so “public IPv4 addresses stay allowed” is too broad. A translator can map an address in 64:ff9b:1::/48 to a public address like 8.8.8.8, but we now block that entire range.

Could we clarify that the allowance applies to 64:ff9b::/96, and explicitly call out the local-use range as an exception?

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.

@priyasingh2111
priyasingh2111 force-pushed the feature/shell-ssrf-nat64-platform-metadata branch from 32cf550 to a575580 Compare November 11, 2026 19:52
@priyasingh2111

Copy link
Copy Markdown
Contributor Author

@kevin-orellana Good catch, thanks for testing it through Shell and Python. The allowance for a public IPv4 address applies only to 64:ff9b::/96. 64:ff9b:1::/48 is blocked whole, even when a translator maps it to a public address such as 8.8.8.8, because the embedding offset in that range is chosen by the network. Fixed in a575580: UPSTREAM.md and the PR description now say that and call out the local-use range as the exception. The same commit also changes the 0.0.0.0/8 comment to the wording from your shell#240 review ("reserved and not globally reachable, so curl refuses it by default; allowed_urls can still permit it"). That comment fix is upstream in strands-agents/shell#244.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at a575580)

This commit answers @kevin-orellana's 64:ff9b:1::/48 point correctly. The only code change is a comment, and url_safety_tests pass (6/6). I left one non-blocking comment: the new 0.0.0.0/8 wording names an allowed_urls override that this vendored copy does not have.

Checked and held:

  • UPSTREAM.md and the PR description now limit the public-IPv4 allowance to 64:ff9b::/96 and refuse all of 64:ff9b:1::/48. This matches is_ip_blocked: [64:ff9b::808:808] is allowed, and the whole local-use prefix is refused.
  • The new reason given for 0.0.0.0/8 ("reserved and not globally reachable", not OS routing) matches the code, which refuses 0/8 with no routing condition.
  • monty.md:168, linux-enforcement.md:228, and egress.md:45 are the same as when I last verified them.

Comment thread crates/shell/src/vfs_kernel.rs Resolved
…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.
@priyasingh2111
priyasingh2111 force-pushed the feature/shell-ssrf-nat64-platform-metadata branch from a575580 to 7a5c604 Compare November 11, 2026 20:08
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 7a5c604)

This commit fixes my allowed_urls thread in the code comment, UPSTREAM.md, and the PR description. Only that comment line in is_ip_blocked changed, and url_safety_tests pass (6/6). I have no new findings and no open threads.

Checked and held: the "unconditional in Box" claim matches check_url_effect and the README's "unconditionally". The 64:ff9b::/96 vs 64:ff9b:1::/48 scope, the three doc lines, and the metadata_addresses rules are unchanged since I last verified them.

@priyasingh2111
priyasingh2111 merged commit f476373 into main Nov 12, 2026
36 of 39 checks passed
@priyasingh2111
priyasingh2111 deleted the feature/shell-ssrf-nat64-platform-metadata branch November 12, 2026 03:21
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.

3 participants