NodeJS sql注入漏洞审计和修复

一、问题代码
1 | async search( |
二、黑盒测试过程:
/api/search?name=123’
{“success”:false,”errormsg”:”er_parse_error: you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near ‘Ͽor tag_name like ‘3’Ͽn order by gmt_modified desc \n limit’ at line 18”}
/api/search?name=123’’
{“success”:true,”data”:[]}
/api/search?name=123'and’’=‘
{“success”:true,”data”:[]}
/api/search?name='and if(1=1,exp(999),3)and'1
{“success”:false,”errormsg”:”er_data_out_of_range: double value is out of range in ‘exp(999)’”}
/api/search?name='and if(1=2,exp(999),3)and'1
{“success”:true,”data”:[{“id”:82,……}]}
三、修复方案
- mysql.escapeId(identifier)、connection.escapeId(identifier) 或 pool.escapeId(identifier)
1 | var sorter = 'date'; |
1 | var sorter = 'date'; |
- reparing Queries
1 | var sql = "SELECT * FROM ?? WHERE ?? = ?"; |
- Custom format
1 | connection.config.queryFormat = function (query, values) { |
参考: https://github.com/mysqljs/mysql#escaping-query-identifiers
- Post title:NodeJS sql注入漏洞审计和修复
- Post author:langu_xyz
- Create time:2019-05-01 21:00:00
- Post link:https://blog.langu.xyz/NodeJS sql注入漏洞审计和修复/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.