Skip to content

Commit 16e16f0

Browse files
Add webview cert validation query
1 parent a779f0e commit 16e16f0

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java
2+
3+
class OnReceivedSslErrorMethod extends Method {
4+
OnReceivedSslErrorMethod() {
5+
this.hasQualifiedName("android.webkit", "WebViewClient", "onReceivedSslError")
6+
}
7+
8+
Parameter handlerArg() { result = this.getParameter(1) }
9+
}
10+
11+
private class SslCancelCall extends MethodAccess {
12+
SslCancelCall() {
13+
this.getMethod().hasQualifiedName("android.webkit", "SslErrorHandler", "cancel")
14+
}
15+
}
16+
17+
private class SslProceedCall extends MethodAccess {
18+
SslProceedCall() {
19+
this.getMethod().hasQualifiedName("android.webkit", "SslErrorHandler", "proceed")
20+
}
21+
}
22+
23+
predicate trustsAllCerts(OnReceivedSslErrorMethod m) {
24+
exists(SslProceedCall pr | pr.getQualifier().(VarAccess).getVariable() = m.handlerArg()) and
25+
not exists(SslCancelCall ca | ca.getQualifier().(VarAccess).getVariable() = m.handlerArg())
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Android `WebVeiw` that accepts all certificates
3+
* @description Trusting all certificates allows an attacker to perform a machine-in-the-middle attack.
4+
* @kind problem
5+
* @problem.severity error
6+
* @security-severity 7.5
7+
* @precision high
8+
* @id java/improper-webview-certificate-validation
9+
* @tags security
10+
* external/cwe/cwe-295
11+
*/
12+
13+
import java
14+
import semmle.code.java.security.AndroidWebViewCertificateValidationQuery
15+
16+
from OnReceivedSslErrorMethod m
17+
where trustsAllCerts(m)
18+
select m, "This handler accepts all SSL certificates."

0 commit comments

Comments
 (0)