From e7eb716588b04fc09ce75e3c793e13d57c1dc696 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 17 May 2021 15:07:35 +0200 Subject: [PATCH] AnyEvent/websocket_proxy: drop handling of websocket subprotocols We do not support any, and we only ever send binary frames, so drop trying to parse the header. For compatibility with current clients (novnc, pve-xtermjs), we have to reply with the protocols it sent. Signed-off-by: Dominik Csapak --- src/PVE/APIServer/AnyEvent.pm | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm index a7d31cc..6f0abb7 100644 --- a/src/PVE/APIServer/AnyEvent.pm +++ b/src/PVE/APIServer/AnyEvent.pm @@ -650,11 +650,13 @@ sub websocket_proxy { # todo: use stop_read/start_read if write buffer grows to much + # for backwards, compatibility, we have to reply with the websocket + # subprotocol from the request my $res = "$proto 101 Switching Protocols\015\012" . "Upgrade: websocket\015\012" . "Connection: upgrade\015\012" . "Sec-WebSocket-Accept: $wsaccept\015\012" . - "Sec-WebSocket-Protocol: $wsproto\015\012" . + ($wsproto ne "" ? "Sec-WebSocket-Protocol: $wsproto\015\012" : "") . "\015\012"; $self->dprint($res); @@ -902,14 +904,7 @@ sub handle_api2_request { die "unable to upgrade to protocol '$upgrade'\n" if !$upgrade || ($upgrade ne 'websocket'); my $wsver = $r->header('sec-websocket-version'); die "unsupported websocket-version '$wsver'\n" if !$wsver || ($wsver ne '13'); - my $wsproto_str = $r->header('sec-websocket-protocol'); - die "missing websocket-protocol header" if !$wsproto_str; - my $wsproto; - foreach my $p (PVE::Tools::split_list($wsproto_str)) { - $wsproto = $p if !$wsproto && $p eq 'base64'; - $wsproto = $p if $p eq 'binary'; - } - die "unsupported websocket-protocol protocol '$wsproto_str'\n" if !$wsproto; + my $wsproto = $r->header('sec-websocket-protocol') // ""; my $wskey = $r->header('sec-websocket-key'); die "missing websocket-key\n" if !$wskey; # Note: Digest::SHA::sha1_base64 has wrong padding