Skip to content

Commit 87a8746

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add a class for methods that update a sql database (found using sql-injection nodes)
1 parent 43a2880 commit 87a8746

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import java
44
private import semmle.code.java.frameworks.spring.SpringController
55
private import semmle.code.java.frameworks.MyBatis
66
private import semmle.code.java.frameworks.Jdbc
7+
private import semmle.code.java.dataflow.DataFlow
8+
private import semmle.code.java.dataflow.ExternalFlow
79

810
/** A method that is not protected from CSRF by default. */
911
abstract class CsrfUnprotectedMethod extends Method { }
@@ -54,3 +56,18 @@ private class PreparedStatementDatabaseUpdateMethod extends DatabaseUpdateMethod
5456
this instanceof PreparedStatementExecuteLargeUpdateMethod
5557
}
5658
}
59+
60+
/** A method that updates a SQL database. */
61+
private class SqlDatabaseUpdateMethod extends DatabaseUpdateMethod {
62+
SqlDatabaseUpdateMethod() {
63+
// TODO: constrain to only insert/update/delete for `execute%` methods; need to track the sql expression into the execute call.
64+
exists(DataFlow::Node n | this = n.asExpr().(Argument).getCall().getCallee() |
65+
sinkNode(n, "sql-injection") and
66+
// do not include `executeQuery` since it is typically used with a select statement
67+
this.hasName([
68+
"delete", "insert", "update", "batchUpdate", "executeUpdate", "executeLargeUpdate",
69+
"execute"
70+
])
71+
)
72+
}
73+
}

0 commit comments

Comments
 (0)