Answer a question

So i map $http_cookie to check all cookies the client sends the only one i want to intercept to obtain the value of the cookie is any cookie with a MD5 HASH.

The regex to detect a MD5 hash is this

[0-9a-f]{32}

But when i add it to my map directive Nginx won't run because the regex is wrong.

This is my cookie map the issue with this is it gets all cookies i only want the ones with a MD5 sum.

map $http_cookie $session_id_value {
default '';
~^.*.+\=(?<session_value>[\w]+).*$ $session_value;
}

I try this

map $http_cookie $session_id_value {
default '';
~^.*[0-9a-f]{32}.+\=(?<session_value>[\w]+).*$ $session_value;
}

But Nginx does not like my regex. So it errors and won't run.

I test with the echo module to see the value of the cookie my regex has grabbed but currently it keeps grabbing the first random cookie not the one with a MD5 hash for a name.

echo "Session Cookie Value : $session_id_value";
echo "httpcookie : $http_cookie";

Answers

That is a syntax error. From the rewrite documentation:

If a regular expression includes the “}” or “;” characters, the whole expressions should be enclosed in single or double quotes.

Try:

map $http_cookie $session_id_value {
default '';
"~^.*[0-9a-f]{32}.+\=(?<session_value>[\w]+).*$" $session_value;
}
Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐