mirror of
https://github.com/github/codeql.git
synced 2026-03-05 23:26:51 +01:00
35 lines
929 B
Java
35 lines
929 B
Java
public static void main(String[] args) {
|
|
{
|
|
try {
|
|
String protocol = "http://";
|
|
URL u = new URL(protocol + "www.secret.example.org/");
|
|
// BAD: This causes a 'ClassCastException' at runtime, because the
|
|
// HTTP URL cannot be used to make an 'HttpsURLConnection',
|
|
// which enforces SSL.
|
|
HttpsURLConnection hu = (HttpsURLConnection) u.openConnection();
|
|
hu.setRequestMethod("PUT");
|
|
hu.connect();
|
|
OutputStream os = hu.getOutputStream();
|
|
hu.disconnect();
|
|
}
|
|
catch (IOException e) {
|
|
// fail
|
|
}
|
|
}
|
|
|
|
{
|
|
try {
|
|
String protocol = "https://";
|
|
URL u = new URL(protocol + "www.secret.example.org/");
|
|
// GOOD: Opening a connection to a URL using HTTPS enforces SSL.
|
|
HttpsURLConnection hu = (HttpsURLConnection) u.openConnection();
|
|
hu.setRequestMethod("PUT");
|
|
hu.connect();
|
|
OutputStream os = hu.getOutputStream();
|
|
hu.disconnect();
|
|
}
|
|
catch (IOException e) {
|
|
// fail
|
|
}
|
|
}
|
|
} |