【问题标题】:Automatic trailing slash redirect leaks internal IP in the Location header自动尾部斜杠重定向会在 Location 标头中泄漏内部 IP
【发布时间】:2023-03-31 23:21:01
【问题描述】:

在执行curl -ILk http://192.168.0.4/app 时,301 重定向的 Location 标头是 http://my-srv.local/app/,这是一个服务器本地地址。我已经把server_name_in_redirect on到处都去掉了,但是结果是一样的。

配置:

server {
    server_name my-nginx;
    server_name_in_redirect on;
    set $endpoint http://my-srv.local;
    location / {
        server_name_in_redirect  on;
        proxy_pass               $endpoint;
    }
}

注意:我使用的 nginx 版本还没有absolute_redirect

参考:Information leak with automatic trailing slash redirect

如何使它指向正确的 URL 或至少防止泄漏?

【问题讨论】:

  • nginx 没有生成重定向,端点是。您可以尝试添加多个proxy_redirect statements 之一来更改Location 标头。
  • @RichardSmith,看起来proxy_redirect $endpoint http://$host; 做了正确的事。这就是你的建议吗?
  • 如果您无法更改端点,它可能是您唯一的其他解决方案。

标签: redirect nginx


【解决方案1】:

所以是my-srv.local 产生了该响应(这很合理)。使用 nginx 1.11.8+ 它可能会生成相对重定向。与此同时,可能的解决方法是覆盖该重定向:

server {
    server_name my-nginx;
    set $endpoint http://my-srv.local;
    location / {
        proxy_pass               $endpoint;
        proxy_redirect           $endpoint http://$host;
    }
}

【讨论】:

    猜你喜欢
    • 2016-10-29
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 2016-08-13
    相关资源
    最近更新 更多