Ethnaで手軽にCSRF対策する

冗長な解説はしない。まず、プロジェクト毎のActionForm(ActionClassではない)の中で


    function _validatePlus()
    {
        if ($this->use_csrf_plugin == true) {
            if (!Ethna_Util::isCsrfSafe()) {
                $this->ae->add(null, '外部からのリクエストは受け付けていません');
            }
        }
    }

と書いておいて、さらに、プロジェクト毎のViewClassで、


    function getFormBlock($content, $params)
    {
        // method
        if (isset($params['method']) === false) {
            $params['method'] = 'post';
        }
        if ($this->af->use_csrf_plugin == true) {
            Ethna_Util::setCsrfID();
            $csrf = smarty_function_csrfid(array(), &$renderer);
            $content .= $csrf;
        }
        return $this->_getFormInput_Html('form', $params, $content, false);
    }

としておくと、ActionFormで$use_csrf_plugin = true;した時だけ自動的にcsrf用のフォームが追加され、validateした時に一緒に検証されるようになる。はず。

Related posts:

  1. PEARパッケージが存在するかどうかチェックする
  2. 郵便番号の書かれたCSVをsqliteにINSERTするスクリプト
  3. Last-Modified入れてみた
  4. PEAR::Pager使った。
  5. 最近のSQLite操作とか

Ethnaで手軽にCSRF対策する” への1件のコメント

  1. ピンバック: スパムとか

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

ねこ認証:9つのパネルの中からねこを3匹選んでください

Additional comments powered byBackType