You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
session_start();
$clean = array();
if (isset($_REQUEST['item'] && isset($_REQUEST['quantity']))
{
/* Filter Input ($_REQUEST['item'], $_REQUEST['quantity']) */
if (buy_item($clean['item'], $clean['quantity']))
{
echo '<p>Thanks for your purchase.</p>';
}
else
{
echo '<p>There was a problem with your order.</p>';
}
}
?>
<?php
$token_age = time() - $_SESSION['token_time'];
$token = $_SESSION['token'];
unset($_SESSION['token']);
if ($token_age <= 300)
{
/* Less than five minutes has passed. */
}
?>
基本概念
如果能成功的话,攻击者如果取得了当合法用户访问时,可以引发购买的URL格式。在这种情况下,进行跨站请求伪造攻击非常容易,因为攻击者只要引发受害者访问该URL即可。攻击者并不需要取得用户授权
防范方法
使用POST方式而不是使用GET来提交表单,在处理表单提交时使用$_POST而不是$_REQUEST
验证表单来自真正的页面,而不是伪造的。需要验证。
生成表单token
提交表单的时候,token也以前提交到服务器。
一个跨站请求伪造攻击就必须包括一个合法的验证码以完全模仿表单提交。由于验证码的保存在用户的session中的,攻击者必须对每个受害者使用不同的验证码。这样就有效的限制了对一个用户的任何攻击,它要求攻击者获取另外一个用户的合法验证码。使用你自己的验证码来伪造另外一个用户的请求是无效的。
该验证码可以简单地通过一个条件表达式来进行检查:
你也可以让token只能使用一次,在每次请求被请求后token通过后销毁这个token。可以更安全,同时也可以防止表单重复提交。
(完)
The text was updated successfully, but these errors were encountered: