Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Insecure JXBrowser #4945

Merged
merged 10 commits into from Feb 10, 2021
Merged

Conversation

intrigus-lgtm
Copy link
Contributor

JXBrowser is a Java library that allows to embed the Chromium browser inside Java applications.
The version 6.x.x by default ignores any HTTPS certificate errors thereby allowing man-in-the-middle attacks.

This PR detects this case.

@intrigus-lgtm intrigus-lgtm requested a review from a team as a code owner January 12, 2021 16:25
@intrigus-lgtm intrigus-lgtm changed the title Java/insecure jxbrowser Java: Insecure JXBrowser Jan 12, 2021
@intrigus-lgtm
Copy link
Contributor Author

It just came to my attention that this has been fixed in version 6.24.
I've assumed that the latest version is 6.23.1 as this is the version of the javadocs I found...

I will now detect version 6.24 by the existence of the addBoundsListener method on the com.teamdev.jxbrowser.chromium.Browser class.
As far as I know CodeQL extracts all (public) methods of a class.
And the Browser class is always used in this vulnerability, so it will always be extracted and the existence of the method is therefore a reliable indicator for the version.

@smowton
Copy link
Contributor

smowton commented Jan 14, 2021

Could you also add a test using v6.24, to show this is correctly not flagged? By making your test project not reference the addBoundsListener method you can also ensure your detection method works when that method is not called.

@intrigus-lgtm
Copy link
Contributor Author

Could you also add a test using v6.24, to show this is correctly not flagged? By making your test project not reference the addBoundsListener method you can also ensure your detection method works when that method is not called.

How can I use different stubs for different tests? The options file is used for the whole folder, isn't it?
Is there a way to use these options only for a specific test file? Or should I have to create two folders for the different versions?

@smowton
Copy link
Contributor

smowton commented Jan 14, 2021

Two folders looks like the right option to me

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.
@intrigus-lgtm
Copy link
Contributor Author

I've added tests for both versions.

What do you think, would this query need major changes to become a non-experimental query?

@smowton
Copy link
Contributor

smowton commented Jan 15, 2021

I don't think there's anything I'd change about the code; the only possible obstacle would be FPs if any

@intrigus-lgtm
Copy link
Contributor Author

@smowton @aschackmull just checking, is there anything missing I should improve?

aschackmull
aschackmull previously approved these changes Feb 5, 2021
@intrigus-lgtm
Copy link
Contributor Author

Hmm, looks like some tests are failing.

@aschackmull
Copy link
Contributor

Looks like the alert message in the query doesn't match the expected output in the test.

Also, the qhelp apparently fails to render:

  Error: 2-05 09:00:23] [ERROR] generate query-help> ql/java/ql/src/experimental/Security/CWE/CWE-295/JxBrowserWithoutCertValidation.qhelp:14:5: element "li" not allowed here; expected the element end-tag, text or element "a", "b", "code", "em", "i", "img", "strong", "sub", "sup" or "tt"
  Error: 2-05 09:00:23] [ERROR] generate query-help> ql/java/ql/src/experimental/Security/CWE/CWE-295/JxBrowserWithoutCertValidation.qhelp:15:5: element "li" not allowed here; expected the element end-tag, text or element "a", "b", "code", "em", "i", "img", "strong", "sub", "sup" or "tt"

Accept test output for changed alert message.
@intrigus-lgtm
Copy link
Contributor Author

@aschackmull I hope I fixed both the QHelp and the tests.

@aschackmull
Copy link
Contributor

[2021-02-10 12:14:46] This is codeql generate query-help -vvv --log-to-stderr --output out --format markdown --search-path . -- ql/java/ql/src/experimental/Security/CWE/CWE-295/JxBrowserWithoutCertValidation.qhelp
  Error: 2-10 12:14:46] [ERROR] generate query-help> ql/java/ql/src/experimental/Security/CWE/CWE-295/JxBrowserWithoutCertValidation.qhelp:14:5: element "ul" not allowed here; expected the element end-tag, text or element "a", "b", "code", "em", "i", "img", "strong", "sub", "sup" or "tt"

@intrigus-lgtm
Copy link
Contributor Author

Sorry for all the back and forth.
This time it should work for real...
OOI: Why is this qhelp preview check not run by default and public?

[2021-02-10 14:03:18] This is codeql generate query-help -vvv --log-to-stderr --output out.md --format markdown --search-path . -- java/ql/src/experimental/Security/CWE/CWE-295/JxBrowserWithoutCertValidation.qhelp
[2021-02-10 14:03:18] Terminating normally.

@aschackmull
Copy link
Contributor

OOI: Why is this qhelp preview check not run by default and public?

Definitely historical reasons. I'm unsure whether those reasons still apply, and it would be nice if it was automatic and public, so I'll raise the question internally.

@aschackmull aschackmull merged commit b749112 into github:main Feb 10, 2021
@intrigus-lgtm intrigus-lgtm deleted the java/insecure-jxbrowser branch February 10, 2021 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants