我的 sql 查询是否容易受到 sql 注入或其他攻击
我在使用 playframework 开发的 Web 应用程序的视图中使用了一些 sql 语句。我有以下 java 函数
public static void search(String word){
String trimword = word.trim();
String pattern = "%"+trimword+"%";
String query="select distinct item from Item item where item.name like :pattern";
List<Item> items = Item.find(query).bind("pattern", pattern).fetch();
...
}
“word”是用户通过网页表单中的文本输入字段输入的字符串。上面的内容是否会被滥用一个邪恶的人对我的数据库做了令人讨厌的事情?我尝试了用户输入的各种组合,例如 'SomeItem 或 '1'='1'
等,但没有发生任何意外的事情..但是我对 sql 的了解很少..如果有人能指出找出其中的任何漏洞并提出改进/保障措施,这会很有帮助
I was using some sql statements in views in a web app developed using playframework.I have the following java function
public static void search(String word){
String trimword = word.trim();
String pattern = "%"+trimword+"%";
String query="select distinct item from Item item where item.name like :pattern";
List<Item> items = Item.find(query).bind("pattern", pattern).fetch();
...
}
The 'word' is a string entered by user through a text input field in a web page form..Can the above be misused by an evil person to do nasty things to my db?I tried various combinations of user input like 'SomeItem or '1'='1'
etc but nothing unexpected happened..But my knowledge of sql is minimal ..If anyone can point out any vulnerabilities in this and suggest improvements/safeguards ,it would be helpful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.bind("pattern",pattern)
可防止 SQL 注入攻击。因此,您的查询不容易受到 SQL 注入攻击。此外,附加
%
值的代码与用户输入%
类似。bind()
方法将以相同的方式处理这两者。The
.bind("pattern", pattern)
prevents SQL Injection attacks. Thus your query is not prone to an SQL Injection attack.Also, your code appending the
%
values is similar to a user entering the%
. Thebind()
method will handle both the same way.您的查询不容易出现 sql 注入。作为一般规则,对除表名和列名之外的所有内容都使用绑定变量,而表名和列名不能使用绑定变量。
所以,vunerable
不可能,
好吧
编辑@JNK,你必须假设我已经正确编码了oracle连接,因为execute()运行了大约80行。
Your query is not prone to sql injection. As a general rule use bind variables on everything but table names and column names, which you can't use bind variables for.
So, vunerable
impossible,
okay
EDIT @JNK, you'll have to assume that I've coded the oracle connections correctly as execute() runs to about 80 lines.