Skip to content

Commit 43a2880

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add a class for PreparedStatement methods that update a database
1 parent b88731d commit 43a2880

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

java/ql/lib/semmle/code/java/frameworks/Jdbc.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ class ResultSetGetStringMethod extends Method {
3434
this.getReturnType() instanceof TypeString
3535
}
3636
}
37+
38+
/** A method with the name `executeUpdate` declared in `java.sql.PreparedStatement`. */
39+
class PreparedStatementExecuteUpdateMethod extends Method {
40+
PreparedStatementExecuteUpdateMethod() {
41+
this.getDeclaringType() instanceof TypePreparedStatement and
42+
this.hasName("executeUpdate")
43+
}
44+
}
45+
46+
/** A method with the name `executeLargeUpdate` declared in `java.sql.PreparedStatement`. */
47+
class PreparedStatementExecuteLargeUpdateMethod extends Method {
48+
PreparedStatementExecuteLargeUpdateMethod() {
49+
this.getDeclaringType() instanceof TypePreparedStatement and
50+
this.hasName("executeLargeUpdate")
51+
}
52+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java
44
private import semmle.code.java.frameworks.spring.SpringController
55
private import semmle.code.java.frameworks.MyBatis
6+
private import semmle.code.java.frameworks.Jdbc
67

78
/** A method that is not protected from CSRF by default. */
89
abstract class CsrfUnprotectedMethod extends Method { }
@@ -45,3 +46,11 @@ private class MyBatisMapperDatabaseUpdateMethod extends DatabaseUpdateMethod {
4546
)
4647
}
4748
}
49+
50+
/** A method declared in `java.sql.PreparedStatement` that updates a database. */
51+
private class PreparedStatementDatabaseUpdateMethod extends DatabaseUpdateMethod {
52+
PreparedStatementDatabaseUpdateMethod() {
53+
this instanceof PreparedStatementExecuteUpdateMethod or
54+
this instanceof PreparedStatementExecuteLargeUpdateMethod
55+
}
56+
}

0 commit comments

Comments
 (0)