Skip to content

Commit 19d1a78

Browse files
committed
Generalize sanitizer using local flow
1 parent 64518bf commit 19d1a78

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ abstract class SslUnsafeCertTrustSanitizer extends DataFlow::Node { }
5555
*/
5656
private class SslConnectionWithSafeSslParameters extends SslUnsafeCertTrustSanitizer {
5757
SslConnectionWithSafeSslParameters() {
58-
exists(SafeSslParametersFlowConfig config, DataFlow::Node safe |
58+
exists(SafeSslParametersFlowConfig config, DataFlow::Node safe, DataFlow::Node sanitizer |
5959
config.hasFlowTo(safe) and
60-
this = DataFlow::exprNode(safe.asExpr().(Argument).getCall().getQualifier())
60+
sanitizer = DataFlow::exprNode(safe.asExpr().(Argument).getCall().getQualifier()) and
61+
DataFlow::localFlow(sanitizer, this)
6162
)
6263
}
6364
}
@@ -72,7 +73,7 @@ private class SslEngineServerMode extends SslUnsafeCertTrustSanitizer {
7273
m.getDeclaringType().getASupertype*() instanceof SSLEngine and
7374
ma.getMethod() = m and
7475
ma.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = false and
75-
this = DataFlow::exprNode(ma.getQualifier())
76+
this.asExpr() = ma.getQualifier()
7677
)
7778
}
7879
}

java/ql/test/query-tests/security/CWE-273/UnsafeCertTrustTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ private void onSetSSLParameters(SSLParameters sslParameters) {
116116
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
117117
}
118118

119+
public void testSSLSocketEndpointIdSafeWithConditionalSanitizer(boolean safe) throws Exception {
120+
SSLContext sslContext = SSLContext.getInstance("TLS");
121+
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
122+
SSLSocket socket = (SSLSocket) socketFactory.createSocket();
123+
if (safe) {
124+
SSLParameters sslParameters = socket.getSSLParameters();
125+
onSetSSLParameters(sslParameters);
126+
socket.setSSLParameters(sslParameters);
127+
}
128+
socket.getOutputStream(); // Safe
129+
}
130+
119131
public void testSocketEndpointIdNotSet() throws Exception {
120132
SocketFactory socketFactory = SocketFactory.getDefault();
121133
Socket socket = socketFactory.createSocket("www.example.com", 80);

0 commit comments

Comments
 (0)