ActiveRecord/nHibernate SQL 生成“安全”吗?
我正在做这个系统 Stacked 并且我正在创建搜索功能。 在这个过程中,我突然想到 AR/nHibernate Expression.Like(以及兄弟姐妹)可能不是 100%“安全”,因为您可以创建类似的东西; “\r\ndrop database xxx;---”和类似的东西......?
我希望他们是安全的,但我不确定......
I'm doing this system Stacked and I am creating the search function. And in that process it occurs to me that maybe AR/nHibernate Expression.Like (and siblings) might maybe not be 100% "safe" in that you can create stuff like;
"\r\ndrop database xxx;---" and similar things...?
I would expect them to be safe, but I am not sure...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NHibernate(以及扩展的 ActiveRecord)生成形如
sp_executesql 'select blah from table where column = @p1', '@p1 varchar(10)', @p1 = 'drop database xxx;--- 的参数化 SQL 语句'
用于查询。 这些类型的 SQL 语句可以安全地避免 SQL 注入,因为参数的内容不会被执行(与使用简单串联时的情况不同)。所以是的,两者都是“安全的”。
NHibernate (and by extension ActiveRecord) generate parameterized SQL statements of the form
sp_executesql 'select blah from table where column = @p1', '@p1 varchar(10)', @p1 = 'drop database xxx;---'
for queries. These types of SQL statements are safe from SQL injection because the contents of the parameters are not executed (unlike they would be if simple concatenation was used).So yes, both are "safe".
如果您发现安全错误,您一定应该将其归档。 许多人依赖这些东西。
If you find a security bug, you should definitely file it. Many rely on such things.