Repository navigation
nstun: block the Azure, Alibaba, and GCE metadata-service addresses - #416
Open
matepad007 wants to merge 1 commit into
Open
matepad007 wants to merge 1 commit into
matepad007 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The SSRF gate in both IP families blocks loopback, link-local, multicast, and broadcast destinations, plus one cloud provider's instance-local service range: AWS's
fd00:ec2::/32(ip6_is_aws_local_service), added in #282. The other three major cloud providers' metadata-service addresses are not covered by any existing check:168.63.129.16, IPv4) — the VM agent's health/goalstate endpoint.100.100.100.200, IPv4) — the ECS instance metadata service, documented athelp.aliyun.com.fd20:ce::254, IPv6) — per Google's own Compute Engine docs. This is a unique-local address (fc00::/7), not a link-local or deprecated site-local address, so it isn't caught byIN6_IS_ADDR_LINKLOCAL/IN6_IS_ADDR_SITELOCALthe wayfe80::/10orfec0::/10addresses are — the same reason AWS'sfd00:ec2::/32needed its own explicit check rather than falling under the generic ULA/site-local tests.None of the three addresses fall into a standard loopback, link-local, or multicast range, so a jailed process able to reach the host's network path for one of these providers could otherwise reach its metadata service unimpeded, the same SSRF/credential-theft shape AWS's IMDS has.
Change
Adds
ip4_is_azure_local_service,ip4_is_alibaba_local_service, andip6_is_gce_local_servicetonstun/net_defs.h, matchingip6_is_aws_local_service's existing style (exact-address/prefix match, no new types). Wires all three into the two SSRF gates innstun/ip.ccalongside the existing checks.Test
Extended
tests/nstun_ip_test.ccwith boundary assertions for each new check, following the exact pattern already used for the AWS case (exact match, off-by-one neighbors, and a same-prefix-different-service negative case for the GCE /128 check).Validation
Unlike the mount-related PRs from this account, this one only touches POSIX networking code with no Linux-only syscalls, so it was fully compiled and run, not just traced:
g++ -std=c++20 -I. tests/nstun_ip_test.cc nstun/ip.cc -o nstun_ip_test && ./nstun_ip_test→ exit 0, all assertions (including the pre-existing ones) pass.net_defs.h/ip.ccreverted and only the test file changes kept, the test fails to even compile (the new functions don't exist) — confirming the new assertions are actually exercising the new code, not passing vacuously.168.63.129.16→0xA83F8110,100.100.100.200→0x646464C8) rather than trusting a transcription.