zend framework sanitizing data

馋奶兔 提交于 2019-12-07 17:03:54

问题


I've seen different comments all over the place, some say that zend framework automatically sanitizes post/get data but others say it doesn't.

What's the deal? I've seen that doing it in the predispatch with a foreach on getParams is the quickest way, but does anyone have any suggestions?


回答1:


Probably the deal is about Zend_Controller_Request vs the Zend_Db. Request data are often put into the DB.

Request object does not escape anything. You may force it to do using filters, form filters or e.g. using the reflection technique described here:

  • Actions, now with parameters!

Zend_Db queries are basically escaped like in other ORM's, like in PDO.




回答2:


It does not automatically sanitize any request data. It cannot, because that requires it to know how to sanitize it, e.g. should $_GET['foo'] be string sanitized or for numbers? You have to tell it.

Whether you sanitize input manually in the respective Controller Actions or in an ActionHelper or automatically in a Controller Plugin or during bootstrap or with a mixture of these is up to you.

Use what is appropriate.




回答3:


It definitely doesn't automatically sanitise your variables for you. You could do something like foreach or use array_map depending on the context, for example:

$_POST = array_map('mysql_real_escape_string', $_POST);

Ideally though you should treat each variable on a case by case basis. Personally i make a lot of use of PHP's filter_var for filtering and sanitizing.



来源:https://stackoverflow.com/questions/4086852/zend-framework-sanitizing-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!