duanbodai5166 2011-04-21 14:15
浏览 120
已采纳

如果$ _SERVER ['HTTP_REFERER']不可靠,我将使用什么来确保网络应用程序的完整性?

I thought I was being really slick by using the $_SERVER['HTTP_REFERER'] variable to guarantee my script was being called from the appropriate page.

Luckily, when I performed a header('Location: yourPathHere.php') redirect in my testing browser, it wouldn't set the $_SERVER['HTTP_REFERER'] variable. So I looked it up at http://php.net/manual/en/reserved.variables.server.php, only to find this...

'HTTP_REFERER'

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

So my question is: How can I guarantee my page is being navigated to from a trusted source?

EDIT: To clarify questions regarding the comments section. I'm trying to avoid XSRF (cross-site request forgery).

  • 写回答

2条回答 默认 最新

  • douwei1950 2011-04-21 14:59
    关注

    Relying on any user originated input for request verification is almost no better than no verification at all.

    You should read this section on CSRF countermeasures from Wikipedia for a basic outline of available approaches to tackling the issue.

    In short:

    Web sites have various CSRF countermeasures available:

    • Requiring a secret, user-specific token in all form submissions and side-effect URLs prevents CSRF; the attacker's site cannot put the right token in its submissions
    • Requiring the client to provide authentication data in the same HTTP Request used to perform any operation with security implications (money transfer, etc)
    • Limiting the lifetime of session cookies
    • Ensuring that there is no crossdomain.xml file granting unintended access to Flash movies
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程