dounianluo0086 2015-09-16 23:58
浏览 30
已采纳

如果将csrf令牌放在隐藏输入中,则恶意网站不可能使用CURL

and then strip the tag from the source code to use on a malicious POST request?

Say for example, the website places a hidden input like so:

<input type="hidden" value="{session token here}" name="token">

And then the legit website will check the code:

<?php 
  if(Request::post('token') != Session::get('token'):
     //generate new token, display errors etc
  endif;
?>

Couldn't the illegitimate website use CURL to scrape the source code and get form by names/ids etc and then get that token and place it inside their forged form and bypass the token security?

  • 写回答

1条回答 默认 最新

  • doulu8341 2015-09-17 00:33
    关注

    The CSRF ("cross-site request forgery") protection token must only be valid for a specific account (or, better yet, a specific session). An attacker who wanted to discover a victim's CSRF protection using curl or similar would need to know the victim's session token. (Of course, if they have the session token, they can just make requests directly without bothering to send them across sites.)

    CSRF is an attack where I forge requests in a user's session by using my site to tell the user's browser to send a request to your site (which is hosted on a totally different server and domain name, of course, thus "cross-site"). It works, even though I (the attacker) don't know the victim's session token, because the victim's browser automatically sends all the cookies (for your site) with any request to your site, even if the request was made because of the content of my site.

    I never see those cookies, though; they go straight from the victim's browser to your server, leaving mine totally out of the loop. I can't get them using JavaScript or similar, either, because of the same-origin policy. Since I don't have the session cookie, I can't add it to curl. Without that, I can't request the CSRF protection token that is valid for the victim's session, so if your server uses CSRF protection correctly, it won't trust the forged requests.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?