/* * fetch_http.h - URL parse + SSRF policy + HTTP/HTTPS GET with redirects. * * One GET exchange (no keep-alive; Connection: close), up to 5 redirects. * Every hop (and every resolved address of every hop) is checked against the * private/special-purpose denylist BEFORE connect, and the socket is then * connected to that exact validated address, so DNS cannot answer a different * (private) IP between the check and the connect (DNS-rebinding defence). * * TLS on POSIX: vendored mbedTLS over our own sockets, VERIFY_PEER against a * CA bundle (FETCH_TLS_CA_FILE, else the first system bundle found). There is * deliberately NO insecure bypass. On _WIN32 the whole HTTP leg goes through * WinHTTP (system root store). * * Implementation in fetch_http.c (+ fetch_tls.c for the mbedTLS BIO layer). */ #ifndef SX_FETCH_HTTP_H #define SX_FETCH_HTTP_H #include #include "sxbuf.h" /* Hard cap on the response body we are willing to read, like upstream's * MAX_RESPONSE_BYTES. A larger declared body is refused without reading it. */ #define FX_MAX_BODY (5u * 1024u * 1024u) #define FX_MAX_HEAD (64u * 1024u) #define FX_MAX_REDIRECTS 5 #define FX_CONNECT_MS 10000 #define FX_READ_MS 15000 typedef struct { int ok; /* 1 = response delivered */ char error[512]; int status; /* HTTP status of the final response */ char url[1024]; /* final URL after redirects */ char first_url[1024]; /* URL we were first asked for */ char content_type[128]; int hops; /* redirects followed */ char *body; /* heap, NUL-terminated */ size_t body_len; } fx_response; void fx_response_free(fx_response *r); /* Perform GET url (scheme http|https only). Returns 0 on success (response * fields filled) or -1 with r->error set. */ int fx_fetch(const char *url, fx_response *r); /* SSRF: returns 1 when `ip_text` (IPv4 or IPv6 in text form) is a private / * loopback / link-local / special-purpose address that must be refused, * 0 when public. Mirrors the upstream _NON_PUBLIC_NETWORKS list plus its * documented public exceptions. */ int fx_ip_is_denied(const char *ip_text); /* Whether a body with no declared Content-Type opens as an HTML document * (after BOM/whitespace: "