Skip to content

Commit a2b1943

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 ffcc45e commit a2b1943

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 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,15 @@ 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+
this.getName()
67+
.regexpMatch(".*(?i)(delete|insert|update|save|persist|merge|replicate|execute).*")
68+
)
69+
}
70+
}

0 commit comments

Comments
 (0)