File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
lib/semmle/code/java/security
test/query-tests/security/CWE-273 Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,10 @@ abstract class SslUnsafeCertTrustSanitizer extends DataFlow::Node { }
55
55
*/
56
56
private class SslConnectionWithSafeSslParameters extends SslUnsafeCertTrustSanitizer {
57
57
SslConnectionWithSafeSslParameters ( ) {
58
- exists ( SafeSslParametersFlowConfig config , DataFlow:: Node safe |
58
+ exists ( SafeSslParametersFlowConfig config , DataFlow:: Node safe , DataFlow :: Node sanitizer |
59
59
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 )
61
62
)
62
63
}
63
64
}
@@ -72,7 +73,7 @@ private class SslEngineServerMode extends SslUnsafeCertTrustSanitizer {
72
73
m .getDeclaringType ( ) .getASupertype * ( ) instanceof SSLEngine and
73
74
ma .getMethod ( ) = m and
74
75
ma .getArgument ( 0 ) .( CompileTimeConstantExpr ) .getBooleanValue ( ) = false and
75
- this = DataFlow :: exprNode ( ma .getQualifier ( ) )
76
+ this . asExpr ( ) = ma .getQualifier ( )
76
77
)
77
78
}
78
79
}
Original file line number Diff line number Diff line change @@ -116,6 +116,18 @@ private void onSetSSLParameters(SSLParameters sslParameters) {
116
116
sslParameters .setEndpointIdentificationAlgorithm ("HTTPS" );
117
117
}
118
118
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
+
119
131
public void testSocketEndpointIdNotSet () throws Exception {
120
132
SocketFactory socketFactory = SocketFactory .getDefault ();
121
133
Socket socket = socketFactory .createSocket ("www.example.com" , 80 );
You can’t perform that action at this time.
0 commit comments