LoginSignup
8
9

More than 5 years have passed since last update.

FuelPHP での CSRF 対策

Last updated at Posted at 2016-01-05

FuelPHP での CSRF 対策

まずコンフィグを有効にする。

config.php
'security' => array(
    :
    'csrf_autoload'     => false,
    'csrf_token_key'    => 'fuel_csrf_token',
    'csrf_expiration'   => 0,
    'token_salt'        => 'salt'
    :
);

値を取得する。

$token['token_key'] = Config::get('security.csrf_token_key');
$token['token'] = Security::fetch_token();

あとはHiddenを入れるだけ。

echo Form::hidden($token['token_key'], $token['token']);
<input type="hidden" name="コンフィグのcsrf_token_keyの値" value="生成された値" />

あとは項目と合わせてチェックをする。

if(Security::check_token()){
    //正しい場合
}else{
    //不正な場合
}
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9