Skip to content

Commit 69e9c17

Browse files
committed
unencrypted-socket-java
1 parent 035cb30 commit 69e9c17

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
id: unencrypted-socket-java
2+
language: java
3+
severity: info
4+
message: >-
5+
"Detected use of a Java socket that is not encrypted. As a result, the
6+
traffic could be read by an attacker intercepting the network traffic. Use
7+
an SSLSocket created by 'SSLSocketFactory' or 'SSLServerSocketFactory'
8+
instead."
9+
note: >-
10+
[CWE-319] Cleartext Transmission of Sensitive Information
11+
[REFERENCES]
12+
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures
13+
ast-grep-essentials: true
14+
15+
rule:
16+
any:
17+
- pattern: new ServerSocket($$$)
18+
- pattern: new Socket($$$)
19+
not:
20+
has:
21+
stopBy: end
22+
kind: ERROR
23+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
id: unencrypted-socket-java
2+
snapshots:
3+
? |
4+
ServerSocket ssoc = new ServerSocket(1234);
5+
: labels:
6+
- source: new ServerSocket(1234)
7+
style: primary
8+
start: 20
9+
end: 42
10+
? |
11+
ServerSocket ssoc1 = new ServerSocket();
12+
: labels:
13+
- source: new ServerSocket()
14+
style: primary
15+
start: 21
16+
end: 39
17+
? |
18+
ServerSocket ssoc2 = new ServerSocket(1234, 10);
19+
: labels:
20+
- source: new ServerSocket(1234, 10)
21+
style: primary
22+
start: 21
23+
end: 47
24+
? |
25+
ServerSocket ssoc3 = new ServerSocket(1234, 10, InetAddress.getByAddress(address));
26+
: labels:
27+
- source: new ServerSocket(1234, 10, InetAddress.getByAddress(address))
28+
style: primary
29+
start: 21
30+
end: 82
31+
? |
32+
Socket soc = new Socket("www.google.com", 80);
33+
: labels:
34+
- source: new Socket("www.google.com", 80)
35+
style: primary
36+
start: 13
37+
end: 45
38+
? |
39+
Socket soc1 = new Socket("www.google.com", 80, true);
40+
: labels:
41+
- source: new Socket("www.google.com", 80, true)
42+
style: primary
43+
start: 14
44+
end: 52
45+
? |
46+
Socket soc2 = new Socket("www.google.com", 80, InetAddress.getByAddress(address), 13337);
47+
: labels:
48+
- source: new Socket("www.google.com", 80, InetAddress.getByAddress(address), 13337)
49+
style: primary
50+
start: 14
51+
end: 88
52+
? |
53+
Socket soc3 = new Socket(InetAddress.getByAddress(remoteAddress), 80);
54+
: labels:
55+
- source: new Socket(InetAddress.getByAddress(remoteAddress), 80)
56+
style: primary
57+
start: 14
58+
end: 69
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
id: unencrypted-socket-java
2+
valid:
3+
- |
4+
Socket soc = SSLSocketFactory.getDefault().createSocket("www.google.com", 443);
5+
- |
6+
ServerSocket ssoc = SSLServerSocketFactory.getDefault().createServerSocket(1234);
7+
invalid:
8+
- |
9+
Socket soc = new Socket("www.google.com", 80);
10+
- |
11+
Socket soc1 = new Socket("www.google.com", 80, true);
12+
- |
13+
Socket soc2 = new Socket("www.google.com", 80, InetAddress.getByAddress(address), 13337);
14+
- |
15+
Socket soc3 = new Socket(InetAddress.getByAddress(remoteAddress), 80);
16+
- |
17+
ServerSocket ssoc = new ServerSocket(1234);
18+
- |
19+
ServerSocket ssoc1 = new ServerSocket();
20+
- |
21+
ServerSocket ssoc2 = new ServerSocket(1234, 10);
22+
- |
23+
ServerSocket ssoc3 = new ServerSocket(1234, 10, InetAddress.getByAddress(address));

0 commit comments

Comments
 (0)