Nginx:如何转义proxy_pass的参数值

时间:2017-05-23 14:57:43

标签: nginx

我们有这样的位置配置:

location ~ ^/suggest/(?<search>.+) {
    proxy_pass https://internal.host/v1/products?suggest=$search;
}

问题是internal.host按原样接收$search,这意味着来自外部的任何人都可以将&another_param=value作为$search的值传递,从而获得未经授权的访问权限远程端点。

问题是:如何逃避参数值?

1 个答案:

答案 0 :(得分:0)

location ~ ^/app/(.*)$ {
    proxy_pass       http://192.169.154.102:9999/some_dir/$1;
}

此示例导致:

test.com/app/request/xxxxx => http://192.168.154.102:9999/some_dir/xxxxx

并非需要调整示例以满足您的需求。 有关带参数的proxy_pass(ing)的更多信息,请查看this link。此外,接收参数的Web应用程序/脚本应检查给定的参数。 之前使用参数完成任何操作,执行检查和/或过滤传递的参数!如果上述方法确实限制了参数,也请进行一些检查,但请检查。

示例来自:Nginx proxy_pass: examples for how does nginx proxy_pass map the request