teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

update

2016/03/24 18:11

投稿

mpyw
mpyw

スコア5223

answer CHANGED
@@ -36,4 +36,6 @@
36
36
  }
37
37
 
38
38
  }
39
- ```
39
+ ```
40
+
41
+ - [とっても簡単なCSRF対策](http://qiita.com/mpyw/items/8f8989f8575159ce95fc)

1

updated

2016/03/24 18:11

投稿

mpyw
mpyw

スコア5223

answer CHANGED
@@ -26,11 +26,11 @@
26
26
  return hash(self::HASH_ALGO, session_id() . $salt);
27
27
  }
28
28
 
29
- public static function validate($token, $throw = true)
29
+ public static function validate($token, $throw = false)
30
30
  {
31
31
  $success = self::generate() === $token;
32
32
  if (!$success && $throw) {
33
- throw new \RuntimeException('CSRF validation failed.');
33
+ throw new \RuntimeException('CSRF validation failed.', 400);
34
34
  }
35
35
  return $success;
36
36
  }