Usage of naive Socket class to create SSL Socket

Overview

  • Rule ID: java_lang_socket_init

  • Applicable Languages: Java

  • Weakness ID: CWE-319

Description

Using the naive Socket class to create SSL sockets compromises security. Directly creating SSL sockets with new Socket() lacks the advanced security features provided by SSLSocketFactory. SSLSocketFactory is designed with SSL/TLS protocols in mind, offering encryption, hostname verification, and trust manager configuration, making it a more secure option for creating SSL sockets.

Remediation Guidelines

  • Avoid using java.net.Socket to directly create SSL sockets due to its limited security capabilities.

  • Use SSLSocketFactory to create SSL sockets, ensuring the use of SSL/TLS protocols and other security enhancements.

    SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, true);
    

References

Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our SAST TOOL

Last updated