加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

什么时候在CakePHP中进行消毒

发布时间:2020-12-13 13:03:52 所属栏目:PHP教程 来源:网络整理
导读:我从食谱中读到(第4.2节) CakePHP already protects you against SQL Injection if you use CakePHP’s ORM methods (such as find() and save()) and proper array notation (ie. array(‘field’ = $value)) instead of raw SQL. For sanitization against
我从食谱中读到(第4.2节)

CakePHP already protects you against SQL Injection if you use CakePHP’s ORM methods (such as find() and save()) and proper array notation (ie. array(‘field’ => $value)) instead of raw SQL. For sanitization against XSS its generally better to save raw HTML in database without modification and sanitize at the time of output/display.

那么我们是否确定我们不需要针对SQL手动清理用户数据,前提是我们限制使用find()和save()等方法?特别是,如果我直接从$_POST获取数据而不是从$this->数据获取数据,这是真的吗?换句话说,假设我使用$this->数据进行find()查询.然后CakePHP在编写数组$this->数据时或在为find()编写查询时对SQL进行清理?

我的第二个问题是清理要显示的数据.是Sanitize :: html幂等吗?那么,我可以在我的beforeSave()方法中使用它,还是会在第二次保存时中断,因为它再次应用并提供新的结果?

关于这个问题:

CakePHP sanitize against SQL when writing the array $this->data or when writing the query for find()?

Cakephp不会清理控制器中的$this->数据,如果检查蛋糕代码,在Dispatcher :: parseParams()http://api13.cakephp.org/view_source/dispatcher/#line-244中,您会看到当$_POST被复制到控制器数据时,值不会被清理.

但是,建议不要使用$_POST,因为在使用表单助手时,您将失去所有蛋糕的魔力

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读