Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8f3e64

Browse files
intrigus-lgtmfelicitymay
authored andcommitted
Apply suggestions from code review
Co-authored-by: Felicity Chapman <[email protected]>
1 parent 502e4c3 commit b8f3e64

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

java/ql/src/Security/CWE/CWE-297/UnsafeHostnameVerification.qhelp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,31 @@
55
<overview>
66
<p>
77
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>
910

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:
1913
</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+
2027
</overview>
2128

2229
<recommendation>
2330
<p>
2431
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.
2633
</p>
2734

2835
</recommendation>
@@ -37,8 +44,7 @@ In the second (good) example, the <code>HostnameVerifier</code> only returns <co
3744
</example>
3845

3946
<references>
40-
<li><a href="https://developer.android.com/training/articles/security-ssl">Android Security Guide for TLS/HTTPS</a>.</li>
41-
<li><a href="https://tersesystems.com/blog/2014/03/23/fixing-hostname-verification/">Further Information on Hostname Verification</a>.</li>
42-
<li>OWASP: <a href="https://cwe.mitre.org/data/definitions/297.html">CWE-297</a>.</li>
47+
<li>Android developers: <a href="https://developer.android.com/training/articles/security-ssl">Security with HTTPS and SSL</a>.</li>
48+
<li>Terse systems blog: <a href="https://tersesystems.com/blog/2014/03/23/fixing-hostname-verification/">Fixing Hostname Verification</a>.</li>
4349
</references>
4450
</qhelp>

java/ql/src/Security/CWE/CWE-297/UnsafeHostnameVerification.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @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.
44
* @kind path-problem
55
* @problem.severity error
66
* @precision high

0 commit comments

Comments
 (0)