![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
SSRF address guard: is a resolved IP a public, routable unicast address? More...
#include <stdint.h>Go to the source code of this file.
Functions | |
| int | n_ssrf_ipv4_allowed (const uint8_t ip[4]) |
| classify an IPv4 address as safe-to-connect or not | |
| int | n_ssrf_ipv6_allowed (const uint8_t ip[16]) |
| classify an IPv6 address as safe-to-connect or not | |
SSRF address guard: is a resolved IP a public, routable unicast address?
When a program fetches an attacker-supplied URL (link previews, webhooks, avatar imports, ...) the hostname may resolve – or redirect, or DNS-rebind – to a private, loopback or link-local address to reach the local network or a cloud metadata endpoint. The safe pattern is: resolve first, classify EACH resolved address with these predicates, and connect only to an address they accept – never re-resolving the hostname afterwards.
Pure byte classification, no sockets – portable and fully testable. The caller extracts the 4 / 16 address bytes from whatever sockaddr it holds.
Definition in file n_ssrf.h.
| int n_ssrf_ipv4_allowed | ( | const uint8_t | ip[4] | ) |
classify an IPv4 address as safe-to-connect or not
| ip | 4 bytes, network order |
ip is a public routable unicast address; 0 if it is unspecified / private / loopback / CGNAT / link-local / documentation / benchmark / multicast / reserved (RFC 1918, 6598, 5735, 5737, 3927, 2544, ...). NULL is rejected (0). Definition at line 60 of file n_ssrf.c.
References v4_blocked().
Referenced by main().
| int n_ssrf_ipv6_allowed | ( | const uint8_t | ip[16] | ) |
classify an IPv6 address as safe-to-connect or not
| ip | 16 bytes, network order |
ip is a public routable address; 0 otherwise. Rejects unspecified (::), loopback (::1), ULA (fc00::/7), link-local (fe80::/10), multicast (ff00::/8), documentation (2001:db8::/32) and discard (100::/64). IPv4-mapped (::ffff:0:0/96), NAT64 (64:ff9b::/96) and 6to4 (2002::/16) are unwrapped and their embedded IPv4 re-checked, so a private v4 cannot be smuggled in. NULL is rejected (0). Definition at line 101 of file n_ssrf.c.
References v6_blocked().
Referenced by main().