Piece Frameworkã¯PHPã®ãã¬ã¼ã ã¯ã¼ã¯ã§ãã
ã»ãã¥ãªãã£ã«å¼·ããããã¦æ¥æ¬äººãéçºãã¦ãããã¨ããã®ãç¹å¾´ã®ããã§ãã
【PHPウォッチ】第34回 セキュアでロバストなPHPフレームワーク「Piece Framework」:ITPro
Piece Framework - A stateful and secure web application framework for PHP
æ©é触ã£ã¦ã¿ã¾ããã
æ¦è¦
以ä¸ã®3ã¤ã®è¦ç´ ããæ§æããã¾ãã
- Piece_Unity: åºæ¬
- Piece_Right: Validation
- Piece_Flow: ããã¼å¶å¾¡
ä¸çªã®å£²ãã¯ãããã¼å¶å¾¡ã®ããã§ããããã使ãã¨ãWebã¢ããªéçºè ãæèããã¨ããCSRFèå¼±æ§ãæããªããã©ã¼ã ãä½ãã¾ãã
ãã¢ãµã¤ãã§ããã¼å¶å¾¡ãä½é¨
ãã¢ãµã¤ããç¨æããã¦ãã¾ãã
Piece Framework Questionnaire Example
PieceFrameworkによるシンプルなWeb開発 - Piece Framework Documentation - Trac(デモの解説)
ãã¢ã§ã¯ãå ¥åç»é¢①ãå ¥åç»é¢②ãå ¥åç»é¢③ã確èªç»é¢ãå®äºç»é¢ã¨ãã5ã¤ã®ç»é¢ã§æ§æããããã©ã¼ã ãä½é¨ã§ãã¾ãï¼画面遷移図はこちらï¼ã
ãã¢ãµã¤ãã®åã
åºæ¬æ¹å¼ã¨ãã¦ã高木浩光@自宅の日記 CSRF対策に「ワンタイムトークン」方式を推奨しない理由ã®å³5ãæ¡ç¨ãã¦ããã¨ã®ãã¨ã§ãã
以ä¸ã«ãã¢ãµã¤ãã§ã®åä½ã®æ¦ç¥ã説æãã¾ãã
ã¾ããå ¥åç»é¢①ã«ã¢ã¯ã»ã¹ããã¨ãã»ãã·ã§ã³ID Cookieãçºè¡ããã¾ããç»é¢ã«ã¯ãæ°åã¨Eã¡ã¼ã«ã¢ãã¬ã¹ãå ¥åãããã©ã¼ã ã表示ããã¾ãããã®ãã©ã¼ã ã®hiddenã«ã_flowExecutionTicketãã¨ãããããã¼å®è¡ãã±ããããåãè¾¼ã¾ãã¦ãã¾ãã
ãã®ããã¼å®è¡ãã±ããããé«æ¨ããæ¹å¼ã®ãwinidãã«ç¸å½ãã¾ãã
ãã®ãã±ããã¯ããµã¼ãå´ã§ã»ãã·ã§ã³IDã¨ãã¢ä»ãããã¦ãã¾ãããã±ããã¯POST/GETã§ç»é¢éã§å¼ãåããã¾ããåç»é¢ã§ã¦ã¼ã¶ãå ¥åããå¤ã¯ããã±ããã«ãã¢ä»ãã¦ãµã¼ãå´ã®ã»ãã·ã§ã³é åã«ä¿åããã¾ãã
ã¾ãããµã¼ãå´ã§ãã±ããã«ãã¢ä»ãã¦ãã©ãã®ç»é¢ã¾ã§é²ãã ã®ãã®ã¹ãã¼ã¿ã¹ãä¿æãã¦ãã¾ããã¹ãã¼ã¿ã¹ããã§ãã¯ãããã¨ã«ããããããªãå ¥åç»é¢①ããå®äºç»é¢ã«çªãé²ããããªæ»æãé²ãã¾ãã
ããã¼å®è¡ãã±ããã§ã§ãããã¨
ãã±ããã使ããã¨ã§ã以ä¸ã®ãããªå¹æãå¾ããã¾ãã
- ããã¼å¶å¾¡
éä¸ã®ç»é¢ã®è·³ã³è¶ããªã©ãé²ãã - hiddenå¤ã®æ¹ç«é²æ¢
ã¦ã¼ã¶ããã©ã¼ã ã§å ¥åããå¤ã¯ãå¤ã®æ¤è¨¼å¾ã«ãµã¼ãå´ã§ä¿æããããããæ¹ç«ã§ããªãã - CSRFé²æ¢
ãã±ããå¤ã¯äºæ¸¬å°é£ã§ãããããCSRF対çã«ãªãã - äºééä¿¡é²æ¢
ãã±ããã®ã¹ãã¼ã¿ã¹ç®¡çã«ãããã¯ã³ã¿ã¤ã æ§ãæãããããã
è¤æ°ã¦ã£ã³ãã¦ã®åæèµ·åæã®åé¡
ããã§ã¯ãè¤æ°ã¦ã£ã³ãã¦ã®åæèµ·åæã®æåã«ã¤ãã¦æ¸ãã¾ãã
Piece Frameworkã®æ¹å¼ã¯ãè¤æ°ã¦ã£ã³ãã¦åæèµ·åã«å¯¾å¿ãã¦ãã¾ãããã ãããã¯ãè¤æ°ã®ã¦ã£ã³ãã¦ããããããç°ãªãå¤ã®ãã±ãããæ±ãã¦ããå ´åã ãã§ãã
åé¡ãªã®ã¯ãåä¸ã®å¤ã®ãã±ãããæã¤è¤æ°ã®ã¦ã£ã³ãã¦ãèµ·åãããå ´åã§ããåé¡ã¨ãã£ã¦ããã®ã¯ãCSRFã«èå¼±ã¨ãããããªé¡ã®ãã®ã§ã¯ãªããã¦ã¼ã¶æä½ã«ãã£ã¦ã¯ãã¼ã¿ã®æ´åæ§ãç¶æã§ããªããªãã¨ãããã¨ã§ãã
ä¾ãã°ããã¢ã¢ããªã§ã®ç¢ºèªç»é¢ã¯ä»¥ä¸ã®ãããªãã®ã§ãã
ãã®ç»é¢ã§ããForm1ã«æ»ãããªã³ã¯ãªã©ããå¥ã¦ã£ã³ãã¦ã§éããå ´åãåããã±ããã®ã¦ã£ã³ãã¦ãè¤æ°åºæ¥ã¦ãã¾ãã¾ãã
ããã§ãæ°ããã¦ã£ã³ãã¦å´ã§æ§å¥ãã女æ§ããããç·æ§ãã«ä¿®æ£ããæä½ãè¡ãªãã確èªç»é¢ã¾ã§æ¥ãã¨ãã¾ãã
ãã®ç¶æ ã§ãæ§ã¦ã£ã³ãã¦å´ã®ãåçããããªã³ã¯ãæ¼ä¸ããå ´åãæ§ã¦ã£ã³ãã¦ã®ç¢ºèªç»é¢ã«è¡¨ç¤ºããã¦ããæ å ±ï¼å¥³æ§ï¼ã§ã¯ãªããæ°ã¦ã£ã³ãã¦ã®æ å ±ï¼ç·æ§ï¼ãDBãªã©ã«ç»é²ããã¦ãã¾ãã¾ãã
ããã¯ã¦ã¼ã¶ã®æå³ã«åããç¾è±¡ã¨è¨ãã¾ãããéãæ±ããããªãã©ã¼ã ã§ããã°ããã®ãããªä¸æ´åã¯è¨±å®¹ã§ããªãã¨æããã¾ãã
è¤æ°ã¦ã£ã³ãã¦åé¡ã®è§£æ±ºç
ä¸ã¤ã®åé¡ã¯ãä¸è¨ã®ç¢ºèªç»é¢ã«ããã¦ãå ¥åç»é¢①ã③ã«æ»ãã¢ã¯ã·ã§ã³ããªã³ã¯ã§è¡ãªã£ã¦ãããã¨ã§ãããªã³ã¯ã§ã¯ãªããã¿ã³ã使ãã¨ãIEãFirefoxã§ã¯å¥ã¦ã£ã³ãã¦ãèµ·åã§ããªããªãã¾ã*1ã
ãããããã¨ããã¿ã³ã使ã£ãã¨ãã¦ããã¦ã¼ã¶ããããã¨æãã°ãåä¸ã®ãã±ãããæã¤è¤æ°ã®ã¦ã£ã³ãã¦ãèµ·åã§ãã¦ãã¾ãã¾ããç¹ã«Operaã§ã¯ç°¡åã«ã¦ã£ã³ãã¦ã®ã¯ãã¼ã³ãä½ãã¾ãã
ã¤ã¾ãããã®ç¨®ã®ä¸æ´ååé¡ã«ã¯ããªã³ã¯ããã¿ã³ã«ãããã¨ãã§ã¯ãªããæ ¹æ¬çãªå¯¾å¦ãå¿ è¦ã ã¨æãã¾ãã
ããã¤ãèãããã対å¦æ¹æ³ã以ä¸ã«æ¸ãã¾ãã
hiddenã§å ¨é¨ã®æ å ±ãå¼ãåã
ä¸çªç°¡åãªã®ã¯ãããã¼å®è¡ãã±ããã ãã§ã¯ãªããã¦ã¼ã¶ããã©ã¼ã ã«å ¥åããæ å ±ãä¸ç·ã«hiddenã§å¼ãåãæ¹æ³ã§ãã
æ å ±ãDBãªã©ã«ç»é²ããæçµæ®µéã§ããµã¼ãå´ã®ã»ãã·ã§ã³é åã«ä¿åããã¦ããæ å ±ã¨ãhiddenããéãããæ å ±ãä¸è´ããªãå ´åã¯ã¨ã©ã¼ã¨ãã¾ãã
ãã±ããã®å¤ãé½åº¦å¤æ´ãã
ããä¸ã¤ã®è§£æ±ºçã¯ããã±ããã«ãã¢ä»ãã¦ã»ãã·ã§ã³é åã«ä¿åãããæ å ±ã«ãä½ããã®å¤æ´ãå ããããã¿ã¤ãã³ã°ã§ãããã¼å®è¡ãã±ããã®å¤ãå¤æ´ããæ¹æ³ã§ãã
ããããã¨ãæ°ã¦ã£ã³ãã¦å´ã®æä½ã§æ§å¥ãå¤æ´ããéã«ãæ°ã¦ã£ã³ãã¦ã®ãã±ããã®å¤ããæ§ã¦ã£ã³ãã¦ã®ããã¨ã¯ç°ãªãå¤ã«å¤åãã¾ããããã«ãããæ§å¥å¤æ´å¾ã¯æ°ã»æ§ã®ã¦ã£ã³ãã¦ãåºå¥ã§ããããã«ãªãã¾ãã
ãã®æ¹æ³ã§ã¯ããã±ããã®å¤ãå¤æ´ããéã«ãå¤æ´åã®ãã±ããã¨ããã«ãã¢ä»ãæ å ±ããµã¼ãå´ããæ¶å»ããå®è£ ã¨ãæ¶å»ããæ®ãå®è£ ã®2éããèãããã¾ãã
æ¶å»ããå®è£ ã®å ´åãæ§ã¦ã£ã³ãã¦ã®ãåçããããªã³ã¯ãæ¼ä¸ãããéã«ãã¨ã©ã¼ã¨ããããå¾ã¾ããããã©ã¦ã¶ããéä¿¡ããããã±ããã¯ããµã¼ãã«ã¨ã£ã¦ã¯æ¶å»æ¸ã¿ï¼è¦ç¥ãã¬ãã±ããã§ããããã§ããåããããªçç±ã§ããã©ã¦ã¶ã®æ»ã/ãªãã¼ããªã©ã®ãã¿ã³ã®æ©è½ã«å¶ç´ãçãã¾ãã
ä¸æ¹ãæ¶å»ããªãå®è£ ã§ã¯ãä¸è¨ã®ãããªåé¡ã¯çãã¾ãããæ°ã»æ§ã®ã¦ã£ã³ãã¦ã¨ãã«æ£å¸¸ã«æ©è½ããããã¨ãã§ãã¾ããããããã¦ã¼ã¶ã®æä½æ¯ã«ãµã¼ãå´ã®ã»ãã·ã§ã³é åå ã®ãã¼ã¿éãå¢ãã¦ããåé¡ãããã¾ãã
ãªããã±ããã®å¤ãã第ä¸è ãäºæ¸¬å°é£ãªå¤ã«å¤æ´ããã¨ãã»ãã·ã§ã³IDã¨ããã¼å®è¡ãã±ããã第ä¸è ããåºå®ãããã¿ã¤ãã®æ»æã¸ã®èæ§ãã§ãã¾ãã
ãµããã±ããã使ã
ãã±ããã®å¤ãå¤åãããæ¹æ³ã®å¤ç¨®ã§ããããã¼å®è¡ãã±ããã«å ãã¦ãããµããã±ããããhiddenã«åãè¾¼ã¿ãã¦ã¼ã¶ã®æä½æ¯ã«ãµããã±ããã®å¤ãå¤åããã¾ãã
ãµããã±ããã¯ããµã¼ãå´ã®ã»ãã·ã§ã³é åã«ä¿åããããã©ã¼ã å ¥åã®æ å ±ã®ãä¸ä»£ãã示ãæ å ±ã ã¨è¨ãã¾ãã
æå¾ã«
HTTPã®ä¸çã§ã¯ããã©ã¼ã å¦çã²ã¨ã¤ã¨ã£ã¦ãç°¡åãªããã§é£ããã§ããåã ã®ã¢ããªéçºè ããã¡ãã¡å ±éçãªå¦çãä½ãã®ã¯ä¸å¹çã§ããããããæå³ã§ããã®æã®ããã¼å¶å¾¡æ©è½ã¯ããã¬ã¼ã ã¯ã¼ã¯ãæã£ã¦ãã¦æ¬²ãããã®ã ã¨æãã¾ãã
æå¾ã«ãPiece Frameworkã«ã¤ãã¦ä½ç¹ãã
- ããã¥ã¡ã³ããå
å®
ãµã¤ããè¦ã¦ãããã¥ã¡ã³ããæ®ã©ããã¾ãããã½ã¼ã¹ã³ã¼ãã®ã³ã¡ã³ãéãå°ãªãã§ããä»å¾å¢ããã¦æ¬²ãããªã¨æãã¾ãã - è¤æ°ã¦ã£ã³ãã¦ã«å¯¾å¿
ä¸è¨ããè¤æ°ã¦ã£ã³ãã¦ã®å¶å¾¡ãå¯è½ã ã¨ããã¨æãã¾ãããããã¼å¶å¾¡ãã売ãã«ãããªãã°ãå¾¹åºçã«ãã£ã¦æ¬²ãããªã¨æãã¾ããã
ãªããã©ã¼ã ã®å¦çã«ã¤ãã¦ã¯ãææï¼よりセキュアなWebサイト構築の8章ï¼ã«ãæ¸ãã¦ãã¾ããèå³ã®ããæ¹ã¯æ¯éãä¸èªãã
ï¼2007/04/30 02:00, 14:00 å çä¿®æ£ï¼
*1:ãªã³ã¯ã§é·ç§»ããå ´åãURLã®ã¯ã¨ãªã¹ããªã³ã°ã«ãã±ãããå«ã¾ããããããªãã¡ã©ã¼ãããã±ãããæ¼ããã¨ããå¥ã®åé¡ãçããã¾ãã