0

嗨,我有这个基于 ZEND 框架的 Web 应用程序的小代码片段,它不安全,因为“名称”是从发布请求中获取的。是否有标准的 ZEND 方法来防止 $data 中出现特殊符号?就像 $where 有quoteInto。

$name = $this->_request->getParam('name');

// update query
$data = array(
    'name' => $name
);
$where = array(
    $users->getDbAdapter()->quoteInto('user_id = ?', $userId),
);
$users->update($data, $where);
4

2 回答 2

1

这对于 SQL 注入是安全的。Zend_Db将您传递给update()的数组视为命名参数的数组,因此这些值会自动转义。

于 2012-11-29T09:30:21.440 回答
0

如果有点简洁的话,蒂姆是正确的。:)

Zend_Db 中更新语句中的 $data 数组被分解为绑定参数。您可以在 中找到确切的代码Zend_Db_Adapter_Abstract

涉及许多过程,但数组最终在此语句中结束。

$set[] = $this->quoteIdentifier($col, true) . ' = ' . $val;

你的原始数组在哪里$col => $val

然后创建 SQL:

    $sql = "UPDATE "
         . $this->quoteIdentifier($table, true)
         . ' SET ' . implode(', ', $set)
         . (($where) ? " WHERE $where" : '');

它看起来对 SQL 注入相当安全。

但是,您始终可以使用Zend_Filter_InputZend_Validate真正Zend_Filter清理您的输入值。

于 2012-11-29T10:18:52.190 回答