Skip to content

Commit c3c7337

Browse files
committed
Fix scope issues in the Java example
1 parent 0232646 commit c3c7337

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

java/ql/src/Security/CWE/CWE-522/InsecureBasicAuth.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
public class InsecureBasicAuth {
22
/**
33
* Test basic authentication with Apache HTTP request.
4-
*/
4+
*/
55
public void testApacheHttpRequest(String username, String password) {
6-
{
6+
77
// BAD: basic authentication over HTTP
88
String url = "http://www.example.com/rest/getuser.do?uid=abcdx";
9-
}
109

11-
{
1210
// GOOD: basic authentication over HTTPS
13-
String url = "https://www.example.com/rest/getuser.do?uid=abcdx";
14-
}
11+
url = "https://www.example.com/rest/getuser.do?uid=abcdx";
1512

1613
HttpPost post = new HttpPost(url);
1714
post.setHeader("Accept", "application/json");
1815
post.setHeader("Content-type", "application/json");
19-
16+
2017
String authString = username + ":" + password;
2118
byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
2219
String authStringEnc = new String(authEncBytes);
@@ -28,15 +25,12 @@ public void testApacheHttpRequest(String username, String password) {
2825
* Test basic authentication with Java HTTP URL connection.
2926
*/
3027
public void testHttpUrlConnection(String username, String password) {
31-
{
28+
3229
// BAD: basic authentication over HTTP
3330
String urlStr = "http://www.example.com/rest/getuser.do?uid=abcdx";
34-
}
3531

36-
{
3732
// GOOD: basic authentication over HTTPS
38-
String urlStr = "https://www.example.com/rest/getuser.do?uid=abcdx";
39-
}
33+
urlStr = "https://www.example.com/rest/getuser.do?uid=abcdx";
4034

4135
String authString = username + ":" + password;
4236
String encoding = Base64.getEncoder().encodeToString(authString.getBytes("UTF-8"));

0 commit comments

Comments
 (0)