在使用 XPath.compile 进行静态代码分析时,Sonar 会引发严重问题
已使用 common-langs.StringUtils.escapeXml 来验证输入字符串
但是 Sonar 还是一样显示
XPathExpression nodePathExpression = xpath.compile(nodeName);
除了将输入字符串列入白名单之外,还有什么方法可以解决 Sonar 问题吗?
最佳答案
sonarqube 问题本身指出了一些有趣的引用,this one似乎是最有帮助的。
Use parameterized XPath queries (e.g. using XQuery). This will help ensure separation between data plane and control plane.
或
Properly validate user input. Reject data where appropriate, filter where appropriate and escape where appropriate. Make sure input that will be used in XPath queries is safe in that context.
我猜第二个选项不会解决 sonarqube 问题,因为 sonarqube 没有检测到您之前验证了输入。
关于java - 使用 XPath.compile() 容易受到 XPath 注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42110890/