2017-05-23 50 views
0

我們有這樣的位置配置:Nginx的:如何逃脫參數值proxy_pass

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

的問題是,internal.host接收$search原樣,這意味着從外部任何人都可以通過&another_param=value作爲一個值$search,從而獲得對遠程端點的未授權訪問。

問題是:如何逃避參數值?

回答

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 

不就是例子就需要進行調整,以滿足您的需求。 請參閱this link瞭解更多關於proxy_pass(ing)的信息。此外,您的Web應用程序/腳本接受參數應對給定的參數進行檢查。 之前任何事情都完成了參數,執行通過參數的檢查和/或過濾!如果上面的方法確實限制了參數,請做一些檢查,但是請檢查。

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

+0

對不起,我想你錯誤地理解了這個問題。我需要將它作爲參數值傳遞,而不是作爲路徑。 2.在傳遞之前,我需要使用url_escaped,否則可能會傳遞未轉義的&符號,從而傳遞任意參數。正如你所能理解的,它與接受請求的應用程序中的驗證無關。 –