n_ssrf regression: public addresses pass, private/reserved are blocked, and a private IPv4 smuggled inside IPv6 is still blocked.
n_ssrf regression: public addresses pass, private/reserved are blocked, and a private IPv4 smuggled inside IPv6 is still blocked.
#include <string.h>
#define OK4(a, b, c, d) \
do { \
const uint8_t ip[4] = {a, b, c, d}; \
if (!n_ssrf_ipv4_allowed(ip)) { \
n_log(LOG_ERR, "FAIL: %d.%d.%d.%d should be allowed", a, b, c, \
d); \
failures++; \
} \
} while (0)
#define NO4(a, b, c, d) \
do { \
const uint8_t ip[4] = {a, b, c, d}; \
if (n_ssrf_ipv4_allowed(ip)) { \
n_log(LOG_ERR, "FAIL: %d.%d.%d.%d should be blocked", a, b, c, \
d); \
failures++; \
} \
} while (0)
}
{
uint8_t lo[16] = {0};
uint8_t pub[16] = {0x26, 0x06, 0x47, 0x00};
lo[15] = 1;
}
}
}
{
uint8_t mapped[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff,
127, 0, 0, 1};
uint8_t nat64[16] = {0x00, 0x64, 0xff, 0x9b, 0, 0, 0, 0, 0, 0, 0, 0,
10, 0, 0, 1};
uint8_t sixto4[16] = {0x20, 0x02, 192, 168, 1, 1};
n_log(
LOG_ERR,
"FAIL: a private IPv4 smuggled in IPv6 must block");
}
}
return 1;
}
return 0;
}
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NOTICE
normal but significant condition
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?