|
Waiting for #4771 before reviewing this |
Sorry, something went wrong.
|
Hi @intrigus-lgtm. It looks like #4771 has been merged. Are you able to rebase this now? |
Sorry, something went wrong.
|
@kevinbackhouse sure! But I don't have time right now, probably later this day. |
Sorry, something went wrong.
|
@kevinbackhouse @smowton this has been rebased :) |
Sorry, something went wrong.
There was a problem hiding this comment.
How about instead of implementing custom logic for barrier guards to pick out the various "if(acceptAllCertificates) ..." cases, we treat context.getSocketFactory as the sink and init(...) as a taint propagator? That way we'll pick out cases where the if(acceptAll) ... logic happens in a parent function, while the flow from instantiating a bad trust manager to calling context.init happens entirely within a child function. By lengthening the passage of code we consider as the source -> sink path, we should be able to use Configuraton.isBarrierGuard/isSanitizerGuard instead of implementing our own guard.controls logic.
Sorry, something went wrong.
| If the <code>checkServerTrusted</code> method of a <code>TrustManager</code> never throws a <code>CertificateException</code> it trusts every certificate. | ||
| This allows an attacker to perform a Man-in-the-middle attack against the application therefore breaking any security Transport Layer Security (TLS) gives. | ||
|
|
||
| An attack would look like this: |
There was a problem hiding this comment.
| An attack would look like this: | |
| An example attack: |
Sorry, something went wrong.
There was a problem hiding this comment.
This has not been applied.
Instead it has been changed to "An attack might look like this:".
Hope this is ok.
Sorry, something went wrong.
| 3. Java calls the <code>checkServerTrusted</code> method to check whether it should trust the certificate. | ||
| 4. The <code>checkServerTrusted</code> method of your <code>TrustManager</code> does not throw a <code>CertificateException</code>. | ||
| 5. Java proceeds with the connection since your <code>TrustManager</code> implicitly trusted it by not throwing an exception. | ||
| 6. The attacker can now read the data your program sends to <code>https://example.com</code> and/or alter its replies while the program thinks the connection is secure. |
There was a problem hiding this comment.
| 6. The attacker can now read the data your program sends to <code>https://example.com</code> and/or alter its replies while the program thinks the connection is secure. | |
| 6. The attacker can now read the data your program sends to <code>https://example.com</code> and/or alter its replies while the user might expect that the connection is secure. |
Sorry, something went wrong.
There was a problem hiding this comment.
Currently not applied as this is the same as https://github.com/intrigus-lgtm/ql/blob/2931e1f3fb4f68205c20db825d85d81f6782631b/java/ql/src/Security/CWE/CWE-297/UnsafeHostnameVerification.qhelp#L23-L24
If you still want to see it changed, I can apply it.
Sorry, something went wrong.
There was a problem hiding this comment.
I see, ok let's leave this the way it is for now and when I get a moment I'll see if that query can be improved.
Sorry, something went wrong.
| } | ||
|
|
||
| /** Holds if `node` is guarded by a flag that suggests an intentionally insecure feature. */ | ||
| private predicate isNodeGuardedByFlag(DataFlow::Node node) { |
There was a problem hiding this comment.
This is reimplementing the Configuration.isBarrierGuard concept
Sorry, something went wrong.
There was a problem hiding this comment.
So what do you suggest going forward?
Sorry, something went wrong.
There was a problem hiding this comment.
I'll see if I can fit this into a barrier-guard tomorrow.
Sorry, something went wrong.
|
How about instead of implementing custom logic for barrier guards to pick out the various "if(acceptAllCertificates) ..." cases, we treat context.getSocketFactory as the sink and init(...) as a taint propagator? That way we'll pick out cases where the if(acceptAll) ... logic happens in a parent function, while the flow from instantiating a bad trust manager to calling context.init happens entirely within a child function. By lengthening the passage of code we consider as the source -> sink path, we should be able to use Configuraton.isBarrierGuard/isSanitizerGuard instead of implementing our own guard.controls logic. How strong do you feel about this? |
Sorry, something went wrong.
|
@smowton I applied most of your suggestions besides to suggestions in the .qhelp file. Suggestions on the barrier stuff are also unresolved, as it is not yet clear how we want to proceed. |
Sorry, something went wrong.
|
OK, if you don't want to pursue that you don't have to; I'll start a benchmark run with the query as-is |
Sorry, something went wrong.
There was a problem hiding this comment.
There are also various unaddressed comments here. They don't all have to be applied, but please do respond to them
Sorry, something went wrong.
|
There are also various unaddressed comments here. They don't all have to be applied, but please do respond to them Will do, but I'm currently lacking a continuous chunk of time needed for evaluating the barrier guard stuff which could make some comments outdated. |
Sorry, something went wrong.
|
👋🏻 I've removed myself as a reviewer so that I don't get nagged about reviewing this PR every morning 😄 @github/codeql-java When this is ready for a docs team review, please ping the new @github/docs-content-codeql team and a member of the team will be in touch. |
Sorry, something went wrong.
|
Sorry for the long wait. I've experimented a bit with the query.
With filtering on flag guards I mean code like this: if(enableHttps) {
sink();
}
Re:
Links for the query runs have been privately shared with @smowton. |
Sorry, something went wrong.
|
Which version do you want to submit for consideration for a bounty? |
Sorry, something went wrong.
|
Which version do you want to submit for consideration for a bounty? The best one :D But I don't know what you would consider best. |
Sorry, something went wrong.
|
I don't have the time to assess 5 variants to decide which is best -- you should pick one. To assess which is doing a better job you could use the LGTM API to determine which projects differ between the different versions and take a closer look at those ones. Then you'll know whether version 4 or 5 is actually useful or whether your guess that they're just producing less results is correct. |
Sorry, something went wrong.
|
Rebased. |
Sorry, something went wrong.
This can be rebased once #4771 is merged.