Heim  >  Artikel  >  Backend-Entwicklung  >  开发一个简单的PHP框架,有哪些安全问题需要注意?

开发一个简单的PHP框架,有哪些安全问题需要注意?

WBOY
WBOYOriginal
2016-06-06 20:28:321221Durchsuche

自认为,做一个最简单的PHP mvc框架,用URL路由函数匹配URL中的controller和method的名字,如果method_exists则new该controller再用call_user_func_array执行该method,否则引入error的controller,每个controller中可以require引入model,再require引入tpl,这是我做一个最简单的PHP框架的思路,那这里面需要注意哪些安全问题呢?

回复内容:

自认为,做一个最简单的PHP mvc框架,用URL路由函数匹配URL中的controller和method的名字,如果method_exists则new该controller再用call_user_func_array执行该method,否则引入error的controller,每个controller中可以require引入model,再require引入tpl,这是我做一个最简单的PHP框架的思路,那这里面需要注意哪些安全问题呢?

  • 路径问题,不能通过url调用应用外部文件比如/etc/passwd

  • 数据过滤,永远不要信任用户的任何输入。输入的所有数据使用htmlspecialchars过滤后入库。

  • 数据库,使用PDO代替mysql_xxxx,使用参数绑定处理外部数据(如果数据库只使用mysql也可使用mysqli扩展)

关于 call_user_func_array 的安全问题,之前drupal中过招。

http://blog.knownsec.com/2014/10/drupal__callback_nightmare/

require 可能产生文件包含漏洞。

http://www.neatstudio.com/show-1123-1.shtml

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn