Skip to content

Commit 313d24f

Browse files
authored
Merge pull request #1 from aspectsecurity/alert-autofix-6
Potential fix for code scanning alert no. 6: XPath injection
2 parents 5cec9ee + f0dc179 commit 313d24f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/org/owasp/benchmark/testcode/Benchmark00207.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
5656
org.apache.commons.codec.binary.Base64.encodeBase64(
5757
param.getBytes())));
5858
}
59+
final String bar2 = bar;
5960

6061
try {
6162
java.io.FileInputStream file =
@@ -71,7 +72,17 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
7172
javax.xml.xpath.XPathFactory xpf = javax.xml.xpath.XPathFactory.newInstance();
7273
javax.xml.xpath.XPath xp = xpf.newXPath();
7374

74-
String expression = "/Employees/Employee[@emplid='" + bar + "']";
75+
String expression = "/Employees/Employee[@emplid=$emplid]";
76+
xp.setXPathVariableResolver(
77+
new javax.xml.xpath.XPathVariableResolver() {
78+
@Override
79+
public Object resolveVariable(javax.xml.namespace.QName variableName) {
80+
if ("emplid".equals(variableName.getLocalPart())) {
81+
return bar2;
82+
}
83+
return null;
84+
}
85+
});
7586
String result = xp.evaluate(expression, xmlDocument);
7687

7788
response.getWriter().println("Your query results are: " + result + "<br/>");

0 commit comments

Comments
 (0)