use of net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression in project pmd by pmd.
the class ApexXSSFromURLParamRule method processEscapingMethodCalls.
private void processEscapingMethodCalls(ASTMethodCallExpression methodNode, Object data) {
ASTMethodCallExpression nestedCall = methodNode.getFirstChildOfType(ASTMethodCallExpression.class);
if (nestedCall != null) {
processEscapingMethodCalls(nestedCall, data);
}
final ASTVariableExpression variable = methodNode.getFirstChildOfType(ASTVariableExpression.class);
if (variable != null) {
if (urlParameterStrings.contains(Helper.getFQVariableName(variable))) {
if (!isEscapingMethod(methodNode)) {
addViolation(data, variable);
}
}
}
}
use of net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression in project pmd by pmd.
the class ApexXSSFromURLParamRule method visit.
@Override
public Object visit(ASTReturnStatement node, Object data) {
ASTBinaryExpression binaryExpression = node.getFirstChildOfType(ASTBinaryExpression.class);
if (binaryExpression != null) {
processBinaryExpression(binaryExpression, data);
}
ASTMethodCallExpression methodCall = node.getFirstChildOfType(ASTMethodCallExpression.class);
if (methodCall != null) {
String retType = getReturnType(node);
if ("string".equalsIgnoreCase(retType)) {
processInlineMethodCalls(methodCall, data, true);
}
}
List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
for (ASTVariableExpression varExpression : nodes) {
if (urlParameterStrings.contains(Helper.getFQVariableName(varExpression))) {
addViolation(data, nodes.get(0));
}
}
return data;
}
use of net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression in project pmd by pmd.
the class ApexXSSFromURLParamRule method processVariableAssignments.
private void processVariableAssignments(AbstractApexNode<?> node, Object data, final boolean reverseOrder) {
ASTMethodCallExpression methodCallAssignment = node.getFirstChildOfType(ASTMethodCallExpression.class);
if (methodCallAssignment != null) {
String varType = null;
if (node instanceof ASTVariableDeclaration) {
varType = ((ASTVariableDeclaration) node).getNode().getLocalInfo().getType().getApexName();
}
if (varType == null || !"id".equalsIgnoreCase(varType)) {
processInlineMethodCalls(methodCallAssignment, data, false);
}
}
List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
switch(nodes.size()) {
case 1:
{
// Look for: foo + bar
final List<ASTBinaryExpression> ops = node.findChildrenOfType(ASTBinaryExpression.class);
if (!ops.isEmpty()) {
for (ASTBinaryExpression o : ops) {
processBinaryExpression(o, data);
}
}
}
break;
case 2:
{
// Look for: foo = bar;
final ASTVariableExpression right = reverseOrder ? nodes.get(0) : nodes.get(1);
if (urlParameterStrings.contains(Helper.getFQVariableName(right))) {
addViolation(data, right);
}
}
break;
default:
break;
}
}
use of net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression in project pmd by pmd.
the class Helper method getFQVariableName.
static String getFQVariableName(final ASTVariableExpression variable) {
final ASTReferenceExpression ref = variable.getFirstChildOfType(ASTReferenceExpression.class);
String objectName = "";
if (ref != null) {
if (ref.getNode().getNames().size() == 1) {
objectName = ref.getNode().getNames().get(0).getValue() + ".";
}
}
VariableExpression n = variable.getNode();
StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(objectName).append(n.getIdentifier().getValue());
return sb.toString();
}
Aggregations