Search in sources :

Example 6 with ASTMethodCallExpression

use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.

the class ApexSOQLInjectionRule method reportStrings.

private void reportStrings(ASTMethodCallExpression m, Object data) {
    final HashSet<ASTVariableExpression> setOfSafeVars = new HashSet<>();
    final List<ASTStandardCondition> conditions = m.findDescendantsOfType(ASTStandardCondition.class);
    for (ASTStandardCondition c : conditions) {
        List<ASTVariableExpression> vars = c.findDescendantsOfType(ASTVariableExpression.class);
        setOfSafeVars.addAll(vars);
    }
    final List<ASTBinaryExpression> binaryExpr = m.findChildrenOfType(ASTBinaryExpression.class);
    for (ASTBinaryExpression b : binaryExpr) {
        List<ASTVariableExpression> vars = b.findDescendantsOfType(ASTVariableExpression.class);
        for (ASTVariableExpression v : vars) {
            String fqName = Helper.getFQVariableName(v);
            if (selectContainingVariables.containsKey(fqName)) {
                boolean isLiteral = selectContainingVariables.get(fqName);
                if (isLiteral) {
                    continue;
                }
            }
            if (setOfSafeVars.contains(v) || safeVariables.contains(fqName)) {
                continue;
            }
            final ASTMethodCallExpression parentCall = v.getFirstParentOfType(ASTMethodCallExpression.class);
            boolean isSafeMethod = Helper.isMethodName(parentCall, STRING, ESCAPE_SINGLE_QUOTES) || Helper.isMethodName(parentCall, STRING, JOIN);
            if (!isSafeMethod) {
                addViolation(data, v);
            }
        }
    }
}
Also used : ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) ASTBinaryExpression(net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression) ASTStandardCondition(net.sourceforge.pmd.lang.apex.ast.ASTStandardCondition) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression) HashSet(java.util.HashSet)

Example 7 with ASTMethodCallExpression

use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.

the class ApexSuggestUsingNamedCredRule method visit.

@Override
public Object visit(ASTUserClass node, Object data) {
    if (Helper.isTestMethodOrClass(node)) {
        return data;
    }
    List<ASTVariableDeclaration> variableDecls = node.findDescendantsOfType(ASTVariableDeclaration.class);
    for (ASTVariableDeclaration varDecl : variableDecls) {
        findAuthLiterals(varDecl);
    }
    List<ASTField> fieldDecl = node.findDescendantsOfType(ASTField.class);
    for (ASTField fDecl : fieldDecl) {
        findFieldLiterals(fDecl);
    }
    List<ASTMethodCallExpression> methodCalls = node.findDescendantsOfType(ASTMethodCallExpression.class);
    for (ASTMethodCallExpression method : methodCalls) {
        flagAuthorizationHeaders(method, data);
    }
    listOfAuthorizationVariables.clear();
    return data;
}
Also used : ASTVariableDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration) ASTField(net.sourceforge.pmd.lang.apex.ast.ASTField) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 8 with ASTMethodCallExpression

use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.

the class ApexXSSFromURLParamRule method findTaintedVariables.

private void findTaintedVariables(AbstractApexNode<?> node, Object data) {
    final ASTMethodCallExpression right = node.getFirstChildOfType(ASTMethodCallExpression.class);
    if (right != null) {
        if (Helper.isMethodCallChain(right, URL_PARAMETER_METHOD)) {
            ASTVariableExpression left = node.getFirstChildOfType(ASTVariableExpression.class);
            String varType = null;
            if (node instanceof ASTVariableDeclaration) {
                varType = ((ASTVariableDeclaration) node).getNode().getLocalInfo().getType().getApexName();
            }
            if (left != null) {
                if (varType == null || !"id".equalsIgnoreCase(varType)) {
                    urlParameterStrings.add(Helper.getFQVariableName(left));
                }
            }
        }
        processEscapingMethodCalls(right, data);
    }
}
Also used : ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) ASTVariableDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 9 with ASTMethodCallExpression

use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.

the class ApexXSSFromURLParamRule method processBinaryExpression.

private void processBinaryExpression(AbstractApexNode<?> node, Object data) {
    ASTBinaryExpression nestedBinaryExpression = node.getFirstChildOfType(ASTBinaryExpression.class);
    if (nestedBinaryExpression != null) {
        processBinaryExpression(nestedBinaryExpression, data);
    }
    ASTMethodCallExpression methodCallAssignment = node.getFirstChildOfType(ASTMethodCallExpression.class);
    if (methodCallAssignment != null) {
        processInlineMethodCalls(methodCallAssignment, data, true);
    }
    final List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
    for (ASTVariableExpression n : nodes) {
        if (urlParameterStrings.contains(Helper.getFQVariableName(n))) {
            addViolation(data, n);
        }
    }
}
Also used : ASTBinaryExpression(net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression) ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 10 with ASTMethodCallExpression

use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.

the class ApexCRUDViolationRule method getPreviousMethodCalls.

private Set<ASTMethodCallExpression> getPreviousMethodCalls(final AbstractApexNode<?> self) {
    final Set<ASTMethodCallExpression> innerMethodCalls = new HashSet<>();
    final ASTMethod outerMethod = self.getFirstParentOfType(ASTMethod.class);
    if (outerMethod != null) {
        final ASTBlockStatement blockStatement = outerMethod.getFirstChildOfType(ASTBlockStatement.class);
        recursivelyEvaluateCRUDMethodCalls(self, innerMethodCalls, blockStatement);
        final List<ASTMethod> constructorMethods = findConstructorlMethods();
        for (ASTMethod method : constructorMethods) {
            innerMethodCalls.addAll(method.findDescendantsOfType(ASTMethodCallExpression.class));
        }
        // some methods might be within this class
        mapCallToMethodDecl(self, innerMethodCalls, new ArrayList<ASTMethodCallExpression>(innerMethodCalls));
    }
    return innerMethodCalls;
}
Also used : ASTMethod(net.sourceforge.pmd.lang.apex.ast.ASTMethod) ASTBlockStatement(net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression) HashSet(java.util.HashSet)

Aggregations

ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)18 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)10 ASTVariableDeclaration (net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration)7 ASTBinaryExpression (net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression)5 ASTMethod (net.sourceforge.pmd.lang.apex.ast.ASTMethod)4 ASTBlockStatement (net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement)3 HashSet (java.util.HashSet)2 ASTAssignmentExpression (net.sourceforge.pmd.lang.apex.ast.ASTAssignmentExpression)2 ASTFieldDeclaration (net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration)2 ASTLiteralExpression (net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression)2 ASTUserClass (net.sourceforge.pmd.lang.apex.ast.ASTUserClass)2 Identifier (apex.jorje.data.Identifier)1 VariableDeclaration (apex.jorje.semantic.ast.statement.VariableDeclaration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ASTField (net.sourceforge.pmd.lang.apex.ast.ASTField)1 ASTIfElseBlockStatement (net.sourceforge.pmd.lang.apex.ast.ASTIfElseBlockStatement)1 ASTNewKeyValueObjectExpression (net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression)1 ASTReferenceExpression (net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression)1 ASTReturnStatement (net.sourceforge.pmd.lang.apex.ast.ASTReturnStatement)1