File tree Expand file tree Collapse file tree
lib/semmle/code/java/security
test/query-tests/security/CWE-273 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,9 +55,10 @@ abstract class SslUnsafeCertTrustSanitizer extends DataFlow::Node { }
5555 */
5656private 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}
Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments