使用 Chrome 的 Data Saver 访问 Symfony 应用程序会导致 BadRequestHttpException

Accessing a Symfony app using Chrome's Data Saver causes BadRequestHttpException

使用 Chrome’s Data Saver on Android 访问我的 Symfony 网站生成错误 500。

这是日志

[2017-04-06 18:56:23] request.ERROR: Uncaught PHP Exception
Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
"The request headers contain conflicting information regarding the origin of this request." at /home/myapp/app/bootstrap.php.cache line 3184
{"exception":"[object] (Symfony\Component\HttpKernel\Exception\BadRequestHttpException(code: 0): The request headers contain conflicting information regarding the origin of this request. at /home/myapp/app/bootstrap.php.cache:3184, Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException(code: 0): The request has both a trusted Forwarded header and a trusted Client IP header, conflicting with each other with regards to the originating IP addresses of the request. This is the result of a misconfiguration. You should either configure your proxy only to send one of these headers, or configure Symfony to distrust one of them. at /home/myapp/app/bootstrap.php.cache:788)"} []

据我了解,Chrome 的 Data Saver 在我的应用程序压缩代码和图像之前充当反向代理。

我阅读了这篇关于 how to use a reverse proxy in front of a Symfony app 的文档。

问题是我没有找到任何关于 IP Chrome 的 Data Saver 代理正在使用的文档。

感谢帮助!

关键信息在这里:

The request has both a trusted Forwarded header and a trusted Client IP header

我建议解决该问题,或者 - 如果您没有权限 - 禁用冲突 header,如文档中所述:

您可能想在您的 web/ 目录中的 app.php 或 app_dev.php 中执行此操作。在创建 $request 之后。

这个错误也会影响 Drupal 8.3(可能还有 8.0/1/2)。而且你不能真正相信 FORWARDED header 因为它可以像其他任何东西一样被伪造,你不能(AFAIK)列出接受它的代理地址。因此,每当用户启用 Chrome Data Saver 时,您基本上就失去了获取其 IP 的能力,因为您不能依赖 FORWARDED header.

如果您将信任 X_FORWARDED_FOR 与受信任的反向代理列表(即您可以控制的反向代理)一起使用,则信任的默认行为会起作用。

如果法律强制您跟踪任何 user-generated 内容的用户 IP(例如在法国),这可能会成为一个问题。