加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 我可以信任从ServerVariables [“REMOTE_ADDR”]返回

发布时间:2020-12-16 09:53:09 所属栏目:asp.Net 来源:网络整理
导读:我有一个IIS托管的ASP.NET WebAPI应用程序,我使用ServerVariables [“REMOTE_ADDR”]获取客户??端地址并识别用户:客户端登录,我将生成一个包含客户端IP的cookie.在后续调用中,我将从cookie中获取IP,并验证它是否正确. 我可以信任该地址,或者是否存在ServerV
我有一个IIS托管的ASP.NET WebAPI应用程序,我使用ServerVariables [“REMOTE_ADDR”]获取客户??端地址并识别用户:客户端登录,我将生成一个包含客户端IP的cookie.在后续调用中,我将从cookie中获取IP,并验证它是否正确.

我可以信任该地址,或者是否存在ServerVariables [“REMOTE_ADDR”]返回的方式,例如161.121.222.223和客户真的在别的地方?

解决方法

Yes,it’s safe. It is the source IP of the TCP connection and can’t be substituted by changing an HTTP header.

One case you may want to be worry of is if you are behind a reverse proxy in which case the REMOTE_ADDR will always be the IP of the proxy server and the user IP will be provided in an HTTP header (such as X-Forwarded-For). But for the normal use case reading REMOTE_ADDR is fine.

取自:Is it safe to trust $_SERVER[‘REMOTE_ADDR’]?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读