Created
October 16, 2013 23:52
-
-
Save arekinath/7017005 to your computer and use it in GitHub Desktop.
potential sec-websocket-protocol fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/apps/wiggle/src/wiggle_wsproxy.erl b/apps/wiggle/src/wiggle_wsproxy.erl | |
index 86da16d..0049aad 100644 | |
--- a/apps/wiggle/src/wiggle_wsproxy.erl | |
+++ b/apps/wiggle/src/wiggle_wsproxy.erl | |
@@ -24,13 +24,24 @@ terminate(_Req, _State) -> | |
ok. | |
websocket_init(_Any, Req, []) -> | |
+ Req1 = case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of | |
+ {undefined, _, ReqR} -> ReqR; | |
+ {ok, List, ReqR} -> | |
+ case lists:member(<<"base64">>, List) of | |
+ true -> cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, <<"base64">>, ReqR); | |
+ _ -> cowboy_http_req:reply(400, [], <<"">>, ReqR), stop | |
+ end | |
+ end, | |
+ case Req1 of | |
+ stop -> {shutdown, Req1}; | |
+ _ -> | |
case wiggle_session:get(Req) of | |
undefined -> | |
- {ok, Req1} = cowboy_http_req:reply(401, [{'Content-Type', <<"text/html">>}], <<"">>, Req), | |
- {shutdown, Req1}; | |
+ {ok, Req2} = cowboy_http_req:reply(401, [{'Content-Type', <<"text/html">>}], <<"">>, Req1), | |
+ {shutdown, Req2}; | |
Auth -> | |
- {[<<"machines">>, ID, <<"vnc">>], Req1} = cowboy_http_req:path(Req), | |
+ {[<<"machines">>, ID, <<"vnc">>], Req2} = cowboy_http_req:path(Req1), | |
case libsniffle:get_machine(Auth, ID) of | |
{ok, VM} -> | |
{hypervisor, Hypervisor} = lists:keyfind(hypervisor, 1, VM), | |
@@ -45,26 +56,27 @@ websocket_init(_Any, Req, []) -> | |
[binary,{nodelay, true}, {packet, 0}]) of | |
{ok, Socket} -> | |
gen_tcp:controlling_process(Socket, self()), | |
- Req2 = cowboy_http_req:compact(Req), | |
- {ok, Req2, {Socket}, hibernate}; | |
+ Req3 = cowboy_http_req:compact(Req2), | |
+ {ok, Req3, {Socket}, hibernate}; | |
_ -> | |
- Req2 = cowboy_http_req:compact(Req), | |
- {ok, Req2, undefined, hibernate} | |
+ Req3 = cowboy_http_req:compact(Req2), | |
+ {ok, Req3, undefined, hibernate} | |
end; | |
E -> | |
- {ok, Req2} = cowboy_http_req:reply(505, [{'Content-Type', <<"text/html">>}], | |
- list_to_binary(io_lib:format("~p", E)), Req1), | |
- {shutdown, Req2} | |
+ {ok, Req3} = cowboy_http_req:reply(505, [{'Content-Type', <<"text/html">>}], | |
+ list_to_binary(io_lib:format("~p", E)), Req2), | |
+ {shutdown, Req3} | |
end; | |
E -> | |
- {ok, Req2} = cowboy_http_req:reply(505, [{'Content-Type', <<"text/html">>}], | |
- list_to_binary(io_lib:format("~p", E)), Req1), | |
- {shutdown, Req2} | |
+ {ok, Req3} = cowboy_http_req:reply(505, [{'Content-Type', <<"text/html">>}], | |
+ list_to_binary(io_lib:format("~p", E)), Req2), | |
+ {shutdown, Req3} | |
end; | |
false -> | |
- {ok, Req2} = cowboy_http_req:reply(401, [{'Content-Type', <<"text/html">>}], | |
- <<"">>, Req), | |
- {shutdown, Req2} | |
+ {ok, Req3} = cowboy_http_req:reply(401, [{'Content-Type', <<"text/html">>}], | |
+ <<"">>, Req2), | |
+ {shutdown, Req3} | |
+ end | |
end | |
end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment