Skip to content

Commit 085c12a

Browse files
authored
Merge pull request #10116 from atorralba/atorralba/static-init-vector-fix
Java: Improve Static Initialization Vector query
2 parents e3c1101 + da3288f commit 085c12a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,25 @@ private class ArrayUpdate extends Expr {
5454
ma = this and
5555
ma.getArgument(0) = array
5656
|
57-
m.hasQualifiedName("java.io", "InputStream", "read") or
57+
m.getAnOverride*().hasQualifiedName("java.io", ["InputStream", "RandomAccessFile"], "read") or
58+
m.getAnOverride*().hasQualifiedName("java.io", "DataInput", "readFully") or
5859
m.hasQualifiedName("java.nio", "ByteBuffer", "get") or
5960
m.hasQualifiedName("java.security", "SecureRandom", "nextBytes") or
60-
m.hasQualifiedName("java.util", "Random", "nextBytes")
61+
m.hasQualifiedName("java.util", "Random", "nextBytes") or
62+
m.hasQualifiedName("java.util.zip", "Inflater", "inflate") or
63+
m.hasQualifiedName("io.netty.buffer", "ByteBuf", "readBytes") or
64+
m.getAnOverride*().hasQualifiedName("org.bouncycastle.crypto", "Digest", "doFinal")
65+
)
66+
or
67+
exists(MethodAccess ma, Method m |
68+
m = ma.getMethod() and
69+
ma = this and
70+
ma.getArgument(1) = array
71+
|
72+
m.hasQualifiedName("org.apache.commons.io", "IOUtils", ["read", "readFully"]) or
73+
m.hasQualifiedName("io.netty.buffer", "ByteBuf", "getBytes") or
74+
m.hasQualifiedName("org.bouncycastle.crypto.generators",
75+
any(string s | s.matches("%BytesGenerator")), "generateBytes")
6176
)
6277
}
6378

@@ -95,17 +110,15 @@ private class StaticInitializationVectorSource extends DataFlow::Node {
95110
}
96111

97112
/**
98-
* A sink that initializes a cipher for encryption with unsafe parameters.
113+
* A sink that initializes a cipher with unsafe parameters.
99114
*/
100115
private class EncryptionInitializationSink extends DataFlow::Node {
101116
EncryptionInitializationSink() {
102-
exists(MethodAccess ma, Method m, FieldRead fr | m = ma.getMethod() |
117+
exists(MethodAccess ma, Method m | m = ma.getMethod() |
103118
m.hasQualifiedName("javax.crypto", "Cipher", "init") and
104119
m.getParameterType(2)
105120
.(RefType)
106121
.hasQualifiedName("java.security.spec", "AlgorithmParameterSpec") and
107-
fr.getField().hasQualifiedName("javax.crypto", "Cipher", "ENCRYPT_MODE") and
108-
DataFlow::localExprFlow(fr, ma.getArgument(0)) and
109122
ma.getArgument(2) = this.asExpr()
110123
)
111124
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `java/static-initialization-vector` no longer requires a `Cipher` object to be initialized with `ENCRYPT_MODE` to be considered a valid sink. Also, several new sanitizers were added.

0 commit comments

Comments
 (0)