// A ?var surrounded by " or ' where the variable is a literal is an
// attack vector
Pattern p = Pattern.compile("\"[?$]" + var + "\"|'[?$]" + var + "'");
if (p.matcher(command).find() && n.isLiteral()) {
throw new ARQException(
"Command string is vunerable to injection attack, variable ?"
+ var
+ " appears surrounded directly by quotes and is bound to a literal which provides a SPARQL injection attack vector");
}
// Parse out delimiter info
DelimiterInfo delims = this.findDelimiters(command);
// Check each occurrence of the variable for safety
p = Pattern.compile("([?$]" + var + ")([^\\w]|$)");
Matcher matcher = p.matcher(command);
while (matcher.find()) {
MatchResult posMatch = matcher.toMatchResult();
if (n.isLiteral()) {
if (delims.isInsideLiteral(posMatch.start(1), posMatch.end(1))) {
throw new ARQException(
"Command string is vunerable to injection attack, variable ?"
+ var
+ " appears inside of a literal and is bound to a literal which provides a SPARQL injection attack vector");
}
}