| index 2968b90..d45af97 100644 | ||
| --- a/docs/SECURITY.md | ||
| +++ b/docs/SECURITY.md | ||
| @@ -50,8 +50,14 @@ token into a transcript. `redact_url: false` is available and documented as the | ||
| 50 | 50 | choice. |
| 51 | 51 | |
| 52 | 52 | **DNS rebinding to a private address.** The check runs on the *numeric* answers of the |
| 53 | -lookup, all of them, not on the hostname; the connection is then made to the validated | |
| 54 | -address, so a second lookup after the check cannot change where the bytes go. | |
| 53 | +lookup, all of them, not on the hostname. On POSIX the connection is then made to that | |
| 54 | +validated numeric address, so a second lookup after the check cannot change where the | |
| 55 | +bytes go. On Windows the request must go to the real hostname instead - WinHTTP takes | |
| 56 | +both SNI and the certificate hostname it verifies from the name given to | |
| 57 | +`WinHttpConnect()`, so connecting by IP would break verification for every ordinary | |
| 58 | +name-based certificate - and the protection there is the all-answers check plus | |
| 59 | +verified TLS, which refuses a certificate issued for a public name when the peer is a | |
| 60 | +private host that cannot present one. | |
| 55 | 61 | |
| 56 | 62 | **Request splitting.** A header value containing CR or LF is refused at save time |
| 57 | 63 | (`value` validation) and again at request time (`wh_http.c` skips framing headers and |
| index 235fa09..b8e579e 100644 | ||
| --- a/plugin.json | ||
| +++ b/plugin.json | ||
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "slug": "webhook", |
| 3 | 3 | "id": "plugin_webhook", |
| 4 | - "version": "1.0.0", | |
| 4 | + "version": "1.0.1", | |
| 5 | 5 | "name": "webhook", |
| 6 | 6 | "desc": "HTTP triggers", |
| 7 | 7 | "title": "Named Webhooks & REST Triggers (MCP)", |
| index aec298c..c07d28b 100644 | ||
| --- a/src/plugin_webhook.c | ||
| +++ b/src/plugin_webhook.c | ||
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | #define PLUGIN_ID "plugin_webhook" |
| 76 | 76 | #define PLUGIN_NAME "webhook" |
| 77 | 77 | #define PLUGIN_DESC "HTTP triggers" |
| 78 | -#define PLUGIN_VER "1.0.0" | |
| 78 | +#define PLUGIN_VER "1.0.1" | |
| 79 | 79 | #define PLUGIN_KIND "mcp" |
| 80 | 80 | |
| 81 | 81 | /* ===================================================================== |
| index 511b14d..41abeff 100644 | ||
| --- a/src/wh_http.c | ||
| +++ b/src/wh_http.c | ||
| @@ -905,10 +905,7 @@ static int exchange_winhttp(const wh_url *u, const char *method, | ||
| 905 | 905 | if (!sess) { snprintf(r->error, sizeof r->error, "WinHttpOpen failed"); return -1; } |
| 906 | 906 | WinHttpSetTimeouts(sess, WH_CONNECT_MS, WH_CONNECT_MS, WH_READ_MS, WH_READ_MS); |
| 907 | 907 | |
| 908 | - /* Connect to the validated numeric address; the real name travels in the | |
| 909 | - * Host header and in SNI (WinHTTP derives SNI from the added Host value | |
| 910 | - * only when connecting by name, so we also pass it explicitly below). */ | |
| 911 | - a2w(tgt.text, wtarget, 128); | |
| 908 | + a2w(u->host, wtarget, 128); | |
| 912 | 909 | a2w(u->path[0] ? u->path : "/", wpath, WH_URL_MAX + 8); |
| 913 | 910 | a2w(method, wmethod, 16); |
| 914 | 911 | |
| @@ -934,13 +931,15 @@ static int exchange_winhttp(const wh_url *u, const char *method, | ||
| 934 | 931 | DWORD pol = WINHTTP_OPTION_REDIRECT_POLICY_NEVER; |
| 935 | 932 | WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol); |
| 936 | 933 | } |
| 937 | - { | |
| 938 | - /* SNI + certificate hostname must be the real name, not the IP. */ | |
| 939 | - wchar_t whost[300]; | |
| 940 | - a2w(u->host, whost, 300); | |
| 941 | - WinHttpSetOption(req, WINHTTP_OPTION_TLS_SERVER_NAME, | |
| 942 | - whost, (DWORD)(wcslen(whost) * sizeof(wchar_t))); | |
| 943 | - } | |
| 934 | + /* On Windows the request goes to the real hostname, not to the numeric | |
| 935 | + * address: WinHTTP takes both SNI and the certificate hostname it verifies | |
| 936 | + * from the name given to WinHttpConnect(), so connecting by IP would break | |
| 937 | + * verification for every ordinary name-based certificate. The SSRF policy | |
| 938 | + * is still applied first, on every address the name resolves to, so a host | |
| 939 | + * that answers with a private record is refused before any connection is | |
| 940 | + * attempted. (POSIX has no such constraint and connects to the validated | |
| 941 | + * numeric address, which removes the rebinding window entirely; see the | |
| 942 | + * note in docs/SECURITY.md.) */ | |
| 944 | 943 | |
| 945 | 944 | host_has_port = !((u->tls && u->port == 443) || (!u->tls && u->port == 80)); |
| 946 | 945 | { |
| index 626e24d..ca61399 100644 | ||
| --- a/src/wh_http.h | ||
| +++ b/src/wh_http.h | ||
| @@ -15,8 +15,13 @@ | ||
| 15 | 15 | * |
| 16 | 16 | * 2. Verified TLS. POSIX wraps the validated socket in mbedTLS (TLS 1.2+, |
| 17 | 17 | * VERIFY_PEER, hostname check, system or WEBHOOK_TLS_CA_FILE anchors) with |
| 18 | - * no insecure bypass. _WIN32 uses WinHTTP against the validated numeric | |
| 19 | - * address with the real Host header and the system root store. | |
| 18 | + * no insecure bypass. _WIN32 uses WinHTTP with the system root store; it | |
| 19 | + * connects by NAME rather than by the validated numeric address because | |
| 20 | + * WinHTTP derives both SNI and the certificate hostname it verifies from | |
| 21 | + * the name given to WinHttpConnect(), so an IP connection would refuse | |
| 22 | + * every ordinary name-based certificate. The all-answers SSRF check still | |
| 23 | + * runs first, and verified TLS refuses a public name whose peer cannot | |
| 24 | + * present a certificate for it. | |
| 20 | 25 | * |
| 21 | 26 | * Redirects are NOT followed: a hook's URL is part of its definition, so a |
| 22 | 27 | * 30x is reported as a status instead of silently becoming a request to |
| index 0ac9149..6c5e49a 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -111,7 +111,7 @@ json_ok "--meta mcp true" "$meta" 'd["mcp"] is True' | ||
| 111 | 111 | json_ok "--meta daemon false" "$meta" 'd["daemon"] is False' |
| 112 | 112 | json_ok "--meta menus false" "$meta" 'd["menus"] is False' |
| 113 | 113 | json_ok "--meta verified live" "$meta" 'd["verified"]=="live"' |
| 114 | -json_ok "--meta version 1.0.0" "$meta" 'd["version"]=="1.0.0"' | |
| 114 | +json_ok "--meta version matches plugin.json" "$meta" 'd["version"]=="1.0.1"' | |
| 115 | 115 | check "--meta is a single line" "1" "$($BIN --meta | wc -l | tr -d ' ')" |
| 116 | 116 | |
| 117 | 117 | schema=$($BIN --schema) |
| 118 | 118 |
| index 2968b90..d45af97 100644 | index 2968b90..d45af97 100644 | ||
| --- a/docs/SECURITY.md | --- a/docs/SECURITY.md | ||
| +++ b/docs/SECURITY.md | +++ b/docs/SECURITY.md | ||
| @@ -50,8 +50,14 @@ token into a transcript. `redact_url: false` is available and documented as the | @@ -50,8 +50,14 @@ token into a transcript. `redact_url: false` is available and documented as the | ||
| 50 | choice. | 50 | choice. |
| 51 | 51 | ||
| 52 | **DNS rebinding to a private address.** The check runs on the *numeric* answers of the | 52 | **DNS rebinding to a private address.** The check runs on the *numeric* answers of the |
| 53 | -lookup, all of them, not on the hostname; the connection is then made to the validated | 53 | +lookup, all of them, not on the hostname. On POSIX the connection is then made to that |
| 54 | -address, so a second lookup after the check cannot change where the bytes go. | 54 | +validated numeric address, so a second lookup after the check cannot change where the |
| 55 | +bytes go. On Windows the request must go to the real hostname instead - WinHTTP takes | ||
| 56 | +both SNI and the certificate hostname it verifies from the name given to | ||
| 57 | +`WinHttpConnect()`, so connecting by IP would break verification for every ordinary | ||
| 58 | +name-based certificate - and the protection there is the all-answers check plus | ||
| 59 | +verified TLS, which refuses a certificate issued for a public name when the peer is a | ||
| 60 | +private host that cannot present one. | ||
| 55 | 61 | ||
| 56 | **Request splitting.** A header value containing CR or LF is refused at save time | 62 | **Request splitting.** A header value containing CR or LF is refused at save time |
| 57 | (`value` validation) and again at request time (`wh_http.c` skips framing headers and | 63 | (`value` validation) and again at request time (`wh_http.c` skips framing headers and |
| index 235fa09..b8e579e 100644 | index 235fa09..b8e579e 100644 | ||
| --- a/plugin.json | --- a/plugin.json | ||
| +++ b/plugin.json | +++ b/plugin.json | ||
| @@ -1,7 +1,7 @@ | @@ -1,7 +1,7 @@ | ||
| 1 | { | 1 | { |
| 2 | "slug": "webhook", | 2 | "slug": "webhook", |
| 3 | "id": "plugin_webhook", | 3 | "id": "plugin_webhook", |
| 4 | - "version": "1.0.0", | 4 | + "version": "1.0.1", |
| 5 | "name": "webhook", | 5 | "name": "webhook", |
| 6 | "desc": "HTTP triggers", | 6 | "desc": "HTTP triggers", |
| 7 | "title": "Named Webhooks & REST Triggers (MCP)", | 7 | "title": "Named Webhooks & REST Triggers (MCP)", |
| index aec298c..c07d28b 100644 | index aec298c..c07d28b 100644 | ||
| --- a/src/plugin_webhook.c | --- a/src/plugin_webhook.c | ||
| +++ b/src/plugin_webhook.c | +++ b/src/plugin_webhook.c | ||
| @@ -75,7 +75,7 @@ | @@ -75,7 +75,7 @@ | ||
| 75 | #define PLUGIN_ID "plugin_webhook" | 75 | #define PLUGIN_ID "plugin_webhook" |
| 76 | #define PLUGIN_NAME "webhook" | 76 | #define PLUGIN_NAME "webhook" |
| 77 | #define PLUGIN_DESC "HTTP triggers" | 77 | #define PLUGIN_DESC "HTTP triggers" |
| 78 | -#define PLUGIN_VER "1.0.0" | 78 | +#define PLUGIN_VER "1.0.1" |
| 79 | #define PLUGIN_KIND "mcp" | 79 | #define PLUGIN_KIND "mcp" |
| 80 | 80 | ||
| 81 | /* ===================================================================== | 81 | /* ===================================================================== |
| index 511b14d..41abeff 100644 | index 511b14d..41abeff 100644 | ||
| --- a/src/wh_http.c | --- a/src/wh_http.c | ||
| +++ b/src/wh_http.c | +++ b/src/wh_http.c | ||
| @@ -905,10 +905,7 @@ static int exchange_winhttp(const wh_url *u, const char *method, | @@ -905,10 +905,7 @@ static int exchange_winhttp(const wh_url *u, const char *method, | ||
| 905 | if (!sess) { snprintf(r->error, sizeof r->error, "WinHttpOpen failed"); return -1; } | 905 | if (!sess) { snprintf(r->error, sizeof r->error, "WinHttpOpen failed"); return -1; } |
| 906 | WinHttpSetTimeouts(sess, WH_CONNECT_MS, WH_CONNECT_MS, WH_READ_MS, WH_READ_MS); | 906 | WinHttpSetTimeouts(sess, WH_CONNECT_MS, WH_CONNECT_MS, WH_READ_MS, WH_READ_MS); |
| 907 | 907 | ||
| 908 | - /* Connect to the validated numeric address; the real name travels in the | 908 | + a2w(u->host, wtarget, 128); |
| 909 | - * Host header and in SNI (WinHTTP derives SNI from the added Host value | ||
| 910 | - * only when connecting by name, so we also pass it explicitly below). */ | ||
| 911 | - a2w(tgt.text, wtarget, 128); | ||
| 912 | a2w(u->path[0] ? u->path : "/", wpath, WH_URL_MAX + 8); | 909 | a2w(u->path[0] ? u->path : "/", wpath, WH_URL_MAX + 8); |
| 913 | a2w(method, wmethod, 16); | 910 | a2w(method, wmethod, 16); |
| 914 | 911 | ||
| @@ -934,13 +931,15 @@ static int exchange_winhttp(const wh_url *u, const char *method, | @@ -934,13 +931,15 @@ static int exchange_winhttp(const wh_url *u, const char *method, | ||
| 934 | DWORD pol = WINHTTP_OPTION_REDIRECT_POLICY_NEVER; | 931 | DWORD pol = WINHTTP_OPTION_REDIRECT_POLICY_NEVER; |
| 935 | WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol); | 932 | WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol); |
| 936 | } | 933 | } |
| 937 | - { | 934 | + /* On Windows the request goes to the real hostname, not to the numeric |
| 938 | - /* SNI + certificate hostname must be the real name, not the IP. */ | 935 | + * address: WinHTTP takes both SNI and the certificate hostname it verifies |
| 939 | - wchar_t whost[300]; | 936 | + * from the name given to WinHttpConnect(), so connecting by IP would break |
| 940 | - a2w(u->host, whost, 300); | 937 | + * verification for every ordinary name-based certificate. The SSRF policy |
| 941 | - WinHttpSetOption(req, WINHTTP_OPTION_TLS_SERVER_NAME, | 938 | + * is still applied first, on every address the name resolves to, so a host |
| 942 | - whost, (DWORD)(wcslen(whost) * sizeof(wchar_t))); | 939 | + * that answers with a private record is refused before any connection is |
| 943 | - } | 940 | + * attempted. (POSIX has no such constraint and connects to the validated |
| 941 | + * numeric address, which removes the rebinding window entirely; see the | ||
| 942 | + * note in docs/SECURITY.md.) */ | ||
| 944 | 943 | ||
| 945 | host_has_port = !((u->tls && u->port == 443) || (!u->tls && u->port == 80)); | 944 | host_has_port = !((u->tls && u->port == 443) || (!u->tls && u->port == 80)); |
| 946 | { | 945 | { |
| index 626e24d..ca61399 100644 | index 626e24d..ca61399 100644 | ||
| --- a/src/wh_http.h | --- a/src/wh_http.h | ||
| +++ b/src/wh_http.h | +++ b/src/wh_http.h | ||
| @@ -15,8 +15,13 @@ | @@ -15,8 +15,13 @@ | ||
| 15 | * | 15 | * |
| 16 | * 2. Verified TLS. POSIX wraps the validated socket in mbedTLS (TLS 1.2+, | 16 | * 2. Verified TLS. POSIX wraps the validated socket in mbedTLS (TLS 1.2+, |
| 17 | * VERIFY_PEER, hostname check, system or WEBHOOK_TLS_CA_FILE anchors) with | 17 | * VERIFY_PEER, hostname check, system or WEBHOOK_TLS_CA_FILE anchors) with |
| 18 | - * no insecure bypass. _WIN32 uses WinHTTP against the validated numeric | 18 | + * no insecure bypass. _WIN32 uses WinHTTP with the system root store; it |
| 19 | - * address with the real Host header and the system root store. | 19 | + * connects by NAME rather than by the validated numeric address because |
| 20 | + * WinHTTP derives both SNI and the certificate hostname it verifies from | ||
| 21 | + * the name given to WinHttpConnect(), so an IP connection would refuse | ||
| 22 | + * every ordinary name-based certificate. The all-answers SSRF check still | ||
| 23 | + * runs first, and verified TLS refuses a public name whose peer cannot | ||
| 24 | + * present a certificate for it. | ||
| 20 | * | 25 | * |
| 21 | * Redirects are NOT followed: a hook's URL is part of its definition, so a | 26 | * Redirects are NOT followed: a hook's URL is part of its definition, so a |
| 22 | * 30x is reported as a status instead of silently becoming a request to | 27 | * 30x is reported as a status instead of silently becoming a request to |
| index 0ac9149..6c5e49a 100755 | index 0ac9149..6c5e49a 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -111,7 +111,7 @@ json_ok "--meta mcp true" "$meta" 'd["mcp"] is True' | @@ -111,7 +111,7 @@ json_ok "--meta mcp true" "$meta" 'd["mcp"] is True' | ||
| 111 | json_ok "--meta daemon false" "$meta" 'd["daemon"] is False' | 111 | json_ok "--meta daemon false" "$meta" 'd["daemon"] is False' |
| 112 | json_ok "--meta menus false" "$meta" 'd["menus"] is False' | 112 | json_ok "--meta menus false" "$meta" 'd["menus"] is False' |
| 113 | json_ok "--meta verified live" "$meta" 'd["verified"]=="live"' | 113 | json_ok "--meta verified live" "$meta" 'd["verified"]=="live"' |
| 114 | -json_ok "--meta version 1.0.0" "$meta" 'd["version"]=="1.0.0"' | 114 | +json_ok "--meta version matches plugin.json" "$meta" 'd["version"]=="1.0.1"' |
| 115 | check "--meta is a single line" "1" "$($BIN --meta | wc -l | tr -d ' ')" | 115 | check "--meta is a single line" "1" "$($BIN --meta | wc -l | tr -d ' ')" |
| 116 | 116 | ||
| 117 | schema=$($BIN --schema) | 117 | schema=$($BIN --schema) |
| 118 | 118 |