use of org.sonar.plugins.python.api.tree.CallExpression in project sonar-python by SonarSource.
the class SecureModeEncryptionAlgorithmsCheck method initialize.
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(CALL_EXPR, ctx -> {
CallExpression callExpression = (CallExpression) ctx.syntaxNode();
Symbol calleeSymbol = callExpression.calleeSymbol();
if (calleeSymbol == null) {
return;
}
checkPycaLibrary(ctx, callExpression, calleeSymbol);
checkPycryptoAndCryptodomeLibraries(ctx, callExpression, calleeSymbol);
checkPydesLibrary(ctx, callExpression, calleeSymbol);
});
}
use of org.sonar.plugins.python.api.tree.CallExpression in project sonar-python by SonarSource.
the class CsrfDisabledCheck method functionCsrfExemptCheck.
/**
* Raises an issue whenever one of the CSRF-exemption decorators is used as an ordinary function.
*/
private static void functionCsrfExemptCheck(SubscriptionContext subscriptionContext) {
CallExpression callExpr = (CallExpression) subscriptionContext.syntaxNode();
Optional.ofNullable(callExpr.calleeSymbol()).map(Symbol::fullyQualifiedName).filter(DANGEROUS_DECORATORS::contains).ifPresent(fqn -> subscriptionContext.addIssue(callExpr.callee().lastToken(), MESSAGE));
}
use of org.sonar.plugins.python.api.tree.CallExpression in project sonar-python by SonarSource.
the class DebugModeCheck method initialize.
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Kind.CALL_EXPR, ctx -> {
CallExpression callExpression = (CallExpression) ctx.syntaxNode();
List<Argument> arguments = callExpression.arguments();
if (!(callExpression.callee() instanceof QualifiedExpression)) {
return;
}
if ("django.conf.settings.configure".equals(getQualifiedName(callExpression)) && !arguments.isEmpty()) {
arguments.stream().filter(DebugModeCheck::isDebugArgument).forEach(arg -> ctx.addIssue(arg, MESSAGE));
}
});
context.registerSyntaxNodeConsumer(Kind.ASSIGNMENT_STMT, ctx -> {
if (!settingFiles.contains(ctx.pythonFile().fileName())) {
return;
}
AssignmentStatement assignmentStatementTree = (AssignmentStatement) ctx.syntaxNode();
for (ExpressionList lhsExpression : assignmentStatementTree.lhsExpressions()) {
boolean isDebugProperties = lhsExpression.expressions().stream().anyMatch(DebugModeCheck::isDebugIdentifier);
if (isDebugProperties && isTrueLiteral(assignmentStatementTree.assignedValue())) {
ctx.addIssue(assignmentStatementTree, MESSAGE);
}
}
});
}
use of org.sonar.plugins.python.api.tree.CallExpression in project sonar-python by SonarSource.
the class HttpOnlyCookieCheck method dictConstructorSessionCookieHttponlyCheck.
private void dictConstructorSessionCookieHttponlyCheck(SubscriptionContext ctx) {
CallExpression callExpression = (CallExpression) ctx.syntaxNode();
Optional<Expression> falsySetting = searchForFalsySessionCookieHttponlyInDictCons(callExpression);
falsySetting.ifPresent(expression -> ctx.addIssue(expression, message()));
}
use of org.sonar.plugins.python.api.tree.CallExpression in project sonar-python by SonarSource.
the class ClearTextProtocolsCheck method initialize.
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Tree.Kind.STRING_ELEMENT, ctx -> {
Tree node = ctx.syntaxNode();
String value = Expressions.unescape((StringElement) node);
unsafeProtocol(value).map(protocol -> protocol.substring(0, protocol.length() - 3)).ifPresent(protocol -> ctx.addIssue(node, message(protocol)));
});
context.registerSyntaxNodeConsumer(Tree.Kind.CALL_EXPR, ctx -> {
Symbol symbol = ((CallExpression) ctx.syntaxNode()).calleeSymbol();
isUnsafeLib(symbol).ifPresent(protocol -> ctx.addIssue(ctx.syntaxNode(), message(protocol)));
});
context.registerSyntaxNodeConsumer(Tree.Kind.ASSIGNMENT_STMT, ctx -> handleAssignmentStatement((AssignmentStatement) ctx.syntaxNode(), ctx));
}
Aggregations