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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度