Skip to content

Commit 5cf8ca2

Browse files
authored
Validate that hostname is ascii in OkHostnameVerifier.java
Sec vuln fix
1 parent 486b8ba commit 5cf8ca2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

okhttp/third_party/okhttp/main/java/io/grpc/okhttp/internal/OkHostnameVerifier.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.Locale;
3131
import java.util.regex.Pattern;
32+
import java.nio.charset.StandardCharsets;
3233
import javax.net.ssl.HostnameVerifier;
3334
import javax.net.ssl.SSLException;
3435
import javax.net.ssl.SSLSession;
@@ -63,6 +64,9 @@ private OkHostnameVerifier() {
6364

6465
@Override
6566
public boolean verify(String host, SSLSession session) {
67+
if (!isAscii(host)) {
68+
return false;
69+
}
6670
try {
6771
Certificate[] certificates = session.getPeerCertificates();
6872
return verify(host, (X509Certificate) certificates[0]);
@@ -254,4 +258,9 @@ private boolean verifyHostName(String hostName, String pattern) {
254258
// hostName matches pattern
255259
return true;
256260
}
261+
262+
private static boolean isAscii(String input) {
263+
// Only ASCII characters are 1 byte in UTF-8.
264+
return input.getBytes(StandardCharsets.UTF_8).length == input.length();
265+
}
257266
}

0 commit comments

Comments
 (0)