gpt4 book ai didi

javascript - knex.where容易受到sql注入(inject)攻击吗?

转载 作者:行者123 更新时间:2023-12-03 06:56:34 26 4
gpt4 key购买 nike

这是 https://stackoverflow.com/a/50337990/1370984 的后续问题.

它提到knex('table').where('description', 'like', '%${term}%')因为容易受到sql注入(inject)攻击。甚至有评论提到第一种情况容易受到注入(inject)攻击。然而,提供的引用资料从未提及 .where容易受到注入(inject)攻击。

这是一个错误吗?为什么 knex 允许 .where容易受到注入(inject)攻击但不是.whereRaw('description like \'%??%\'', [term]) .在这两种情况下,参数不是都被参数化了吗?

最佳答案

This is a follow up question to https://stackoverflow.com/a/50337990/1370984 .

It mentions knex('table').where('description', 'like', '%${term}%') as prone to sql injection attacks. Even a comment mentions the first case as prone to injection attacks. Yet the reference provided never mentions .where being prone to injection attacks.



我是 knex 维护者,我在那里评论说
knex('table').where('description', 'like', `%${term}%`)

不易受到 SQL 注入(inject)攻击。

Is this a mistake? Why would knex allow .where to be prone to injection attacks but not .whereRaw('description like \'%??%\'', [term]) . Aren't the arguments being parameterized in both cases?



.whereRaw当您将值直接插入到 sql 字符串时很容易受到攻击(例如 ?? 标识符替换)。

正确使用 .whereRaw在这种情况下,例如:
.whereRaw("?? like '%' || ? || '%'", ['description', term])

正确引用所有标识符和 term作为参数绑定(bind)发送到数据库。

因此,答案和添加到该答案的大多数评论都是完全错误的。

关于javascript - knex.where容易受到sql注入(inject)攻击吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59654157/

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