ColdFusion 中带有 like 运算符的 cfqueryparam

发布于 2024-07-04 10:21:01 字数 372 浏览 6 评论 0 原文

我的任务是检查一些最近遭受相当严重的 SQL 注入攻击的 ColdFusion 站点。 基本上我的工作涉及添加 > 标记到所有内联 sql。 大多数情况下我已经把它记下来了,但是有人能告诉我如何将 cfqueryparam 与 LIKE 运算符一起使用吗?

如果我的查询如下所示:

select * from Foo where name like '%Bob%'

我的 > 应该是什么? 标签是什么样的?

I have been tasked with going through a number of ColdFusion sites that have recently been the subject of a rather nasty SQL Injection attack. Basically my work involves adding <cfqueryparam> tags to all of the inline sql. For the most part I've got it down, but can anybody tell me how to use cfqueryparam with the LIKE operator?

If my query looks like this:

select * from Foo where name like '%Bob%'

what should my <cfqueryparam> tag look like?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-07-11 10:21:01

@Joel,我必须不同意。

select a,b,c
from Foo
where name like <cfqueryparam cfsqltype="columnType" value="%#variables.someName#%" />
  1. 永远不要向某人建议他们应该“选择明星”。 形式不好! 甚至举个例子! (甚至是从问题中复制的!)

  2. 查询是预编译的,您应该包含通配符作为传递给查询的参数的一部分。 此格式更具可读性并且运行效率更高。

  3. 进行字符串连接时,请使用与运算符 (&),而不是加号。 从技术上讲,在大多数情况下, plus 都可以正常工作......直到您在字符串中间抛出 NumberFormat() 并开始想知道为什么在检查时被告知您没有传递有效数字

@Joel, I have to disagree.

select a,b,c
from Foo
where name like <cfqueryparam cfsqltype="columnType" value="%#variables.someName#%" />
  1. Never suggest to someone that they should "select star." Bad form! Even for an example! (Even copied from the question!)

  2. The query is pre-compiled and you should include the wild card character(s) as part of the parameter being passed to the query. This format is more readable and will run more efficiently.

  3. When doing string concatenation, use the ampersand operator (&), not the plus sign. Technically, in most cases, plus will work just fine... until you throw a NumberFormat() in the middle of the string and start wondering why you're being told that you're not passing a valid number when you've checked and you are.

仙女 2024-07-11 10:21:01
select a,b,c
from  Foo
where name like  <cfqueryparam cfsqltype="cf_sql_varchar" value="%Bob%" />;
select a,b,c
from  Foo
where name like  <cfqueryparam cfsqltype="cf_sql_varchar" value="%Bob%" />;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文