You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java/ql/src/Security/CWE/CWE-297/UnsafeHostnameVerification.qhelp
+20-14Lines changed: 20 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -5,24 +5,31 @@
5
5
<overview>
6
6
<p>
7
7
If a <code>HostnameVerifier</code> always returns <code>true</code> it will not verify the hostname at all.
8
-
This allows an attacker to perform a Man-in-the-middle attack against the application therefore breaking any security Transport Layer Security (TLS) gives.
8
+
This stops Transport Layer Security (TLS) providing any security and allows an attacker to perform a Man-in-the-middle attack against the application.
9
+
</p>
9
10
10
-
An attack would look like this:
11
-
1. The program connects to <code>https://example.com</code>.
12
-
2. The attacker intercepts this connection and presents one of their valid certificates they control, for example one from Let's Encrypt.
13
-
3. Java verifies that the certificate has been issued by a trusted certificate authority.
14
-
4. Java verifies that the certificate has been issued for the host <code>example.com</code>, which will fail because the certificate has been issued for <code>malicious.domain</code>.
15
-
5. Java wants to reject the certificate because the hostname does not match. Before doing this it checks whether there exists a <code>HostnameVerifier</code>.
16
-
6. Your <code>HostnameVerifier</code> is called which returns <code>true</code> for any certificate so also for this one.
17
-
7. Java proceeds with the connection since your <code>HostnameVerifier</code> accepted it.
18
-
8. The attacker can now read the data your program sends to <code>https://example.com</code> and/or alter its replies while the program thinks the connection is secure.
11
+
<p>
12
+
An attack might look like this:
19
13
</p>
14
+
15
+
<ol>
16
+
<li>The program connects to <code>https://example.com</code>.</li>
17
+
<li>The attacker intercepts this connection and presents one of their valid certificates they control, for example one from Let's Encrypt.</li>
18
+
<li>Java verifies that the certificate has been issued by a trusted certificate authority.</li>
19
+
<li>Java verifies that the certificate has been issued for the host <code>example.com</code>, which will fail because the certificate has been issued for <code>malicious.domain</code>.</li>
20
+
<li>Java wants to reject the certificate because the hostname does not match. Before doing this it checks whether there exists a <code>HostnameVerifier</code>.</li>
21
+
<li>Your <code>HostnameVerifier</code> is called which returns <code>true</code> for any certificate so also for this one.</li>
22
+
<li>Java proceeds with the connection since your <code>HostnameVerifier</code> accepted it.</li>
23
+
<li>The attacker can now read the data your program sends to <code>https://example.com</code>
24
+
and/or alter its replies while the program thinks the connection is secure.</li>
25
+
</ol>
26
+
20
27
</overview>
21
28
22
29
<recommendation>
23
30
<p>
24
31
Do not use an open <code>HostnameVerifier</code>.
25
-
If you use an open verifier to solve a configuration problem with TLS/HTTPS you should solve the configuration problem instead.
32
+
If you have a configuration problem with TLS/HTTPS, you should always solve the configuration problem instead of using an open verifier.
26
33
</p>
27
34
28
35
</recommendation>
@@ -37,8 +44,7 @@ In the second (good) example, the <code>HostnameVerifier</code> only returns <co
37
44
</example>
38
45
39
46
<references>
40
-
<li><ahref="https://developer.android.com/training/articles/security-ssl">Android Security Guide for TLS/HTTPS</a>.</li>
41
-
<li><ahref="https://tersesystems.com/blog/2014/03/23/fixing-hostname-verification/">Further Information on Hostname Verification</a>.</li>
Copy file name to clipboardExpand all lines: java/ql/src/Security/CWE/CWE-297/UnsafeHostnameVerification.ql
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
/**
2
2
* @name Disabled hostname verification
3
-
* @description Accepting any certificate as valid for a host allows an attacker to perform a machine-in-the-middle attack.
3
+
* @description Marking a certificate as valid for a host without checking the certificate hostname allows an attacker to perform a machine-in-the-middle attack.
0 commit comments