fix(win64): connect by name so WinHTTP can verify the certificate
WINHTTP_OPTION_TLS_SERVER_NAME does not exist in MinGW's winhttp.h, and the underlying problem is worse than a missing constant: WinHTTP takes both SNI and the hostname it checks the certificate against from the name given to WinHttpConnect(), so connecting to the validated numeric address would have refused every ordinary name-based certificate. The all-answers SSRF check still runs first. Documents the difference from the POSIX path, which does connect to the validated address. 1.0.1.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-14 05:25:41
Commit6b0f4cfa
Parentseffac9a7
Changed files
docs/SECURITY.md+8−2■■■■■
plugin.json+1−1■■
src/wh_http.c+10−11■■■■■
src/wh_http.h+7−2■■■■■
tests/run.sh+1−1■■
6 files+28−18
Diff
docs/SECURITY.md+8−2■■■■■
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
5050 choice.
5151
5252 **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.
5561
5662 **Request splitting.** A header value containing CR or LF is refused at save time
5763 (`value` validation) and again at request time (`wh_http.c` skips framing headers and
plugin.json+1−1■■
index 235fa09..b8e579e 100644
--- a/plugin.json
+++ b/plugin.json
@@ -1,7 +1,7 @@
11 {
22 "slug": "webhook",
33 "id": "plugin_webhook",
4- "version": "1.0.0",
4+ "version": "1.0.1",
55 "name": "webhook",
66 "desc": "HTTP triggers",
77 "title": "Named Webhooks & REST Triggers (MCP)",
src/plugin_webhook.c+1−1■■
index aec298c..c07d28b 100644
--- a/src/plugin_webhook.c
+++ b/src/plugin_webhook.c
@@ -75,7 +75,7 @@
7575 #define PLUGIN_ID "plugin_webhook"
7676 #define PLUGIN_NAME "webhook"
7777 #define PLUGIN_DESC "HTTP triggers"
78-#define PLUGIN_VER "1.0.0"
78+#define PLUGIN_VER "1.0.1"
7979 #define PLUGIN_KIND "mcp"
8080
8181 /* =====================================================================
src/wh_http.c+10−11■■■■■
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,
905905 if (!sess) { snprintf(r->error, sizeof r->error, "WinHttpOpen failed"); return -1; }
906906 WinHttpSetTimeouts(sess, WH_CONNECT_MS, WH_CONNECT_MS, WH_READ_MS, WH_READ_MS);
907907
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);
912909 a2w(u->path[0] ? u->path : "/", wpath, WH_URL_MAX + 8);
913910 a2w(method, wmethod, 16);
914911
@@ -934,13 +931,15 @@ static int exchange_winhttp(const wh_url *u, const char *method,
934931 DWORD pol = WINHTTP_OPTION_REDIRECT_POLICY_NEVER;
935932 WinHttpSetOption(req, WINHTTP_OPTION_REDIRECT_POLICY, &pol, sizeof pol);
936933 }
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.) */
944943
945944 host_has_port = !((u->tls && u->port == 443) || (!u->tls && u->port == 80));
946945 {
src/wh_http.h+7−2■■■■■
index 626e24d..ca61399 100644
--- a/src/wh_http.h
+++ b/src/wh_http.h
@@ -15,8 +15,13 @@
1515 *
1616 * 2. Verified TLS. POSIX wraps the validated socket in mbedTLS (TLS 1.2+,
1717 * 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.
2025 *
2126 * Redirects are NOT followed: a hook's URL is part of its definition, so a
2227 * 30x is reported as a status instead of silently becoming a request to
tests/run.sh+1−1■■
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'
111111 json_ok "--meta daemon false" "$meta" 'd["daemon"] is False'
112112 json_ok "--meta menus false" "$meta" 'd["menus"] is False'
113113 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"'
115115 check "--meta is a single line" "1" "$($BIN --meta | wc -l | tr -d ' ')"
116116
117117 schema=$($BIN --schema)
118118
docs/SECURITY.md+8−2■■■■■
index 2968b90..d45af97 100644index 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 the52 **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 validated53+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 time62 **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 and63 (`value` validation) and again at request time (`wh_http.c` skips framing headers and
plugin.json+1−1■■
index 235fa09..b8e579e 100644index 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)",
src/plugin_webhook.c+1−1■■
index aec298c..c07d28b 100644index 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 /* =====================================================================
src/wh_http.c+10−11■■■■■
index 511b14d..41abeff 100644index 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 the908+ 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 {
src/wh_http.h+7−2■■■■■
index 626e24d..ca61399 100644index 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) with17 * VERIFY_PEER, hostname check, system or WEBHOOK_TLS_CA_FILE anchors) with
18- * no insecure bypass. _WIN32 uses WinHTTP against the validated numeric18+ * 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 a26 * 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 to27 * 30x is reported as a status instead of silently becoming a request to
tests/run.sh+1−1■■
index 0ac9149..6c5e49a 100755index 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)
118118