Using sockets is security-sensitive. It has led in the past to the following vulnerabilities:

Sockets are vulnerable in multiple ways:

This rules flags code that creates sockets. It matches only the direct use of sockets, not use through frameworks or high-level APIs such as the use of http connections.

Ask Yourself Whether

There is a risk if you answered yes to any of those questions.

Recommended Secure Coding Practices

Sensitive Code Example

Imports System.Net.Sockets

Public Class Sockets

    Public Shared Sub Run()
        ' Sensitive
        Dim socket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

        ' TcpClient And UdpClient simply abstract the details of creating a Socket
        Dim client As TcpClient = New TcpClient("example.com", 80) ' Sensitive
        Dim listener As UdpClient = New UdpClient(80)   ' Sensitive
    End Sub

End Class

See

Deprecated

This rule is deprecated, and will eventually be removed.