CakePHPã®é²å¾¡åã試ã1ãSQLã¤ã³ã¸ã§ã¯ã·ã§ã³ã
ãCakePHP 1.3.2ã
CakePHPã®ããã©ã«ãã®ç¶æ
ã§ãã©ãã¾ã§ã»ãã¥ãªãã£å¯¾çã
æ½ããã¦ããã®ããå®é¨ãã¾ãã
ãå®é¨æ¹æ³ã
ãããã°ã"2"ã«è¨å®ããäºæ³ãããæ»æã«ãã£ã¦ã©ã®ãããªSQLãçæãããã®ãã確èªãã¾ãã
ã/app/config/core.phpã
Configure::write('debug', 2);
1. SQLã¤ã³ã¸ã§ã¯ã·ã§ã³
ãå®é¨ç°å¢ã
ä¸è¨ã®3ã¤ã®ã¡ã½ããã«ã¤ãã¦ãCakePHPã®å¯¾å¿ãè¦ã¦ã¿ã¾ãã- read()
- find()
- findById()
viewã¢ã¯ã·ã§ã³ã¸æ¸¡ãã¦ã¼ã¶IDã®ãã©ã¡ã¼ã¿ã®å¾ã«æ»æç¨ã®
ãã³ã³ããã¼ã©ã
function view($id){
//ã1ã
$this->data = $this->User->read(null, $id);//ã2ã
$this->data = $this->User->find('first',
array('conditions'=>array('User.id'=>$id)
));//ã3ã
$this->data = $this->User->findById($id);
}
//â»å®éã«ã¯ãåæã§ã¯ãªãåå¥ã«å®è¡ãã¾ãã
SQLãç¶ãã¦è¨è¿°ãããã©ã¦ã¶ã§ã¢ã¯ã»ã¹ãã¦ã¿ã¾ãã
(ã'ãã¨ã¯ãã'ãã®æåå®ä½åç §ã§ã)
- example.com/users/view/12; select * from users;
- example.com/users/view/12;'select * from users;
- example.com/users/view/12;'select * from users;
ãçæãããSQLã
- ... WHERE `User`.`id` = '12;select * from users;'
- ... WHERE `User`.`id` = '12;\'select * from users;'
- ... WHERE `User`.`id` = '12;\'select * from users;'
readãfindãfindByIdãããããä¸è¨ã®æ»æä¾ã§çæããã
SQLã¯åãã§ããã
2. æ¯è¼æ¼ç®åã¤ã³ã¸ã§ã¯ã·ã§ã³
ãå®é¨ç°å¢ã
ä¸è¨ã®2ã¤ã®ã¡ã½ããã«ã¤ãã¦ãCakePHPã®å¯¾å¿ãè¦ã¦ã¿ã¾ãã- $form->input()
- $form->text()
ããã¹ãããã¯ã¹ã«æ»æç¨ã®æ¯è¼æ¼ç®åã¨ã¦ã¼ã¶æ
å ±(ãã®å ´åã¯
ã¡ã¼ã«ã¢ãã¬ã¹)ãè¨è¿°ãããã©ã¼ã éä¿¡ãã¦ã¿ã¾ãã
ãçæãããSQLã
- ... WHERE `User`.`mail` = '!= hoge@fuga.com'
- ... WHERE `User`.`mail` = '\'!= hoge@fuga.com'
- ... WHERE `User`.`mail` = ''!= hoge@fuga.com'
$form->input()ã$form->text()ãããããä¸è¨ã®æ»æä¾ã§çæããã
SQLã¯åãã§ããã
ææ³
CakePHP 1.1ã®é ã¯ãã»ãã¥ãªãã£ã®ããã«åæç¶æ ã«ã¡ãã£ã¨æãå ããå¿ è¦ãããã¾ãããã1.2以éã¯findã®æ§é ãå¤ãã£ãã®ã§
æéãçãã¦ä¾¿å©ã«ãªã£ãããã§ãã
次åã¯ãã¯ãã¹ãµã¤ãã¹ã¯ãªããã£ã³ã°(XSS)ã«ã¤ãã¦
å®é¨ãã¦ã¿ããã¨æãã¾ãã