use of org.sonar.plugins.python.api.tree.Argument 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.Argument in project sonar-python by SonarSource.
the class HttpOnlyCookieCheck method searchForFalsySessionCookieHttponlyInDictCons.
private static Optional<Expression> searchForFalsySessionCookieHttponlyInDictCons(CallExpression callExpression) {
Symbol callee = callExpression.calleeSymbol();
if (callee != null && "dict".equals(callee.fullyQualifiedName())) {
for (Argument arg : callExpression.arguments()) {
if (arg.is(Tree.Kind.REGULAR_ARGUMENT)) {
RegularArgument regArg = (RegularArgument) arg;
Name key = regArg.keywordArgument();
if (key != null && SESSION_COOKIE_HTTPONLY.equals(key.name()) && Expressions.isFalsy(regArg.expression())) {
return Optional.of(regArg.expression());
}
}
}
}
return Optional.empty();
}
use of org.sonar.plugins.python.api.tree.Argument in project sonar-python by SonarSource.
the class CorsCheck method reportIfAllowOriginIsStar.
private static void reportIfAllowOriginIsStar(SubscriptionContext ctx, CallExpression callExpression) {
Argument arg0 = callExpression.arguments().get(0);
Argument arg1 = callExpression.arguments().get(1);
if (isString(arg0, ALLOW_ORIGIN) && isString(arg1, STAR)) {
ctx.addIssue(callExpression, MESSAGE);
}
}
use of org.sonar.plugins.python.api.tree.Argument in project sonar-python by SonarSource.
the class CorsCheck method checkFlaskResponse.
private static void checkFlaskResponse(SubscriptionContext ctx) {
CallExpression callExpression = (CallExpression) ctx.syntaxNode();
Symbol symbol = callExpression.calleeSymbol();
if (isSymbol(symbol, "flask.Response") || isSymbol(symbol, "flask.wrappers.Response")) {
if (callExpression.arguments().size() > 2) {
Argument argument = callExpression.arguments().get(2);
reportOnHeader(ctx, argument);
}
} else if (isSymbol(symbol, "flask.make_response") || isSymbol(symbol, "flask.helpers.make_response")) {
if (callExpression.arguments().size() != 1) {
return;
}
Argument argument = callExpression.arguments().get(0);
if (argument.is(REGULAR_ARGUMENT) && ((RegularArgument) argument).expression().is(TUPLE)) {
List<Expression> elements = ((Tuple) ((RegularArgument) argument).expression()).elements();
if (!elements.isEmpty()) {
reportOnHeader(ctx, elements.get(elements.size() - 1));
}
}
}
}
use of org.sonar.plugins.python.api.tree.Argument in project sonar-python by SonarSource.
the class XMLParserXXEVulnerableCheck method checkSettingFeatureGesToTrue.
private static boolean checkSettingFeatureGesToTrue(CallExpression callExpression) {
List<Argument> arguments = callExpression.arguments();
if (arguments.size() != 2 || arguments.stream().anyMatch(argument -> !argument.is(Tree.Kind.REGULAR_ARGUMENT))) {
return false;
}
Expression first = ((RegularArgument) arguments.get(0)).expression();
Expression second = ((RegularArgument) arguments.get(1)).expression();
if (!(first instanceof HasSymbol)) {
return false;
}
Symbol symbol = ((HasSymbol) first).symbol();
if (symbol == null) {
return false;
}
return "xml.sax.handler.feature_external_ges".equals(symbol.fullyQualifiedName()) && !Expressions.isFalsy(second);
}
Aggregations