Skip to content

Commit b0d9c80

Browse files
committed
Java: add taint steps for Protobuf framework
1 parent fc4aa16 commit b0d9c80

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

java/ql/src/semmle/code/java/dataflow/TaintTracking.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private import semmle.code.java.security.SecurityTests
1313
private import semmle.code.java.security.Validation
1414
private import semmle.code.java.frameworks.android.Intent
1515
private import semmle.code.java.frameworks.Guice
16+
private import semmle.code.java.frameworks.Protobuf
1617
private import semmle.code.java.Maps
1718

1819
module TaintTracking {
@@ -474,6 +475,8 @@ module TaintTracking {
474475
m.hasName("get")
475476
or
476477
m = any(GuiceProvider gp).getAnOverridingGetMethod()
478+
or
479+
m = any(ProtobufMessageLite p).getAGetterMethod()
477480
}
478481

479482
private class StringReplaceMethod extends Method {
@@ -578,6 +581,12 @@ module TaintTracking {
578581
method.getDeclaringType().hasQualifiedName("javax.xml.transform.sax", "SAXSource") and
579582
method.hasName("sourceToInputSource") and
580583
arg = 0
584+
or
585+
exists(ProtobufParser p | method = p.getAParseFromMethod()) and
586+
arg = 0
587+
or
588+
exists(ProtobufMessageLite m | method = m.getAParseFromMethod()) and
589+
arg = 0
581590
}
582591

583592
/**
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Provides classes and predicates for working with the Protobuf framework.
3+
*/
4+
5+
import java
6+
7+
/**
8+
* The interface `com.google.protobuf.Parser`.
9+
*/
10+
class ProtobufParser extends Interface {
11+
ProtobufParser() { this.hasQualifiedName("com.google.protobuf", "Parser") }
12+
13+
/**
14+
* Gets a method named `parseFrom` (or similar) declared on a subtype of `com.google.protobuf.Parser`.
15+
*/
16+
Method getAParseFromMethod() {
17+
result.getDeclaringType().getASupertype*().getSourceDeclaration() = this and
18+
result.getName().matches("parse%From")
19+
}
20+
}
21+
22+
/**
23+
* The interface `com.google.protobuf.MessageLite`.
24+
*/
25+
class ProtobufMessageLite extends Interface {
26+
ProtobufMessageLite() { this.hasQualifiedName("com.google.protobuf", "MessageLite") }
27+
28+
/**
29+
* Gets a static method named `parseFrom` (or similar) declared on a subtype of the `MessageLite` interface.
30+
*/
31+
Method getAParseFromMethod() {
32+
result = getASubtype+().getAMethod() and
33+
result.getName().matches("parse%From") and
34+
result.isStatic()
35+
}
36+
37+
/**
38+
* Gets a getter method declared on a subtype of the `MessageLite` interface.
39+
*/
40+
Method getAGetterMethod() {
41+
exists(RefType decl | decl = result.getDeclaringType() and decl = this.getASubtype+() |
42+
exists(string name, string suffix |
43+
suffix = "" or
44+
suffix = "list" or
45+
suffix = "map" or
46+
suffix = "ordefault" or
47+
suffix = "orthrow"
48+
|
49+
exists(Field f | f.getDeclaringType() = decl |
50+
f.getName().toLowerCase().replaceAll("_", "") = name
51+
) and
52+
result.getName().toLowerCase() = "get" + name + suffix
53+
)
54+
)
55+
}
56+
}

0 commit comments

Comments
 (0)