Handle a specific pass-by-reference flow issue

This commit is contained in:
Tony Torralba
2021-06-23 15:43:48 +02:00
parent 4508945f85
commit 64518bf91a
2 changed files with 15 additions and 1 deletions

View File

@@ -97,7 +97,7 @@ private class SafeSslParametersFlowConfig extends DataFlow2::Configuration {
override predicate isSource(DataFlow::Node source) {
exists(MethodAccess ma |
ma instanceof SafeSetEndpointIdentificationAlgorithm and
ma.getQualifier() = source.asExpr()
DataFlow::getInstanceArgument(ma) = source.(DataFlow::PostUpdateNode).getPreUpdateNode()
)
}

View File

@@ -102,6 +102,20 @@ public class UnsafeCertTrustTest {
socket.getOutputStream(); // Safe
}
public void testSSLSocketEndpointIdSafeWithModificationByReference() throws Exception {
SSLContext sslContext = SSLContext.getInstance("TLS");
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
SSLSocket socket = (SSLSocket) socketFactory.createSocket();
SSLParameters sslParameters = socket.getSSLParameters();
onSetSSLParameters(sslParameters);
socket.setSSLParameters(sslParameters);
socket.getOutputStream(); // Safe
}
private void onSetSSLParameters(SSLParameters sslParameters) {
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
}
public void testSocketEndpointIdNotSet() throws Exception {
SocketFactory socketFactory = SocketFactory.getDefault();
Socket socket = socketFactory.createSocket("www.example.com", 80);