我们真的从CSRF中获得了保障吗?

kor*_*esh 5 php security xss csrf csrf-protection

confirm.php

<?php
 session_start();
 $token= md5(uniqid());
 $_SESSION['delete_customer_token']= $token;
 session_write_close();
?>
<form method="post" action="confirm_save.php">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
Do you really want to delete?
<input type="submit" value=" Yes " />
<input type="button" value=" No " onclick="history.go(-1);" />
Run Code Online (Sandbox Code Playgroud)

confirm_save.php

<?php
 session_start();
 $token= $_SESSION['delete_customer_token'];
 unset($_SESSION['delete_customer_token']);
 session_write_close();
 if ($_POST['token']==$token) {
   // delete the record
 } else {
   // log potential CSRF attack.
 }
?>
Run Code Online (Sandbox Code Playgroud)

假设我们有一个像这样的典型CSRF保护如果攻击者使用此代码绕过csrf令牌怎么办?

//On any site
<img src="http://cia.teletubbies.com/csrf.php" height="0" weight="0"/>

//csrf.php
$cont = get_file_contents("http://cia.google.com/confirm.php");
// parse the html using [PHP Simple HTML DOM Parser][2] and get the CSRF token
//CURL and send a POST request to confirm_save.php with the token
Run Code Online (Sandbox Code Playgroud)

这件事让我烦恼,但我懒得试图攻击任何随机网站.这有可能吗?

示例代码从php中阻止csrf被盗

更新

当有人想将令牌从一个平台传递到另一个平台或从服务器端传递到客户端时会发生什么?以Flash为例,它如何从csrf安全?

Chr*_*ner 5

您将获得用于刮擦页面的服务器会话的CSRF令牌.由于该会议不是受害者,因此是安全的.(如果您正在窃取用户的会话,则不再是CSRF攻击!)

所以,是的,除非它实施得非常糟糕,否则你不能只刮掉CSRF令牌并在CSRF攻击中使用它.