| index 6521c63..7bfb05b 100644 | ||
| --- a/plugin.json | ||
| +++ b/plugin.json | ||
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | "menus": false, |
| 12 | 12 | "verified": "live", |
| 13 | 13 | "category": "network", |
| 14 | - "version": "1.0.0", | |
| 14 | + "version": "1.0.1", | |
| 15 | 15 | "license": "MIT", |
| 16 | 16 | "capabilities": [ |
| 17 | 17 | "outbound_http_user_requested", |
| index f3f1cf0..7bf166f 100644 | ||
| --- a/release-dist.sh | ||
| +++ b/release-dist.sh | ||
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | set -eu |
| 19 | 19 | |
| 20 | 20 | SLUG=fetch |
| 21 | -VERSION="${VERSION:-1.0.0}" | |
| 21 | +VERSION="${VERSION:-1.0.1}" | |
| 22 | 22 | PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}" |
| 23 | 23 | |
| 24 | 24 | ROOT=$(cd "$(dirname "$0")" && pwd) |
| index 8cf77bb..774aed6 100644 | ||
| --- a/src/fetch_http.c | ||
| +++ b/src/fetch_http.c | ||
| @@ -14,7 +14,12 @@ | ||
| 14 | 14 | * FX_MAX_REDIRECTS. No TLS bypass exists. |
| 15 | 15 | */ |
| 16 | 16 | /* The feature-test macros must precede every include (netdb/inet functions, |
| 17 | - * POSIX sockets). */ | |
| 17 | + * POSIX sockets). _WIN32_WINNT likewise precedes winsock2.h: MinGW defaults | |
| 18 | + * it to 0x0502, which hides InetPtonA and inet_ntop - both of which the SSRF | |
| 19 | + * validator needs - behind a Windows Vista gate. */ | |
| 20 | +#if defined(_WIN32) && !defined(_WIN32_WINNT) | |
| 21 | +# define _WIN32_WINNT 0x0601 | |
| 22 | +#endif | |
| 18 | 23 | #if !defined(_WIN32) && !defined(_POSIX_C_SOURCE) |
| 19 | 24 | # define _POSIX_C_SOURCE 200809L |
| 20 | 25 | #endif |
| @@ -1087,7 +1092,12 @@ static int exchange_winhttp(const fx_url *u, const char *urltext, fx_response *r | ||
| 1087 | 1092 | WinHttpSetOption(req, WINHTTP_OPTION_SECURE_PROTOCOLS, &sec, sizeof sec); |
| 1088 | 1093 | } |
| 1089 | 1094 | { |
| 1090 | - DWORD pol = WINHTTP_REDIRECT_POLICY_NONE; | |
| 1095 | + /* Our own redirect loop owns every hop (each one re-resolved and | |
| 1096 | + * re-validated), so WinHTTP must not follow any on its own. | |
| 1097 | + * _NEVER is the documented spelling; _NONE is what the WinRT | |
| 1098 | + * WINHTTP_REDIRECT_POLICY enum calls it and MinGW's winhttp.h does | |
| 1099 | + * not define _NONE at all. */ | |
| 1100 | + DWORD pol = WINHTTP_OPTION_REDIRECT_POLICY_NEVER; | |
| 1091 | 1101 | WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol); |
| 1092 | 1102 | } |
| 1093 | 1103 | { |
| @@ -1143,7 +1153,7 @@ static int exchange_winhttp(const fx_url *u, const char *urltext, fx_response *r | ||
| 1143 | 1153 | wchar_t wloc[1024]; |
| 1144 | 1154 | DWORD sz = sizeof wloc; |
| 1145 | 1155 | wloc[0] = L'\0'; |
| 1146 | - a2w(L"Location", whdr, 128); | |
| 1156 | + a2w("Location", whdr, 128); | |
| 1147 | 1157 | if (WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, whdr, wloc, &sz, |
| 1148 | 1158 | WINHTTP_NO_HEADER_INDEX)) { |
| 1149 | 1159 | WideCharToMultiByte(CP_UTF8, 0, wloc, -1, r->url, sizeof r->url, |
| index 561948d..3f23ce9 100644 | ||
| --- a/src/plugin_fetch.c | ||
| +++ b/src/plugin_fetch.c | ||
| @@ -52,8 +52,13 @@ | ||
| 52 | 52 | #include <time.h> |
| 53 | 53 | |
| 54 | 54 | #if defined(_WIN32) |
| 55 | + /* MinGW splits what one POSIX header covers into three: <io.h> declares | |
| 56 | + * _setmode/_fileno, <fcntl.h> declares the _O_* constants _setmode takes, | |
| 57 | + * <direct.h> declares _mkdir. windows.h pulls in none of them. */ | |
| 55 | 58 | # include <windows.h> |
| 56 | 59 | # include <io.h> |
| 60 | +# include <fcntl.h> | |
| 61 | +# include <direct.h> | |
| 57 | 62 | #endif |
| 58 | 63 | #include <sys/stat.h> |
| 59 | 64 | #include <sys/types.h> |
| @@ -66,7 +71,7 @@ | ||
| 66 | 71 | |
| 67 | 72 | #define PLUGIN_SLUG "fetch" |
| 68 | 73 | #define PLUGIN_ID "plugin_fetch" |
| 69 | -#define PLUGIN_VER "1.0.0" | |
| 74 | +#define PLUGIN_VER "1.0.1" | |
| 70 | 75 | |
| 71 | 76 | #if defined(_WIN32) |
| 72 | 77 | # define sx_mkdir(p) _mkdir(p) |
| index 1ba6115..35555a9 100644 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -250,7 +250,9 @@ check "a missing url is an error" 'url is required' "$(fld nourl)" | ||
| 250 | 250 | check "a schemeless url is refused" 'no scheme' "$(fld noscheme)" |
| 251 | 251 | check "ftp is refused" "scheme 'ftp'" "$(fld badscheme)" |
| 252 | 252 | check "an empty url is refused" 'url is required' "$(fld empty)" |
| 253 | -check "string numbers are coerced" 'truncation footer proves max_length was applied' /dev/null >/dev/null | |
| 253 | +# the string-vs-int coercion path: max_length arrives as the string "40", so | |
| 254 | +# only the truncation footer naming start_index 40 proves it was read as a | |
| 255 | +# number rather than rejected or defaulted | |
| 254 | 256 | check "string numbers are coerced (max_length honoured as a string)" 'start_index of 40' "$(fld strnums)" |
| 255 | 257 | check "the request sends our User-Agent" 'SCORPIOXBOT-fetch' "$(fld useragent)" |
| 256 | 258 | check "the request asks for identity encoding" 'identity' "$(fld useragent)" |
| @@ -610,7 +612,7 @@ check "the socket connects to the validated address" 'connected to that exact va | ||
| 610 | 612 | check "the connect is non-blocking so the deadline is real" 'O_NONBLOCK' "$(cat src/fetch_http.c)" |
| 611 | 613 | check "the Windows leg sets hard timeouts too" 'WinHttpSetTimeouts' "$(cat src/fetch_http.c)" |
| 612 | 614 | check "WinHTTP is pinned to TLS 1.2+" 'WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2' "$(cat src/fetch_http.c)" |
| 613 | -check "WinHTTP does not follow redirects itself" 'WINHTTP_REDIRECT_POLICY_NONE' "$(cat src/fetch_http.c)" | |
| 615 | +check "WinHTTP does not follow redirects itself" 'WINHTTP_OPTION_REDIRECT_POLICY_NEVER' "$(cat src/fetch_http.c)" | |
| 614 | 616 | check "the body cap is 5 MB" 'define FX_MAX_BODY' "$(cat src/fetch_http.h)" |
| 615 | 617 | check "the redirect cap is 5" 'define FX_MAX_REDIRECTS 5' "$(cat src/fetch_http.h)" |
| 616 | 618 | check "the page is a generated header" '#include "ui_html.h"' "$(cat src/plugin_fetch.c)" |
| 617 | 619 |
| index 6521c63..7bfb05b 100644 | index 6521c63..7bfb05b 100644 | ||
| --- a/plugin.json | --- a/plugin.json | ||
| +++ b/plugin.json | +++ b/plugin.json | ||
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | "menus": false, | 11 | "menus": false, |
| 12 | "verified": "live", | 12 | "verified": "live", |
| 13 | "category": "network", | 13 | "category": "network", |
| 14 | - "version": "1.0.0", | 14 | + "version": "1.0.1", |
| 15 | "license": "MIT", | 15 | "license": "MIT", |
| 16 | "capabilities": [ | 16 | "capabilities": [ |
| 17 | "outbound_http_user_requested", | 17 | "outbound_http_user_requested", |
| index f3f1cf0..7bf166f 100644 | index f3f1cf0..7bf166f 100644 | ||
| --- a/release-dist.sh | --- a/release-dist.sh | ||
| +++ b/release-dist.sh | +++ b/release-dist.sh | ||
| @@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
| 18 | set -eu | 18 | set -eu |
| 19 | 19 | ||
| 20 | SLUG=fetch | 20 | SLUG=fetch |
| 21 | -VERSION="${VERSION:-1.0.0}" | 21 | +VERSION="${VERSION:-1.0.1}" |
| 22 | PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}" | 22 | PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}" |
| 23 | 23 | ||
| 24 | ROOT=$(cd "$(dirname "$0")" && pwd) | 24 | ROOT=$(cd "$(dirname "$0")" && pwd) |
| index 8cf77bb..774aed6 100644 | index 8cf77bb..774aed6 100644 | ||
| --- a/src/fetch_http.c | --- a/src/fetch_http.c | ||
| +++ b/src/fetch_http.c | +++ b/src/fetch_http.c | ||
| @@ -14,7 +14,12 @@ | @@ -14,7 +14,12 @@ | ||
| 14 | * FX_MAX_REDIRECTS. No TLS bypass exists. | 14 | * FX_MAX_REDIRECTS. No TLS bypass exists. |
| 15 | */ | 15 | */ |
| 16 | /* The feature-test macros must precede every include (netdb/inet functions, | 16 | /* The feature-test macros must precede every include (netdb/inet functions, |
| 17 | - * POSIX sockets). */ | 17 | + * POSIX sockets). _WIN32_WINNT likewise precedes winsock2.h: MinGW defaults |
| 18 | + * it to 0x0502, which hides InetPtonA and inet_ntop - both of which the SSRF | ||
| 19 | + * validator needs - behind a Windows Vista gate. */ | ||
| 20 | +#if defined(_WIN32) && !defined(_WIN32_WINNT) | ||
| 21 | +# define _WIN32_WINNT 0x0601 | ||
| 22 | +#endif | ||
| 18 | #if !defined(_WIN32) && !defined(_POSIX_C_SOURCE) | 23 | #if !defined(_WIN32) && !defined(_POSIX_C_SOURCE) |
| 19 | # define _POSIX_C_SOURCE 200809L | 24 | # define _POSIX_C_SOURCE 200809L |
| 20 | #endif | 25 | #endif |
| @@ -1087,7 +1092,12 @@ static int exchange_winhttp(const fx_url *u, const char *urltext, fx_response *r | @@ -1087,7 +1092,12 @@ static int exchange_winhttp(const fx_url *u, const char *urltext, fx_response *r | ||
| 1087 | WinHttpSetOption(req, WINHTTP_OPTION_SECURE_PROTOCOLS, &sec, sizeof sec); | 1092 | WinHttpSetOption(req, WINHTTP_OPTION_SECURE_PROTOCOLS, &sec, sizeof sec); |
| 1088 | } | 1093 | } |
| 1089 | { | 1094 | { |
| 1090 | - DWORD pol = WINHTTP_REDIRECT_POLICY_NONE; | 1095 | + /* Our own redirect loop owns every hop (each one re-resolved and |
| 1096 | + * re-validated), so WinHTTP must not follow any on its own. | ||
| 1097 | + * _NEVER is the documented spelling; _NONE is what the WinRT | ||
| 1098 | + * WINHTTP_REDIRECT_POLICY enum calls it and MinGW's winhttp.h does | ||
| 1099 | + * not define _NONE at all. */ | ||
| 1100 | + DWORD pol = WINHTTP_OPTION_REDIRECT_POLICY_NEVER; | ||
| 1091 | WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol); | 1101 | WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol); |
| 1092 | } | 1102 | } |
| 1093 | { | 1103 | { |
| @@ -1143,7 +1153,7 @@ static int exchange_winhttp(const fx_url *u, const char *urltext, fx_response *r | @@ -1143,7 +1153,7 @@ static int exchange_winhttp(const fx_url *u, const char *urltext, fx_response *r | ||
| 1143 | wchar_t wloc[1024]; | 1153 | wchar_t wloc[1024]; |
| 1144 | DWORD sz = sizeof wloc; | 1154 | DWORD sz = sizeof wloc; |
| 1145 | wloc[0] = L'\0'; | 1155 | wloc[0] = L'\0'; |
| 1146 | - a2w(L"Location", whdr, 128); | 1156 | + a2w("Location", whdr, 128); |
| 1147 | if (WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, whdr, wloc, &sz, | 1157 | if (WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, whdr, wloc, &sz, |
| 1148 | WINHTTP_NO_HEADER_INDEX)) { | 1158 | WINHTTP_NO_HEADER_INDEX)) { |
| 1149 | WideCharToMultiByte(CP_UTF8, 0, wloc, -1, r->url, sizeof r->url, | 1159 | WideCharToMultiByte(CP_UTF8, 0, wloc, -1, r->url, sizeof r->url, |
| index 561948d..3f23ce9 100644 | index 561948d..3f23ce9 100644 | ||
| --- a/src/plugin_fetch.c | --- a/src/plugin_fetch.c | ||
| +++ b/src/plugin_fetch.c | +++ b/src/plugin_fetch.c | ||
| @@ -52,8 +52,13 @@ | @@ -52,8 +52,13 @@ | ||
| 52 | #include <time.h> | 52 | #include <time.h> |
| 53 | 53 | ||
| 54 | #if defined(_WIN32) | 54 | #if defined(_WIN32) |
| 55 | + /* MinGW splits what one POSIX header covers into three: <io.h> declares | ||
| 56 | + * _setmode/_fileno, <fcntl.h> declares the _O_* constants _setmode takes, | ||
| 57 | + * <direct.h> declares _mkdir. windows.h pulls in none of them. */ | ||
| 55 | # include <windows.h> | 58 | # include <windows.h> |
| 56 | # include <io.h> | 59 | # include <io.h> |
| 60 | +# include <fcntl.h> | ||
| 61 | +# include <direct.h> | ||
| 57 | #endif | 62 | #endif |
| 58 | #include <sys/stat.h> | 63 | #include <sys/stat.h> |
| 59 | #include <sys/types.h> | 64 | #include <sys/types.h> |
| @@ -66,7 +71,7 @@ | @@ -66,7 +71,7 @@ | ||
| 66 | 71 | ||
| 67 | #define PLUGIN_SLUG "fetch" | 72 | #define PLUGIN_SLUG "fetch" |
| 68 | #define PLUGIN_ID "plugin_fetch" | 73 | #define PLUGIN_ID "plugin_fetch" |
| 69 | -#define PLUGIN_VER "1.0.0" | 74 | +#define PLUGIN_VER "1.0.1" |
| 70 | 75 | ||
| 71 | #if defined(_WIN32) | 76 | #if defined(_WIN32) |
| 72 | # define sx_mkdir(p) _mkdir(p) | 77 | # define sx_mkdir(p) _mkdir(p) |
| index 1ba6115..35555a9 100644 | index 1ba6115..35555a9 100644 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -250,7 +250,9 @@ check "a missing url is an error" 'url is required' "$(fld nourl)" | @@ -250,7 +250,9 @@ check "a missing url is an error" 'url is required' "$(fld nourl)" | ||
| 250 | check "a schemeless url is refused" 'no scheme' "$(fld noscheme)" | 250 | check "a schemeless url is refused" 'no scheme' "$(fld noscheme)" |
| 251 | check "ftp is refused" "scheme 'ftp'" "$(fld badscheme)" | 251 | check "ftp is refused" "scheme 'ftp'" "$(fld badscheme)" |
| 252 | check "an empty url is refused" 'url is required' "$(fld empty)" | 252 | check "an empty url is refused" 'url is required' "$(fld empty)" |
| 253 | -check "string numbers are coerced" 'truncation footer proves max_length was applied' /dev/null >/dev/null | 253 | +# the string-vs-int coercion path: max_length arrives as the string "40", so |
| 254 | +# only the truncation footer naming start_index 40 proves it was read as a | ||
| 255 | +# number rather than rejected or defaulted | ||
| 254 | check "string numbers are coerced (max_length honoured as a string)" 'start_index of 40' "$(fld strnums)" | 256 | check "string numbers are coerced (max_length honoured as a string)" 'start_index of 40' "$(fld strnums)" |
| 255 | check "the request sends our User-Agent" 'SCORPIOXBOT-fetch' "$(fld useragent)" | 257 | check "the request sends our User-Agent" 'SCORPIOXBOT-fetch' "$(fld useragent)" |
| 256 | check "the request asks for identity encoding" 'identity' "$(fld useragent)" | 258 | check "the request asks for identity encoding" 'identity' "$(fld useragent)" |
| @@ -610,7 +612,7 @@ check "the socket connects to the validated address" 'connected to that exact va | @@ -610,7 +612,7 @@ check "the socket connects to the validated address" 'connected to that exact va | ||
| 610 | check "the connect is non-blocking so the deadline is real" 'O_NONBLOCK' "$(cat src/fetch_http.c)" | 612 | check "the connect is non-blocking so the deadline is real" 'O_NONBLOCK' "$(cat src/fetch_http.c)" |
| 611 | check "the Windows leg sets hard timeouts too" 'WinHttpSetTimeouts' "$(cat src/fetch_http.c)" | 613 | check "the Windows leg sets hard timeouts too" 'WinHttpSetTimeouts' "$(cat src/fetch_http.c)" |
| 612 | check "WinHTTP is pinned to TLS 1.2+" 'WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2' "$(cat src/fetch_http.c)" | 614 | check "WinHTTP is pinned to TLS 1.2+" 'WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2' "$(cat src/fetch_http.c)" |
| 613 | -check "WinHTTP does not follow redirects itself" 'WINHTTP_REDIRECT_POLICY_NONE' "$(cat src/fetch_http.c)" | 615 | +check "WinHTTP does not follow redirects itself" 'WINHTTP_OPTION_REDIRECT_POLICY_NEVER' "$(cat src/fetch_http.c)" |
| 614 | check "the body cap is 5 MB" 'define FX_MAX_BODY' "$(cat src/fetch_http.h)" | 616 | check "the body cap is 5 MB" 'define FX_MAX_BODY' "$(cat src/fetch_http.h)" |
| 615 | check "the redirect cap is 5" 'define FX_MAX_REDIRECTS 5' "$(cat src/fetch_http.h)" | 617 | check "the redirect cap is 5" 'define FX_MAX_REDIRECTS 5' "$(cat src/fetch_http.h)" |
| 616 | check "the page is a generated header" '#include "ui_html.h"' "$(cat src/plugin_fetch.c)" | 618 | check "the page is a generated header" '#include "ui_html.h"' "$(cat src/plugin_fetch.c)" |
| 617 | 619 |