【发布时间】:2020-10-23 01:03:53
【问题描述】:
我在 docker 中使用以下 nginx.conf 运行 openresty 以删除特殊 cookie,这样我就可以避免将此 cookie 代理到上游。
user nobody nogroup;
pid /data/var/run/nginx.pid;
worker_processes 36;
worker_rlimit_nofile 51000;
events {
worker_connections 50000;
accept_mutex off;
}
error_log /data/log/nginx/default.error.log;
daemon off;
http {
include mime.types;
default_type text/html;
log_format main '$http_x_req_id [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time $upstream_response_time "$remote_addr" - "$host" "$http_log_traceid"';
access_log /data/log/nginx/default.access.log main;
lua_package_path "/data/etc/nginx/lua/?.lua;/data/etc/nginx/lua/?/init.lua;;";
lua_package_cpath "/data/etc/nginx/lua/clib/?.so;;";
upstream nginx-platform {
server host.docker.internal:9090;
}
server {
listen 80 default_server reuseport;
server_name _;
set $stripped_cookie $http_cookie;
if ($http_cookie ~ "(.*)\s*_u_sh0=[^;]+;?(.*)$") {
set $stripped_cookie $1$2;
}
location / {
include proxy.conf;
include proxy-headers.conf;
proxy_pass http://nginx-platform;
proxy_set_header Host $host;
proxy_set_header Cookie $stripped_cookie;
}
}
}
但是当请求url被编码时,cookie也被编码了。如果我在终端中运行以下代码
curl 'professor.in.home.com/221%23?a=22%22&name=test' -H "cookie: ff=gg; _u_sh0=48c1be09c567538fe327348b241aebbd0642f24c1c02cfd28506dd561414112d; dd=e++d; ee=ff;"
然后,我grep下面的必要信息,cookie也被编码了。
E.._/#@.@.\.......A...#.+(vf..8|P.......GET /221%23?a=22%22&name=test HTTP/1.1
X-Forwarded-For: 172.17.0.1
Connection: upgrade
Host: professor.in.home.com
Cookie: ff=gg%3B%20%20dd=e%2B%2Bd%3B%20ee=ff%3B
User-Agent: curl/7.54.0
Accept: */*
如何避免这种编码的cookie???
【问题讨论】: