gpt4 book ai didi

mysql - nodejs MYSQL 中的 mysql.format 是否不受未转义输入的影响?

转载 作者:搜寻专家 更新时间:2023-10-30 23:28:15 25 4
gpt4 key购买 nike

我听说准备 MySQL 查询可以防止注入(inject)。我正在使用 nodejs,所以我找到了 MySql Preparing Queries .根据文档,

You can use mysql.format to prepare a query with multiple insertion points, utilizing the proper escaping for ids and values.

这是否意味着我可以将未转义的内容放入 userId 并获得名为 sql 的转义 mysql 请求?

代码是:

var sql = "SELECT * FROM ?? WHERE ?? = ?";
var inserts = ['users', 'id', userId];
sql = mysql.format(sql, inserts);

最佳答案

这是安全的。

转义由 sqlstring 执行模块,您可以查看其源代码以获取更多信息,它相当小。

您应该始终转义您的值,使用 ? 占位符或直接调用 escape。但是,更推荐使用占位符,因为它可以保护您免受可能忘记进行手动转义的情况的影响。

关于mysql - nodejs MYSQL 中的 mysql.format 是否不受未转义输入的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53399686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com