Skip to content

Commit a4cbd70

Browse files
committed
Java: Add tests for different versions.
Adds a test for version 6.24, because that version is not vulnerable. The other test is for versions < 6.24, because these versions are vulnerable.
1 parent b807648 commit a4cbd70

14 files changed

Lines changed: 76 additions & 3 deletions

java/ql/test/experimental/query-tests/security/CWE-295/JxBrowserWithoutCertValidation.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| JxBrowserWithoutCertValidationV6_23_1.java:17:27:17:39 | new Browser(...) | This JxBrowser instance allows man-in-the-middle attacks. |

java/ql/test/experimental/query-tests/security/CWE-295/JxBrowserWithoutCertValidation.qlref renamed to java/ql/test/experimental/query-tests/security/CWE-295/jxbrowser-6.23.1/JxBrowserWithoutCertValidation.qlref

File renamed without changes.

java/ql/test/experimental/query-tests/security/CWE-295/JxBrowserWithoutCertValidation.java renamed to java/ql/test/experimental/query-tests/security/CWE-295/jxbrowser-6.23.1/JxBrowserWithoutCertValidationV6_23_1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.teamdev.jxbrowser.chromium.LoadParams;
44
import com.teamdev.jxbrowser.chromium.CertificateErrorParams;
55

6-
public class JxBrowserWithoutCertValidation {
6+
public class JxBrowserWithoutCertValidationV6_23_1 {
77

88
public static void main(String[] args) {
99

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

java/ql/test/experimental/query-tests/security/CWE-295/jxbrowser-6.24/JxBrowserWithoutCertValidation.expected

Whitespace-only changes.
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: 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 JxBrowserWithoutCertValidationV6_24 {
7+
8+
public static void main(String[] args) {
9+
10+
goodUsage();
11+
12+
goodUsage2();
13+
14+
}
15+
16+
private static void goodUsage() {
17+
Browser browser = new Browser();
18+
browser.loadURL("https://example.com");
19+
// no further calls
20+
// GOOD: On version 6.24 the browser properly validates certificates by default!
21+
}
22+
23+
private static void goodUsage2() {
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+
}

java/ql/test/experimental/query-tests/security/CWE-295/options renamed to java/ql/test/experimental/query-tests/security/CWE-295/jxbrowser-6.24/options

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/jxbrowser-6.23.1
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/jxbrowser-6.24
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 interface BoundsListener {
4+
5+
}

0 commit comments

Comments
 (0)