Description
tls.Config{InsecureSkipVerify: true} skips Go’s default certificate chain and hostname checks. The client then needs another trusted way to authenticate the intended server.
Potential impact
- An attacker on the network path may intercept a connection using an invalid certificate.
- Sensitive requests and responses may be exposed or altered.
Remediation
- Leave
InsecureSkipVerifyat its default,false. The server must present a trusted certificate chain and the client must use trusted roots and aServerNamethat matches the destination. - If you need custom verification, authenticate the intended server in
VerifyConnectionor its equivalent. For CA-based verification, check the chain and destination hostname. Keep server verification enabled with mTLS and keep test exceptions out of production.
Examples
The examples show the TLS client settings. Supply the destination hostname when connecting. Trusted roots can come from the system trust store.
Before
go
cfg := &tls.Config{InsecureSkipVerify: true}
After
go
cfg := &tls.Config{MinVersion: tls.VersionTLS12}
The revised client verifies the server because InsecureSkipVerify keeps its default value. MinVersion sets the lowest TLS version it accepts.