mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Fix scope issues in the Java example
This commit is contained in:
@@ -1,22 +1,19 @@
|
|||||||
public class InsecureBasicAuth {
|
public class InsecureBasicAuth {
|
||||||
/**
|
/**
|
||||||
* Test basic authentication with Apache HTTP request.
|
* Test basic authentication with Apache HTTP request.
|
||||||
*/
|
*/
|
||||||
public void testApacheHttpRequest(String username, String password) {
|
public void testApacheHttpRequest(String username, String password) {
|
||||||
{
|
|
||||||
// BAD: basic authentication over HTTP
|
// BAD: basic authentication over HTTP
|
||||||
String url = "http://www.example.com/rest/getuser.do?uid=abcdx";
|
String url = "http://www.example.com/rest/getuser.do?uid=abcdx";
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// GOOD: basic authentication over HTTPS
|
// GOOD: basic authentication over HTTPS
|
||||||
String url = "https://www.example.com/rest/getuser.do?uid=abcdx";
|
url = "https://www.example.com/rest/getuser.do?uid=abcdx";
|
||||||
}
|
|
||||||
|
|
||||||
HttpPost post = new HttpPost(url);
|
HttpPost post = new HttpPost(url);
|
||||||
post.setHeader("Accept", "application/json");
|
post.setHeader("Accept", "application/json");
|
||||||
post.setHeader("Content-type", "application/json");
|
post.setHeader("Content-type", "application/json");
|
||||||
|
|
||||||
String authString = username + ":" + password;
|
String authString = username + ":" + password;
|
||||||
byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
|
byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
|
||||||
String authStringEnc = new String(authEncBytes);
|
String authStringEnc = new String(authEncBytes);
|
||||||
@@ -28,15 +25,12 @@ public class InsecureBasicAuth {
|
|||||||
* Test basic authentication with Java HTTP URL connection.
|
* Test basic authentication with Java HTTP URL connection.
|
||||||
*/
|
*/
|
||||||
public void testHttpUrlConnection(String username, String password) {
|
public void testHttpUrlConnection(String username, String password) {
|
||||||
{
|
|
||||||
// BAD: basic authentication over HTTP
|
// BAD: basic authentication over HTTP
|
||||||
String urlStr = "http://www.example.com/rest/getuser.do?uid=abcdx";
|
String urlStr = "http://www.example.com/rest/getuser.do?uid=abcdx";
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// GOOD: basic authentication over HTTPS
|
// GOOD: basic authentication over HTTPS
|
||||||
String urlStr = "https://www.example.com/rest/getuser.do?uid=abcdx";
|
urlStr = "https://www.example.com/rest/getuser.do?uid=abcdx";
|
||||||
}
|
|
||||||
|
|
||||||
String authString = username + ":" + password;
|
String authString = username + ":" + password;
|
||||||
String encoding = Base64.getEncoder().encodeToString(authString.getBytes("UTF-8"));
|
String encoding = Base64.getEncoder().encodeToString(authString.getBytes("UTF-8"));
|
||||||
|
|||||||
Reference in New Issue
Block a user