SameSiteæ»æè ãCodeIgniter4ã¨Shieldã§ã®CSRFä¿è·ãåé¿ã§ããèå¼±æ§ã®è§£èª¬
CodeIgniter4ã¨CodeIgniter Shieldã§ã®çµã¿åããã§ãCSRFä¿è·ãåé¿ã§ããèå¼±æ§ã«é¢ããã»ãã¥ãªãã£å§åã2022/08/08ã«å ¬è¡¨ããã¾ãããä»æ¥ã¯ããã®èå¼±æ§ã«ã¤ãã¦è§£èª¬ãã¦ããã¾ãã
ãªãããã®æ»ææ¹æ³ã¯CodeIgniterã«éå®ããããã®ã§ã¯ããã¾ããã
ä¿®æ£æ¸ã¿ã®ãã¼ã¸ã§ã³
- CodeIgniter 4.2.3
- CodeIgniter Shield 1.0.0-beta.2
åææ¡ä»¶
ãã®èå¼±æ§ãæ»æããã«ã¯ãæ»æè ãæ»æ対象ã®ãµã¤ãã¨åããã¡ã¤ã³ã®ãµããã¡ã¤ã³ãµã¤ããæ¯é ä¸ã«ç½®ãã¦ããå¿ è¦ãããã¾ãã
ç°¡åã«è¨ãã°ããµããã¡ã¤ã³ãµã¤ãã®ãã¼ã¸ãæ¸ãæããããã¨ãããã¨ã§ããããã¯ãã®ãµã¼ãã¼ãä¹ã£åã£ã¦ãããããã®ãµããã¡ã¤ã³ãµã¤ãã«XSSèå¼±æ§ã1ã¤ããã°OKã§ãã
ãã®ãããªæ»æè ããSameSiteæ»æè ãã¨å¼ãã§ãã¾ãã
æ»æè ã¯ãã®ãµããã¡ã¤ã³ãµã¤ãã使ããæ»æ対象ãã¡ã¤ã³ã®Cookieãçºè¡ãã¾ãã
æ»ææ¹æ³
ãã®èå¼±æ§ã¯ãCSRFä¿è·ãCookieãã¼ã¹ãSessionãã¼ã¹ãã«é¢ãããï¼Config\Security::$csrfProtection
ã 'cookie'
ã§ã 'session'
ã§ãï¼ã
ã¾ããCSRFãã¼ã¯ã³ãåçæãããå¦ãã«é¢ãããï¼Config\Security::$regenerate
ã true
ã§ã false
ã§ãï¼æ»æå¯è½ã§ãã
Cookieãã¼ã¹ã®CSRFä¿è·ã®å ´å
CodeIgniter3åã³CodeIgniter4ã¯ãããã©ã«ãã§ã¯ãCookieãã¼ã¹ã®CSRFä¿è·æ©è½ãæä¾ãã¾ãã
Cookieã«CSRFãã¼ã¯ã³ãã»ãããã¦ãPOSTãããCSRFãã¼ã¯ã³ã¨ä¸è´ããã°OKã¨ããå®è£ ã§ãã
ãã®å ´åãæ»æè ã¯æ¯é ä¸ã«ãããµããã¡ã¤ã³ãµã¤ãã使ãã被害è ã®ãã©ã¦ã¶ã«CSRFãã¼ã¯ã³ã®Cookieãã»ãããã¾ãã
ããã§æ»æè ã¯CSRFãã¼ã¯ã³ã®å¤ãç¥ã£ã¦ãã¾ãã®ã§ã被害è ã«åãå¤ãPOSTãããã°ãCSRFä¿è·ãçªç ´ã§ãã¾ãã
ããããCookieãã¼ã¹ã®CSRFä¿è·ã¯Cookieã®æ¹ç«ãã§ããªããã¨ãåæãªã®ã§ãæ»æè ãCookieãæ¸ãè¾¼ããå ´åã¯å®å ¨ã¨ã¯è¨ãã¾ããï¼CodeIgniter3ã®Securityã¯ã©ã¹ã®CSRF対çãææ¡ãã¦ãã åç §ï¼ã
Sessionãã¼ã¹ã®CSRFä¿è·ã®å ´å
CodeIgniter4ã§ã¯ãè¨å®ã«ããããå®å ¨ãªSessionãã¼ã¹ã®CSRFä¿è·æ©è½ã使ãã¾ãã
Sessionã«CSRFãã¼ã¯ã³ãã»ãããã¦ãPOSTãããCSRFãã¼ã¯ã³ã¨ä¸è´ããã°OKã¨ããå®è£ ã§ãã
ãã®å ´åãæ»æè ã¯æ¯é ä¸ã«ãããµããã¡ã¤ã³ãµã¤ãã使ãã被害è ã®ãã©ã¦ã¶ã«ã»ãã·ã§ã³Cookieãã»ãããã¾ãã ã»ãã·ã§ã³åºå®åæ»æã®ãã¯ããã¯ã§ãã
ãã®ç¶æ ã§è¢«å®³è ããµã¤ãã«ãã°ã¤ã³ããã¨ãã»ãã·ã§ã³IDãæ´æ°ãããã®ã§ãããå¤ãã»ãã·ã§ã³ãã¼ã¿ãæ®ã£ã¦ãã¾ããã
ããã§ããã°ã¤ã³ãã©ã¼ã ã«CSRFä¿è·ãããã¨ï¼ã°ãã¼ãã«ã«CSRFãã£ã«ã¿ãè¨å®ãã¦ããã°ãããªãã¾ãï¼ãå¤ãã»ãã·ã§ã³ã«ãCSRFãã¼ã¯ã³ãä¿åããã¦ãã¾ãã
ãã©ã¼ã æ稿æã«CSRFãã¼ã¯ã³ããã§ãã¯ãããOKãªããCSRFãã¼ã¯ã³ã®å¤ãæ´æ°ããã¾ãï¼ããã©ã«ãè¨å®ã®å ´åï¼ãããããå¤ãã»ãã·ã§ã³ã«ããæ´æ°ãããå¾ã®CSRFãã¼ã¯ã³ãä¿åããã¦ãã¾ããã
æ»æè ã¯ãå¤ãã»ãã·ã§ã³Cookieã§ãµã¤ãã«ã¢ã¯ã»ã¹ãããã¨ã§ãèªè¨¼åã®ã»ãã·ã§ã³ãä¹ã£åããã¨ãã§ããæ´æ°ãããCSRFãã¼ã¯ã³ã®å¤ãç¥ããã¨ãã§ãã¾ããã
ããã¯ãCSRFä¿è·ãã³ã³ããã¼ã©ãã£ã«ã¿ã§å®è£ ããã¦ããããã°ã¤ã³å¦çãããåã«å®è¡ãããCSRFãã¼ã¯ã³ãæ´æ°ãããããã§ãã
ãªããCSRFãã¼ã¯ã³ãåçæããªãè¨å®ã§ããã°ãCSRFãã¼ã¯ã³ã®å¤ã¯å¤æ´ããã¾ããã®ã§ãCSRFãã¼ã¯ã³ãä¿åããã¦ããã»ãã·ã§ã³ã®ã»ãã·ã§ã³Cookieã被害è ã®ãã©ã¦ã¶ã«ã»ããããã°æ»æå¯è½ã§ãã
対ç
対çã¨ãã¦ã¯ã以ä¸ã®3ã¤ãå ¨ã¦è¡ããã¨ã§ãã
- Sessionãã¼ã¹ã®CSRFä¿è·ãå©ç¨ãã
- ãã°ã¤ã³ç´å¾ã«ã»ãã·ã§ã³ãåçæããå¤ãã»ãã·ã§ã³ãã¼ã¿ãå¿ ãç ´æ£ãã
- ã»ãã·ã§ã³ãåçæããç´å¾ã«CSRFãã¼ã¯ã³ãå¿ ãåçæãã
Cookieãã¼ã¹ã®CSRFä¿è·ã«ã¤ãã¦
Cookieãã¼ã¹ã®CSRFä¿è·ãã©ããã¦ãå©ç¨ããããå¾ãªãå ´åã¯ãCSRFãã¼ã¯ã³ã®å¤ãã¦ã¼ã¶ã«ç´ä»ãããã¨ã§å¯¾çã¯ä¸å¯è½ã§ã¯ããã¾ãããã¦ã¼ã¶ãç¹å®ã§ããä½ããã®å¤ï¼ã»ãã·ã§ã³IDãã¢ã¯ã»ã¹ãã¼ã¯ã³ãªã©ï¼ããã¼ã«ãã¦æå·çã«CSRFãã¼ã¯ã³ãå°åºããä»ã®ã¦ã¼ã¶ã®ããã«ä½æãããCSRFãã¼ã¯ã³ãCookieã«å«ã¾ããå ´åã¯ã¨ã©ã¼ã«ãã¾ãã
ãããã ãã°ã¤ã³æ©è½ãªã©ã§ãã§ã«ã»ãã·ã§ã³ãå©ç¨ãã¦ããç¶æ³ã§Cookieãã¼ã¹ã®CSRFä¿è·ã使ãçç±ã¯ããã¾ããã
ãªããCookieã«ä¿åããCSRFãã¼ã¯ã³ã®å¤ãæå·åããã ãã§ã¯å¯¾çã«ãªãã¾ãããæ»æè ãæ»æ対象ãµã¤ãã«ã¢ã¯ã»ã¹ãã¦æå·åãããæ£è¦ã®CSRFãã¼ã¯ã³ã®å¤ãCookieããåå¾ããã°ããã ãã§ãã
åè
Date: 2022/08/16