Skip to content

Commit 603c1c1

Browse files
Add the domain used to the alert message
1 parent ceb253e commit 603c1c1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

java/ql/lib/semmle/code/java/security/AndroidCertificatePinningQuery.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,21 @@ private class UntrustedUrlConfig extends TaintTracking::Configuration {
128128
}
129129

130130
/** Holds if `node` is a network communication call for which certificate pinning is not implemented. */
131-
predicate missingPinning(DataFlow::Node node) {
131+
predicate missingPinning(DataFlow::Node node, string domain) {
132132
isAndroid() and
133133
node instanceof MissingPinningSink and
134134
(
135-
not exists(string s | trustedDomain(s))
135+
not exists(string s | trustedDomain(s)) and
136+
domain = ""
136137
or
137-
exists(UntrustedUrlConfig conf | conf.hasFlow(_, node))
138+
exists(UntrustedUrlConfig conf, DataFlow::Node src |
139+
conf.hasFlow(src, node) and
140+
domain = getDomain(src.asExpr())
141+
)
138142
)
139143
}
144+
145+
/** Gets the domain name from the given string literal */
146+
private string getDomain(CompileTimeConstantExpr expr) {
147+
result = expr.getStringValue().regexpCapture("(https?://)?([^/]*)/?", 2)
148+
}

java/ql/src/Security/CWE/CWE-295/AndroidMissingCertificatePinning.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import java
1414
import semmle.code.java.security.AndroidCertificatePinningQuery
1515

16-
from DataFlow::Node node, string msg
16+
from DataFlow::Node node, string domain, string msg
1717
where
18-
missingPinning(node) and
19-
if exists(string x | trustedDomain(x))
20-
then msg = "(untrusted domain)"
21-
else msg = "(no trusted domains)"
18+
missingPinning(node, domain) and
19+
if domain = ""
20+
then msg = "(no explicitly trusted domains)"
21+
else msg = "(" + domain + " is not trusted by a pin)"
2222
select node, "This network call does not implement certificate pinning. " + msg

0 commit comments

Comments
 (0)