symfonyãã¬ã¼ã ã¯ã¼ã¯ã®ã»ãã¥ãªãã£
ãã®blogã§ã¯ã主ã«jobeet*1ã¨ãããsymfony*2ãã¥ã¼ããªã¢ã«ã«æ²¿ã£ã¦symfonyèªä½ããPHPã¨ãã®å¨è¾ºã«ã¤ãã¦åå¼·ãé²ãã¦ããä¸ã§ãæ°ã«ãªã£ããã¨ã調ã¹ããã¨ãã¾ã¨ãã¦ãããã¨æãã¾ãã
éä¸ã¾ã§é²ãã¦ããã®ã§ããã°ããã¯ã¡ã¢ãè¦ã¦æãåºããªããæ¸ãã¦ãããã¨æãã¾ãã
ä»åã¯symfonyã§ã®ã»ãã¥ãªãã£ã«ã¤ãã¦ã
webã¢ããªãä½ãä¸ã§ãã»ãã¥ãªãã£ã¯åã£ã¦ãåããªãåå¨ã ã¨æãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ã«è§¦ããã®ã¯å§ãã¦ã ã£ãã®ã§ãããjobeetãå§ããåãã
- ã»ãã¥ãªãã£ã®ç¥èã¯ãã¡ããå¿ é
- åèå¼±æ§ã«ã¤ãã¦å¯¾çãæ¯ãã¦ããªãããã¬ã¼ã ã¯ã¼ã¯å´ã§å¯¾å¦ãã¦ãããã°ããã®ã«
- ã§ããã¬ã¼ã ã¯ã¼ã¯ã®æ¹ã§ãã£ã¦ãããããã»ãã¥ãªãã£ã«å¯¾ããæèãèããªããã
ã¨ã¼ãããèãã¦ã¾ããã
ãããªæãã§jobeetãã¯ãããããã§ãã
symfonyã§ã¯ãããã©ã«ãã§XSSã¨CSRF対çããã¦ããã¾ãã*3
1æ¥ç®ã«æ¸ãã¦ãã£ã¦ãé¢å¿ããããjobeetã¯
ãå®éã®ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãããªãã¼ã·ã§ã³ã¨é©åãªã¨ã©ã¼ãã³ããªã³ã°ã追å ããã®ãå¿ããªãã§ãã ããã
ã
ãèªè ã®ç·´ç¿ã®ãããã»ãã¥ãªãã£ã«ã¤ãã¦ã¯èæ ®ãã¦ãã¾ããã
ã
ããã¡ãããã¹ãã®è¨è¿°ã¯å¿ è¦ã«ãªãã¾ãã
ãªãã¦ãã¨ã¯è¨ããªããå®ç¨çãªãã¥ã¼ããªã¢ã«ãªãã§ãã
XSSã£ã¦ï¼
XSSï¼ã¯ãã¹ãµã¤ãã¹ã¯ãªããã£ã³ã°ï¼*4ã¨ã¯ã
ã¦ã§ãã¢ããªã¸ã®å
¥åããã¡ãã¨ã¨ã¹ã±ã¼ãããªãã§HTMLã«åºåãã¦ãã¾ããã¨ã§ãå
¥åã«å«ã¾ãã¦ããã¿ã°ããã®ã¾ã¾HTMLã¨ãã¦è§£éããã¦ãã¾ãã¨ããèå¼±æ§ã
ç°¡åãªä¾ã¨ãã¦ã
<div> åå : <?php echo $_POST['user'] ?></div>
ã¨ãã風ã«POSTã®å¤æ°ãç´æ¥åºåãã¦ãã¾ãã¨ã
<script>while(1){ alert( 'test' ); }</script>
ã®ããã«Javascriptãå ¥åãããæã«ãã®ã¾ã¾å®è¡ããã¦ã大å¤ãªãã¨ã«ãªãã¾ãã
ãããªæãã§ãä»»æã®ã¹ã¯ãªãããå®è¡ã§ãã¦ãã¾ãã®ã§ãXSSãå©ç¨ããæ»æã¯ããã¨ãããã
wikiã«ããã¨ãXSSãå©ç¨ãããã¨ã§
- ã¯ããã¼ã®å¤ãåå¾ãããã¯è¨å®ãããã¨ã«ãããã»ãã·ã§ã³ãã¤ã¸ã£ãã¯ãã
- å¼·å¶çãªãã¼ã¸é·ç§»ãèµ·ããããã¯ãã¹ãµã¤ããªã¯ã¨ã¹ããã©ã¼ã¸ã§ãªå¯¾çãåé¿ããï¼åå¾ããã¯ããã¼ãæ»æè å´ã§ãã®ã¾ã¾å©ç¨ã§ããªãå ´åã«ç¨ããããææ³ï¼
- ãã¼ã¸å ¨ä½ãç½®ãæãããã¨ã«ãããå½ã®ãã¼ã¸ãä½ãåºãï¼å ¸åçã«ã¯ãã£ãã·ã³ã°ã«ç¨ããããï¼
- ãã©ã¼ã ã®éä¿¡å ãç½®æãããã¨ã«ãããå ¥åã第ä¸è ãµã¤ãã«éä¿¡ããããä»åãã
ã¨ãã£ãæ»æãæç«ãããããã
対ç
XSSã®å¯¾çã¯ãåºåå¤ã®ã¨ã¹ã±ã¼ããé©åã«æ½ããã¨ãããã§ãã
ï¼ãããã§ãã¨ããã®ã¯ãèªåãã¾ã ãé©åã«ãã¨ããã®ãææ¡ãã¦ããã¦ãªãããï¼
wikiã«ããã¨ã
- HTMLã®å®ä½åç §ãç¨ãã& ã & ã«ã< ã < ã«ã> ã > ã«ã" ã " ã«ãããããç½®æãããï¼ãµãã¿ã¤ã¸ã³ã°*5ï¼
- ã¿ã°ã®å±æ§å¤ã¯å¿ ã "ã" ï¼ããã«ã¯ãªã¼ãï¼ã§æ¬ããã¾ãå±æ§å¤ä¸ã®ã¨ã¹ã±ã¼ããå¿ããªããä¾:
ã ããPHPã¨Webã¢ããªã±ã¼ã·ã§ã³ã®ã»ãã¥ãªãã£ã«ã¤ãã¦ã®ã¡ã¢*6ã«ããã¨ã
htmlspecialchars()ãéãã¦åºåããã°ãã»ã¨ãã©ã®XSSã¯åé¿ã§ãã¾ãã
ã¨ã®ãã¨ãã»ã¨ãã©ãã£ã¦ãªã«ï¼ã£ã¦æãã ããã©ã
ãã®è¾ºã¯å
¨ä½ãææ¡ã§ããããã«ãªããã¨ãããã§ããã
ããããsymfonyã¯ãªã«ããã¦ãããã®ï¼
symfonyã®escapeå¦çã«ã¤ãã¦ã¯ããããªãã¼ã¸ãè¦ã¤ãã¾ããã
symfony のエスケープ処理 - アシアルブログ
åºåå¤ã®escapingã®è¨å®ã¯ãapps/frontend/config/settings.yml ãããããã¨ã§ã§ãã¾ãã
escaping_methodã§escapeã®æ¹æ³ãæå®ãã¾ããããã©ã«ãã§ã¯ESC_SPECIALCHARSã«è¨å®ããã¦ã¾ããã
ããããã®è¨å®ã¯
- ESC_RAW: å¤ã®ã¨ã¹ã±ã¼ããè¡ããªã
- ESC_SPECIALCHARS: å ¥åã«å¯¾ãã¦ãhtmlspecialchars()ã§ã¨ã¹ã±ã¼ããè¡ã
- ESC_ENTITIES: ENT_QUOTESå¼æ°ä»ã*7ã®htmlentities()ã§ã¨ã¹ã±ã¼ããè¡ã
- ESC_JS: HTMLã¨ãã¦ä½¿ç¨ãããã§ãããJavaScriptæååãã¨ã¹ã±ã¼ãããã
- ESC_JS_NO_ENTITIES: JavaScritpæååãã¨ã¹ã±ã¼ãããããã¨ã³ãã£ãã£ã¯ä»å ããªãã
è¨äºãå°ãå¤ãã®ãæ°ã«ãªãã¾ãããã¨ã¹ã±ã¼ãã«ä½¿ããã¦ããhtmlspecialchars()ã¨htmlentities()ã®éãã«ã¤ãã¦ã¯ä»¥ä¸ã®ãã¼ã¸ããããããããã¨ã
http://d.hatena.ne.jp/teracc/20070415
èå¿ã®ã¨ã¹ã±ã¼ãã¯lib/vendor/symfony/lib/helper/EscapingHelper.phpã§å®ç¾©ãããé¢æ°ã§è¡ããã¦ãã¦ãescaping_methodã«ESC_SPECIALCHARSãæå®ããã¦ããå ´åã¯ã55è¡ç®ã®
function esc_specialchars($value) { // Numbers and boolean values get turned into strings which can cause problems // with type comparisons (e.g. === or is_int() etc). return is_string($value) ? htmlspecialchars($value, ENT_QUOTES, sfConfig::get('sf_charset')) : $value; }
ã§è¡ããã¦ãã£ã½ããã¡ããã¨htmlspecialchars()ã使ããã¦ã¾ããã
ã§ããããã©ãã§å¼ã³åºããã¦ããã¾ã§ã¯ã³ã¼ã追ãã¾ããã§ããã
ãã¨ã§ãããå°ã詳ããsymfonyã®ã³ã¼ãã追ã£ã¦è¦ããã¨æãã¾ãã
ã¡ãè¦ããæãã ã¨ããã®ããããèªãã°escapingã®æµããã¤ãããããªã¨äºæ³ã
ã¡ãªã¿ã«templateã§å©ç¨ã§ããå¤æ°$sf_dataã¯sfOutputEscaperArrayDecoratorã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¿ããã§ããã
çå
ããã£ã¦ãå
¥åããã¦ã¼ã¶èªèº«ãæ»æã®è¢«å®³ãåããã£ã½ããã©ãèªåã§èªåãæ»æãããªãã¦ãã¨ã¯ãªãã¯ãã
ã ã¨ããããå®éã®æ»æãè¡ãããã·ãã¥ã¨ã¼ã·ã§ã³ã£ã¦ã©ããªæããªãã ããï¼
ã±ã£ã¨æãã¤ããã®ã¯ã該å½ç®æãGETã®å¤ã使ã£ã¦ããªãããããã«ãã¼ã¿ã®ã¤ããURLãè¸ã¾ããã°ãèªå以å¤ã®äººãã¿ã¼ã²ããã«ã§ããããªã¼ãã¨ãã£ãæãã
æå¤ã¨XSSã«ã¤ãã¦èª¿ã¹ãã ãã§æéãããã£ã¦ãã¾ã£ãã®ã§ãCSRFã«ã¤ãã¦ã¯ãã¨ã§ã¾ã¨ãããã¨æãã¾ãã
ãªãã¨ãªãã¾ã¨ãã¦ã¿ã¦ã
ãã¬ã¼ã ã¯ã¼ã¯ã«ä»»ãã£ãããããªãã¦ãå ¨ä½ãææ¡ããä¸ã§ããã¬ã¼ã ã¯ã¼ã¯ã§ãªã«å¯¾çãâã©ããããµãã«âãã¦ããã¦ã¦ãä½ã¯ãã¦ãªãã®ãããã¡ãã¨ææ¡ãã
ã®ã大äºã£ã½ããªãã¨ããçµè«ã«ã
ã¾ã ã¾ã ã»ãã¥ãªãã£ã«é¢ããç¥èã¯è¶³ããªãã®ã§ã¢ã¬ã§ãããã¼ã¡ã¼ã¡åå¼·ãã¦ãããªãã¨ãªãã
*1:http://www.symfony-project.org/jobeet/1_4/Propel/ja/
*2:PHP5åãã®ã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯
*3:http://www.symfony-project.org/jobeet/1_4/Propel/ja/01
*4:http://ja.wikipedia.org/wiki/XSS
*5:ããµãã¿ã¤ãºè¨ããªãã¦ã®ãããããããhttp://takagi-hiromitsu.jp/diary/20051227.html#p02
*6:http://www.asahi-net.or.jp/~wv7y-kmr/memo/php_security.html
*7:ã·ã³ã°ã«ã¯ã©ã¼ãã¼ã·ã§ã³ãå¤æãã