CodeQL 文档

不安全的 TLS 配置

ID: go/insecure-tls
Kind: path-problem
Security severity: 7.5
Severity: warning
Precision: very-high
Tags:
   - security
   - external/cwe/cwe-327
Query suites:
   - go-code-scanning.qls
   - go-security-extended.qls
   - go-security-and-quality.qls

点击查看 CodeQL 代码库中的查询

TLS(传输层安全)协议可保护 Internet 上的通信安全。该协议允许客户端/服务器应用程序以旨在防止窃听、篡改或消息伪造的方式进行通信。

当前最新版本为 1.3(1.2 版本仍被认为是安全的)。由于各种安全漏洞,旧版本不再被认为是安全的,这使得它们不适合用于保护您的应用程序。

不幸的是,许多应用程序和网站仍然支持已弃用的 SSL/TLS 版本和密码套件。

建议

仅使用安全的 TLS 版本(1.3 和 1.2),并避免使用不安全的密码套件(您可以在此处查看列表:https://golang.ac.cn/src/crypto/tls/cipher_suites.go#L81)

示例

以下示例显示了创建不安全 TLS 配置的几种方法

package main

import (
	"crypto/tls"
)

func main() {}

func insecureMinMaxTlsVersion() {
	{
		config := &tls.Config{}
		config.MinVersion = 0 // BAD: Setting the MinVersion to 0 equals to choosing the lowest supported version (i.e. SSL3.0)
	}
	{
		config := &tls.Config{}
		config.MinVersion = tls.VersionSSL30 // BAD: SSL 3.0 is a non-secure version of the protocol; it's not safe to use it as MinVersion.
	}
	{
		config := &tls.Config{}
		config.MaxVersion = tls.VersionSSL30 // BAD: SSL 3.0 is a non-secure version of the protocol; it's not safe to use it as MaxVersion.
	}
}

func insecureCipherSuites() {
	config := &tls.Config{
		CipherSuites: []uint16{
			tls.TLS_RSA_WITH_RC4_128_SHA, // BAD: TLS_RSA_WITH_RC4_128_SHA is one of the non-secure cipher suites; it's not safe to be used.
		},
	}
	_ = config
}

以下示例显示了如何创建更安全的 TLS 配置

package main

import "crypto/tls"

func saferTLSConfig() {
	config := &tls.Config{}
	config.MinVersion = tls.VersionTLS12
	config.MaxVersion = tls.VersionTLS13
	// OR
	config.MaxVersion = 0 // GOOD: Setting MaxVersion to 0 means that the highest version available in the package will be used.
}

参考

  • ©GitHub 公司
  • 条款
  • 隐私