relay: make HTTP headers case-insensitive for WebSocket connections (closes #888)

v2.8-utf8proc
Sébastien Helleu 2017-01-11 07:11:01 +01:00
parent 7cd4a23cdc
commit b547bf6bbb
3 changed files with 9 additions and 7 deletions

View File

@ -52,6 +52,7 @@ Bug fixes::
* irc: fix buffer switching on manual join for forwarded channels (issue #876)
* irc: add missing tags on CTCP message sent
* lua: fix integers returned in Lua >= 5.3 (issue #834)
* relay: make HTTP headers case-insensitive for WebSocket connections (issue #888)
* relay: set status to "authentication failed" and close immediately connection in case of authentication failure in weechat and irc protocols (issue #825)
* script: reload a script after upgrade only if it was loaded, set autoload only if the script was auto-loaded (issue #855)

View File

@ -411,7 +411,7 @@ relay_client_recv_text (struct t_relay_client *client, const char *data)
weechat_prefix ("error"),
RELAY_PLUGIN_NAME,
weechat_hashtable_get (client->http_headers,
"Origin"));
"origin"));
}
break;
}
@ -419,7 +419,7 @@ relay_client_recv_text (struct t_relay_client *client, const char *data)
}
ptr_real_ip = weechat_hashtable_get (
client->http_headers, "X-Real-IP");
client->http_headers, "x-real-ip");
if (ptr_real_ip)
{
weechat_printf_date_tags (

View File

@ -86,10 +86,11 @@ relay_websocket_save_header (struct t_relay_client *client,
if (!pos || (pos == message))
return;
/* get header name */
/* get header name, which is case-insensitive */
name = weechat_strndup (message, pos - message);
if (!name)
return;
weechat_string_tolower (name);
/* get pointer on header value */
ptr_value = pos + 1;
@ -143,20 +144,20 @@ relay_websocket_client_handshake_valid (struct t_relay_client *client)
const char *value;
/* check if we have header "Upgrade" with value "websocket" */
value = weechat_hashtable_get (client->http_headers, "Upgrade");
value = weechat_hashtable_get (client->http_headers, "upgrade");
if (!value)
return -1;
if (weechat_strcasecmp (value, "websocket") != 0)
return -1;
/* check if we have header "Sec-WebSocket-Key" with non-empty value */
value = weechat_hashtable_get (client->http_headers, "Sec-WebSocket-Key");
value = weechat_hashtable_get (client->http_headers, "sec-websocket-key");
if (!value || !value[0])
return -1;
if (relay_config_regex_websocket_allowed_origins)
{
value = weechat_hashtable_get (client->http_headers, "Origin");
value = weechat_hashtable_get (client->http_headers, "origin");
if (!value || !value[0])
return -2;
if (regexec (relay_config_regex_websocket_allowed_origins, value, 0,
@ -193,7 +194,7 @@ relay_websocket_build_handshake (struct t_relay_client *client)
int length;
sec_websocket_key = weechat_hashtable_get (client->http_headers,
"Sec-WebSocket-Key");
"sec-websocket-key");
if (!sec_websocket_key || !sec_websocket_key[0])
return NULL;