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.

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

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划