使用 ELB 和节点防止 X-Forwarded-For 欺骗

Prevent X-Forwarded-For spoofing using ELB and Node

我正在分析一个 public 路由的堆栈,该路由位于一个弹性负载平衡器上,它打开一个由 PM2 公开的端口,该端口使用 koa 模块启动一个节点应用程序。目前,IP 已记录并且仅取决于 X-Forwarded-For header。如果此 header 是使用 curl 手动创建的,则应用程序会将其写入 IP 地址。

是否有一种简单的方法来防止此 header 的欺骗或设置 AWS 的 ELB 以使其忽略手动插入的 headers 或者是否有比可欺骗的 header 更好的方法获取访问者的真实IP地址?

根据 doc :

If a request from a client already contains an X-Forwarded-For header, Elastic Load Balancing appends the IP address of the client at the end of the header value. In this case, the last IP address in the list is the IP address of the client.

所以最后一个IP永远是真实IP。