java - 使用 XPath.compile() 容易受到 XPath 注入(inject)

标签 java xml sonarqube

在使用 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/

相关文章:

java - 在方法之前或内部检查因变量的最佳实践

javascript - 带有数据的 XML 模式?我如何用JS解析它?

sonarqube - 如何共享 Sonarqube 仪表板?

java - Sonar : You must define the following mandatory properties for unknown not resolved

Java if语句currentTimeMillis,检查特定时间是否已经过去

Java, JDBC : Does closing a PreparedStatement also free up its memory footprint in the database connection?

asp.net - Xdocument.Load(XMLReader.Read()) 给我错误

sonarqube - 跟踪 SonarQube 扫描的来源

java - 类路径中的 logback.xml 与logging.config一起执行 环境参数 spring boot

javascript - 是否可以在浏览器中从 json 创建 xml,然后下载该 xml?