Workaround for Safari + Websockets + basic auth

https://bugs.webkit.org/show_bug.cgi?id=80362
This commit is contained in:
Devaev Maxim 2018-08-11 03:46:42 +03:00
parent 3d2282f8f9
commit ba650456aa
4 changed files with 51 additions and 14 deletions

View File

@ -1,3 +1,5 @@
load_module /usr/lib/nginx/modules/ngx_http_lua_module.so;
user http; user http;
worker_processes 4; worker_processes 4;
@ -5,7 +7,7 @@ worker_processes 4;
error_log /dev/null crit; error_log /dev/null crit;
events { events {
worker_connections 64; worker_connections 1024;
use epoll; use epoll;
} }
@ -25,12 +27,6 @@ http {
scgi_temp_path /tmp/nginx.scgi_temp; scgi_temp_path /tmp/nginx.scgi_temp;
uwsgi_temp_path /tmp/nginx.uwsgi_temp; uwsgi_temp_path /tmp/nginx.uwsgi_temp;
#PROD server {
#PROD listen 80;
#PROD server_name localhost;
#PROD return 301 https://$host$request_uri;
#PROD }
upstream kvmd { upstream kvmd {
server localhost:8081 fail_timeout=0s max_fails=0; server localhost:8081 fail_timeout=0s max_fails=0;
} }
@ -39,6 +35,17 @@ http {
server localhost:8082 fail_timeout=0s max_fails=0; server localhost:8082 fail_timeout=0s max_fails=0;
} }
#PROD server {
#PROD listen 80;
#PROD server_name localhost;
#PROD return 301 https://$host$request_uri;
#PROD }
#PROD lua_shared_dict WS_TOKENS 10m;
#PROD init_by_lua_block {
#PROD WS_TOKEN_EXPIRES = 10;
#PROD }
server { server {
#PROD listen 443 ssl http2; #PROD listen 443 ssl http2;
server_name localhost; server_name localhost;
@ -58,7 +65,27 @@ http {
index index.html; index index.html;
} }
location /wsauth {
# Workaround for Safari: https://bugs.webkit.org/show_bug.cgi?id=80362
#PROD access_by_lua_block {
#PROD local token = ngx.encode_base64(ngx.sha1_bin(ngx.var.http_Authorization));
#PROD ngx.shared.WS_TOKENS:set(token, token, WS_TOKEN_EXPIRES);
#PROD ngx.header["Set-Cookie"] = "WS_ACCESS_TOKEN=" .. token .. "; Path=/; Expires=" .. ngx.cookie_time(ngx.time() + WS_TOKEN_EXPIRES);
#PROD }
content_by_lua_block {
ngx.say("ok");
}
}
location /kvmd/ws { location /kvmd/ws {
#PROD auth_basic off;
#PROD access_by_lua_block {
#PROD local token = ngx.var.cookie_WS_ACCESS_TOKEN;
#PROD local value, _ = ngx.shared.WS_TOKENS:get(token);
#PROD if value == nil then
#PROD ngx.exec("/wsauth");
#PROD end
#PROD }
rewrite /kvmd/ws /ws break; rewrite /kvmd/ws /ws break;
proxy_pass http://kvmd; proxy_pass http://kvmd;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;

View File

@ -31,7 +31,8 @@ RUN pacman -Syy \
&& user-packer -S --noconfirm \ && user-packer -S --noconfirm \
python \ python \
python-pip \ python-pip \
nginx \ nginx-mainline \
nginx-mainline-mod-lua \
mjpg-streamer-pikvm \ mjpg-streamer-pikvm \
socat \ socat \
&& pacman -Sc --noconfirm && pacman -Sc --noconfirm

View File

@ -20,11 +20,19 @@ var session = new function() {
}; };
this.startPoller = function() { this.startPoller = function() {
var http = tools.makeRequest("GET", "/wsauth", function() {
if (http.readyState === 4) {
if (http.status === 200) {
__ws = new WebSocket((location.protocol == "https:" ? "wss" : "ws") + "://" + location.host + "/kvmd/ws"); __ws = new WebSocket((location.protocol == "https:" ? "wss" : "ws") + "://" + location.host + "/kvmd/ws");
__ws.onopen = __wsOpenHandler; __ws.onopen = __wsOpenHandler;
__ws.onmessage = __wsMessageHandler; __ws.onmessage = __wsMessageHandler;
__ws.onerror = __wsErrorHandler; __ws.onerror = __wsErrorHandler;
__ws.onclose = __wsCloseHandler; __ws.onclose = __wsCloseHandler;
} else {
__wsCloseHandler(null);
}
}
});
}; };
var __wsOpenHandler = function(event) { var __wsOpenHandler = function(event) {

View File

@ -1,5 +1,6 @@
RUN pkg-install \ RUN pkg-install \
nginx \ nginx-mainline \
nginx-mainline-mod-lua \
apache-tools \ apache-tools \
mjpg-streamer-pikvm \ mjpg-streamer-pikvm \
python \ python \