Skip to content

Commit 4694786

Browse files
joke1196sonartech
authored andcommitted
SONARPY-3747 Fix FN on S8370 to raise issue on all children (#827)
GitOrigin-RevId: b12a8338b5faa6b2658c86f5f028dc3c09920f1e
1 parent b44444d commit 4694786

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

python-checks/src/main/java/org/sonar/python/checks/FlaskPostWithQueryParameterCheck.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,16 @@ private static void checkPostWithQueryParams(SubscriptionContext ctx) {
5757
return;
5858
}
5959

60-
TreeUtils.firstChild(functionDef, tree -> tree instanceof QualifiedExpression qe && isRequestArgs(qe, ctx))
61-
.ifPresent(requestArgs -> ctx.addIssue(requestArgs, MESSAGE));
60+
findRequestArgsRecursively(functionDef, ctx)
61+
.forEach(requestArgs -> ctx.addIssue(requestArgs, MESSAGE));
62+
}
63+
64+
private static Stream<Tree> findRequestArgsRecursively(Tree tree, SubscriptionContext ctx) {
65+
if (tree instanceof QualifiedExpression qe && isRequestArgs(qe, ctx)) {
66+
return Stream.of(tree);
67+
}
68+
return tree.children().stream()
69+
.flatMap(child -> findRequestArgsRecursively(child, ctx));
6270
}
6371

6472
private static boolean isPostRoute(FunctionDef functionDef, SubscriptionContext ctx) {
@@ -127,3 +135,4 @@ private static boolean isRequestArgs(QualifiedExpression qualifiedExpr, Subscrip
127135
return TypeMatchers.isObjectOfType(REQUEST_FQN).isTrueFor(request, ctx);
128136
}
129137
}
138+

python-checks/src/test/resources/checks/flaskPostWithQueryParameter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def getting_args():
4040
def update_resource():
4141
key = request.args.get('key') # Noncompliant
4242
# ^^^^^^^^^^^^
43+
response.set_cookie(request.args.get("name"), request.args.get("value")) # Noncompliant 2
4344
return 'Updated'
4445

4546
@app.route('/data', methods=['GET','POST'])

0 commit comments

Comments
 (0)