Home > Ethnaで手軽にCSRF対策する

Ethnaで手軽にCSRF対策する

  • 2006-12-13(2006-12-13 17:19:15)

このエントリーをはてブする

冗長な解説はしない。まず、プロジェクト毎の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した時に一緒に検証されるようになる。はず。

このエントリーのはてなブックマーク

  • 2006年12月24日 hiro_y ethna php security Ethna 2.3.0によるCSRF対策。ワンタイムトークン。

Comment

Comment Form

Name
Url
Comment
Cookie
Preview

Trackback

TrackBackPingURL:

Djangoで手軽にCSRF対策する - スパムとか - 2006-12-14 13:20:35

武蔵流プログラマへの道で、「Ethnaで手軽にCSRF対策する」というエントリが上がっていたので、「Djangoで手軽にCSRF対策する」というまねっ子エントリ。
#LLRingではお世話になりました

はてブ

Page Top