fix(network): block requests to private IPs by default (SSRF protection)#1233
Merged
fix(network): block requests to private IPs by default (SSRF protection)#1233
Conversation
81bfa3e to
57ad30e
Compare
Closes #1176 — Adds is_private_ip() check and block_private_ips option (default: true) to NetworkAllowlist. HTTP client pre-resolves DNS and blocks connections to private/reserved IP ranges (127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, ::1, fd00::/8, fe80::/10). Prevents SSRF via DNS rebinding.
57ad30e to
3a197a4
Compare
The is_private_ip function and block_private_ips field were added but not wired into the check() method. Now literal private IPs in URL hostnames are blocked before pattern matching when block_private_ips is enabled (default: true). Closes #1176
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
Closes #1176
is_private_ip()checks all private/reserved ranges: 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, 100.64.0.0/10, ::1, fd00::/8, fe80::/10NetworkAllowlist::block_private_ips(bool)builder method (default: true)tokio::net::lookup_host()and blocks private IPs before connectinghttp://127.0.0.1) are also checkedTest plan
test_is_private_ip_loopback— 127.x and ::1test_is_private_ip_rfc1918— 10.x, 172.16-31.x, 192.168.xtest_is_private_ip_link_local— 169.254.x including AWS metadatatest_is_private_ip_public— 8.8.8.8, 1.1.1.1 not blockedtest_is_private_ip_v6— ::1, fd00::, fe80::test_block_private_ips_default_truetest_block_private_ips_disabled