powered by nequal

rhaco1-doc :: 050-arbo/HtmlCsrfFilter.txt

http://wikihub.org/wiki/rhaco1-doc/050-arbo/HtmlCsrfFilter

Table of contents:

collapse all expand all

Updates:

HtmlCsrfFilter

CSRF 対策を行います.

Flow や Flow を継承したクラスにフィルターとして組み込むことで利用が可能です.

インストール

インストールにて,"org.rhaco.generic.filter.HtmlCsrfFilter" を指定してください.

Views で使う

<?php
require_once dirname(__FILE__)."/__init__/.php";
Rhaco::import("generic.Views");
Rhaco::import("model.Profile");
Rhaco::import("database.DbUtil");
 
$views = new Views(new DbUtil(Profile::connection()),"org.rhaco.generic.filter.HtmlCsrfFilter");
$views->create(new Profile())->write();

Urls で使う

<?php
Rhaco::import("generic.Urls");
Rhaco::import("database.DbUtil");
Rhaco::import("model.Profile");
 
Urls::parser(array(
	"^$"=>array("class"=>"generic.Views","method"=>"create")
),new DbUtil(Profile::connection()),"org.rhaco.generic.filter.HtmlCsrfFilter")->write();

と View の場合と同じように渡します.

これによって,全ての画面において,自動的に HtmlCsrfFilter が有効になります.

RequestLogin との連携

RequestLogin を用いてログイン認証を行う際に,セットアップフレームワークに記述しているコードを使うとログイン後にCSRFエラーが出力されてします.

ですので,Flow や Views と RequestLogin を連携させるためには以下のようにします.

<?php
require_once "__init__.php";
 
Rhaco::import("database.DbUtil");
Rhaco::import("model.Profile");
Rhaco::import("generic.Views");
$view = new Views(new DbUtil(Profile::connection()),"org.rhaco.generic.filter.HtmlCsrfFilter");
RequestLogin::loginRequired(null,$view);
$view->confirmedUpdate(new Profile(1),"csrf.php")->write();