简体   繁体   English

如何防止我的网站进行sql Injection? 支柱

[英]How to prevent my website from sql Injection? Struts

how to prevent my website from doing sql injection in it 如何防止我的网站在其中进行sql注入

I am working using Struts 2 , DB MY sql . 我正在使用Struts 2,DB MY sql。

The best way I think is to not re-invent the wheel and use the tools already available. 我认为最好的方法是不要重新发明轮子,而是使用已有的工具。 For a small project I would recommend to simply use prepared statements when querying your database. 对于小型项目,我建议在查询数据库时仅使用准备好的语句。

http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html

You could also look into using an ORM like Hybernate. 您还可以考虑使用像Hybernate这样的ORM。 But make sure to use it as intended. 但是请确保按预期使用它。 Even HQL can be susceptible to injection. 甚至HQL也可能容易注射。 See: how much safe from SQL-Injection if using hibernate 请参阅: 如果使用休眠模式,那么从SQL-Injection安全多少

The important thing is to not write your own native queries by concatenating query strings with values from untrusted sources. 重要的是不要通过将查询字符串与来自不受信任来源的值串联来编写自己的本机查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM