jsproxy/server/proc-hdr.conf
2019-03-04 13:45:36 +08:00

78 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 标记客户端是否已安装 Service Worker
# 0请求任何路径都返回 SW 安装页面www/__setup.html
# 1正常反向代理
set $_hasSw '0';
# 标记资源的协议
# 0HTTP
# 1HTTPS
set $_isHttp '0';
# 标记是否为 CORS 请求
# 0不转发 Origin 头
# 1调整并转发 Origin 头
set $_hasCors '0';
# 记录资源的端口号
set $_port '';
set $_ref '';
set $_ori $http_origin;
set $_acao '';
# 获取并删除 flag 参数
# 参数格式: isHttp .. port
if ($args ~
(?<_pre>.*?)&flag__=(?<_hasSw>.)(?<_isHttp>.)(?<_hasCors>.)(?<_port>\d*)(?<_post>.*)
) {
set $args $_pre$_post;
set $_js 1;
}
# 调整 Referer 头
# TODO未考虑协议和端口下面的 cors 也有这问题
if ($http_referer ~ ^https://(?<_vhost>[^/]+)(?<_path>.*)) {
set $_ref https://$_vhost_to_rhost$_path;
set $_acao https://$_vhost;
}
if ($_ori) {
set $_acao $_ori;
}
if ($_acao = '') {
set $_acao '*';
}
# ServiceWorker 的 fetch 强制 cors 模式,
# 所以需要该标记,标识原始请求是否为 cors
if ($_hasCors = '0') {
set $_ori '';
}
if ($_ori ~ ^https://(?<_vhost>.*)) {
set $_ori https://$_vhost_to_rhost;
}
proxy_set_header Origin $_ori;
proxy_set_header Referer $_ref;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
# CSP 可能导致注入页面资源无法加载
more_clear_headers
content-security-policy
content-security-policy-report-only
expect-ct
x-frame-options
;
more_set_headers
'access-control-allow-credentials: true'
'access-control-allow-origin: $_acao'
'strict-transport-security: max-age=99999999; includeSubDomains; preload'
;
# 重定向调整
# 直接用 return 指令返回状态码,会丢失其他的头,比如 set-cookie
header_filter_by_lua_file ../proc-redir.lua;