#115·gixy

检测默认值未为地图指令指定的情况

作者: oxdef创建于 2020年11月12日更新于 2025年12月16日
标签new plugin

当使用 map 进行某种授权控制时,情况通常是这样的。例如,代码如下所示:

nginx
http {
...
map $uri $mappocallow {
/map-poc/private 0;
/map-poc/secret 0;
/map-poc/public 1;
}
...
}
nginx
server {
...
location /map-poc {
if ($mappocallow = 0) {return 403;}
return 200 "Hello. It is private area: $mappocallow";
}
...
}
[根据手册](https://nginx.org/en/docs/http/ngx_http_map_module.html):
> 默认值
> 如果源值不匹配任何指定的变体,则设置结果值。如果未指定默认值,则默认结果值将为空字符串。