Skip to content

Commit 64518bf

Browse files
committed
Handle a specific pass-by-reference flow issue
1 parent 4508945 commit 64518bf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private class SafeSslParametersFlowConfig extends DataFlow2::Configuration {
9797
override predicate isSource(DataFlow::Node source) {
9898
exists(MethodAccess ma |
9999
ma instanceof SafeSetEndpointIdentificationAlgorithm and
100-
ma.getQualifier() = source.asExpr()
100+
DataFlow::getInstanceArgument(ma) = source.(DataFlow::PostUpdateNode).getPreUpdateNode()
101101
)
102102
}
103103

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ public void testSSLSocketEndpointIdSafe() throws Exception {
102102
socket.getOutputStream(); // Safe
103103
}
104104

105+
public void testSSLSocketEndpointIdSafeWithModificationByReference() throws Exception {
106+
SSLContext sslContext = SSLContext.getInstance("TLS");
107+
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
108+
SSLSocket socket = (SSLSocket) socketFactory.createSocket();
109+
SSLParameters sslParameters = socket.getSSLParameters();
110+
onSetSSLParameters(sslParameters);
111+
socket.setSSLParameters(sslParameters);
112+
socket.getOutputStream(); // Safe
113+
}
114+
115+
private void onSetSSLParameters(SSLParameters sslParameters) {
116+
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
117+
}
118+
105119
public void testSocketEndpointIdNotSet() throws Exception {
106120
SocketFactory socketFactory = SocketFactory.getDefault();
107121
Socket socket = socketFactory.createSocket("www.example.com", 80);

0 commit comments

Comments
 (0)