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

Skip to content

Commit b308728

Browse files
committed
Java: Add tests and test stubs.
1 parent 9b3070a commit b308728

8 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| JXBrowserWithoutCertValidation.java:17:27:17:39 | new Browser(...) | This JXBrowser instance allows man-in-the-middle attacks. |
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import com.teamdev.jxbrowser.chromium.Browser;
2+
import com.teamdev.jxbrowser.chromium.LoadHandler;
3+
import com.teamdev.jxbrowser.chromium.LoadParams;
4+
import com.teamdev.jxbrowser.chromium.CertificateErrorParams;
5+
6+
public class JXBrowserWithoutCertValidation {
7+
8+
public static void main(String[] args) {
9+
10+
badUsage();
11+
12+
goodUsage();
13+
14+
}
15+
16+
private static void badUsage() {
17+
Browser browser = new Browser();
18+
browser.loadURL("https://example.com");
19+
// no further calls
20+
// BAD: The browser ignores any certificate error by default!
21+
}
22+
23+
private static void goodUsage() {
24+
Browser browser = new Browser();
25+
browser.setLoadHandler(new LoadHandler() {
26+
public boolean onLoad(LoadParams params) {
27+
return true;
28+
}
29+
30+
public boolean onCertificateError(CertificateErrorParams params) {
31+
return true; // GOOD: This means that loading will be cancelled on certificate errors
32+
}
33+
}); // GOOD: A secure `LoadHandler` is used.
34+
browser.loadURL("https://example.com");
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-295/JXBrowserWithoutCertValidation.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/jxbrowser-6.23.1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.teamdev.jxbrowser.chromium;
2+
3+
public class Browser extends java.lang.Object {
4+
public void setLoadHandler(LoadHandler handler) {
5+
}
6+
7+
public void loadURL(String url) {
8+
}
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.teamdev.jxbrowser.chromium;
2+
3+
public final class CertificateErrorParams extends Object {
4+
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.teamdev.jxbrowser.chromium;
2+
3+
public interface LoadHandler {
4+
boolean onCertificateError(CertificateErrorParams params);
5+
6+
boolean onLoad(LoadParams params);
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.teamdev.jxbrowser.chromium;
2+
3+
public final class LoadParams extends Object {
4+
5+
}

0 commit comments

Comments
 (0)