我有一个控制器,它从 HTML 表单中获取 post 参数,然后将它们发送到模型,该模型将数组插入到 Cassandra 数据库中。
它是 SQLInjection 证明,因为它是 NoSQL,但是我担心用户可以模拟 100k post 参数,或者只是添加一些我不需要的参数,然后它将被插入到数据库中。我如何确保只有我需要的值才会保留在我的数组中。
Example:
$post = ['parent_id', 'type', 'title', 'body', 'tags']; // Good
$post = ['parent_id', 'type', 'title', 'body', 'tags', 'one', 'two', 'three'] // Bad
如何确保我的数组将取消设置不在其中的所有元素good例子?
通过将条目列入白名单,您do expect.
<?php
$post = array(
'parent_id' => 1,
'type' => 'foo',
'title' => 'bar',
'body' => 'foo bar',
'tags' => 'foo, bar',
'one' => 'foo',
'two' => 'bar',
'three' => 'qux'
);
$whitelist = array(
'parent_id',
'type',
'title',
'body',
'tags'
);
$filtered = array_intersect_key( $post, array_flip( $whitelist ) );
var_dump( $filtered );
无论如何,使用 Cassandra 作为数据存储当然不是不对您接收的数据进行验证的理由。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)