Skip to content

Commit d3fcfb0

Browse files
committed
Java: Fix FP in UseSSL.
1 parent ca72c8e commit d3fcfb0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

java/ql/src/Security/CWE/CWE-319/UseSSL.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
import java
13+
import semmle.code.java.dataflow.TypeFlow
1314
import semmle.code.java.security.Encryption
1415

1516
class URLConnection extends RefType {
@@ -27,11 +28,15 @@ from MethodAccess m, Class c, string type
2728
where
2829
m.getQualifier().getType() = c and
2930
(
30-
(c instanceof URLConnection and type = "connection")
31+
c instanceof URLConnection and type = "connection"
3132
or
32-
(c instanceof Socket and type = "socket")
33+
c instanceof Socket and type = "socket"
3334
) and
3435
not c instanceof SSLClass and
36+
not exists(RefType t |
37+
exprTypeFlow(m.getQualifier(), t, _) and
38+
t instanceof SSLClass
39+
) and
3540
(
3641
m.getMethod().getName() = "getInputStream" or
3742
m.getMethod().getName() = "getOutputStream"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.net.HttpURLConnection;
2+
import javax.net.ssl.HttpsURLConnection;
3+
import java.io.*;
4+
5+
class Test {
6+
public void m1(HttpURLConnection connection) {
7+
InputStream input;
8+
if (connection instanceof HttpsURLConnection) {
9+
input = connection.getInputStream(); // OK
10+
} else {
11+
input = connection.getInputStream(); // BAD
12+
}
13+
}
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Test.java:11:15:11:41 | getInputStream(...) | Stream using vulnerable non-SSL connection. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE/CWE-319/UseSSL.ql

0 commit comments

Comments
 (0)