raw-sql-injection
Ast Rule: function call
raw-sql-injection
const isTemplateString = (value) => {
if (/^`.+`$/.test(value)) {
return true;
}
return false;
};
function visit(node, filename, code) {
if (node.functionName.astType === "member") {
if (node.functionName.name.astType === "string" &&
node.functionName.name.value === "whereRaw") {
const arguments = node.arguments.values;
if (arguments.length > 0) {
const firstArgument = arguments[0].value;
if (firstArgument.astType === "string") {
if (isTemplateString(firstArgument.value)) {
const error = buildError(firstArgument.start.line,
firstArgument.start.col,
firstArgument.end.line,
firstArgument.end.col,
"use of string template leads to SQL injection", "WARNING", "SECURITY");
addError(error);
}
}
}
}
}
}
test-where-raw-ok1.js
Expected test result: no error
test-where-raw-failure.js
Expected test result: has error