Scale-of-evaluation / daily-question

This repo is used to help you better understand the world,Enjoy!
MIT License
4 stars 2 forks source link

【09.07】什么是SQL注入,如何防止SQL注入? #277

Open Derek-94tm opened 2 years ago

Derek-94tm commented 2 years ago

请在下方作答。

changjl317 commented 2 years ago

所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。 如何防止: 1、采用PreparedStatement来避免sql注入,会自动对用户填写的数据进行验证(简单有效) sql注入只对sql语句的准备(编译)过程有破坏作用 而PreparedStatement已经准备好了,执行阶段只是把输入串作为数据处理, 而不再对sql语句进行解析,准备,因此也就避免了sql注入问题. 2、使用正则表达式过滤传入的参数(典型的SQL 注入攻击的正则表达式 ) 3、字符串过滤,敏感词过滤