Skip to content

Commit 45d117b

Browse files
authored
Merge pull request github#4603 from pwntester/new_deser_sink
New UnsafeDeserialization sink and improvements to SnakeYaml sink
2 parents 89a808c + f103955 commit 45d117b

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lgtm,codescanning
2+
* The query "Deserialization of user-controlled data" (`java/unsafe-deserialization`) has been improved to recognize unsafe Apache Commons Lang(3) methods.
3+
* The SnakeYAML Unsafe Deserialization sink has been improved to recognize `compose` and `composeAll` unsafe methods.

java/ql/src/semmle/code/java/frameworks/SnakeYaml.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SafeSnakeYamlConstruction extends ClassInstanceExpr {
3939
* The class `org.yaml.snakeyaml.Yaml`.
4040
*/
4141
class Yaml extends RefType {
42-
Yaml() { this.hasQualifiedName("org.yaml.snakeyaml", "Yaml") }
42+
Yaml() { this.getASupertype*().hasQualifiedName("org.yaml.snakeyaml", "Yaml") }
4343
}
4444

4545
private class SafeYamlConstructionFlowConfig extends DataFlow2::Configuration {
@@ -71,7 +71,7 @@ private class SnakeYamlParse extends MethodAccess {
7171
SnakeYamlParse() {
7272
exists(Method m |
7373
m.getDeclaringType() instanceof Yaml and
74-
(m.hasName("load") or m.hasName("loadAll") or m.hasName("loadAs") or m.hasName("parse")) and
74+
m.hasName(["compose", "composeAll", "load", "loadAll", "loadAs", "parse"]) and
7575
m = this.getMethod()
7676
)
7777
}

java/ql/src/semmle/code/java/frameworks/apache/Lang.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@ class TypeApacheRandomStringUtils extends Class {
1010
hasQualifiedName("org.apache.commons.lang3", "RandomStringUtils")
1111
}
1212
}
13+
14+
/*--- Methods ---*/
15+
/**
16+
* The method `deserialize` in either `org.apache.commons.lang.SerializationUtils`
17+
* or `org.apache.commons.lang3.SerializationUtils`.
18+
*/
19+
class MethodApacheSerializationUtilsDeserialize extends Method {
20+
MethodApacheSerializationUtilsDeserialize() {
21+
(
22+
this.getDeclaringType().hasQualifiedName("org.apache.commons.lang", "SerializationUtils") or
23+
this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "SerializationUtils")
24+
) and
25+
this.hasName("deserialize")
26+
}
27+
}

java/ql/src/semmle/code/java/security/UnsafeDeserialization.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import semmle.code.java.frameworks.Kryo
22
import semmle.code.java.frameworks.XStream
33
import semmle.code.java.frameworks.SnakeYaml
4+
import semmle.code.java.frameworks.apache.Lang
45

56
class ObjectInputStreamReadObjectMethod extends Method {
67
ObjectInputStreamReadObjectMethod() {
@@ -71,6 +72,9 @@ predicate unsafeDeserialization(MethodAccess ma, Expr sink) {
7172
sink = ma.getAnArgument() and
7273
not exists(SafeKryo sk | sk.hasFlowToExpr(ma.getQualifier()))
7374
or
75+
m instanceof MethodApacheSerializationUtilsDeserialize and
76+
sink = ma.getArgument(0)
77+
or
7478
ma instanceof UnsafeSnakeYamlParse and
7579
sink = ma.getArgument(0)
7680
)

0 commit comments

Comments
 (0)