CodeQL 文档

证书结果混淆

ID: cpp/certificate-result-conflation
Kind: problem
Security severity: 7.5
Severity: error
Precision: medium
Tags:
   - security
   - external/cwe/cwe-295
Query suites:
   - cpp-security-extended.qls
   - cpp-security-and-quality.qls

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

在检查 SSL 证书验证结果时,接受任何错误代码可能允许攻击者伪装成可信用户。

建议

使用 SSL_get_verify_result 检查 SSL 证书时,只有 X509_V_OK 是成功代码。如果出现其他结果,则不应接受证书。

示例

在此示例中,错误代码 X509_V_ERR_CERT_HAS_EXPIRED 与 OK 结果相同。不应该接受已过期的证书,因为它比有效证书更容易被攻击。

// ...

if (cert = SSL_get_peer_certificate(ssl))
{
	result = SSL_get_verify_result(ssl);

	if ((result == X509_V_OK) || (result == X509_V_ERR_CERT_HAS_EXPIRED)) // BAD (conflates OK and a non-OK codes)
	{
		do_ok();
	} else {
		do_error();
	}
}

在修正后的示例中,只接受 X509_V_OK 的结果。

// ...

if (cert = SSL_get_peer_certificate(ssl))
{
	result = SSL_get_verify_result(ssl);

	if (result == X509_V_OK) // GOOD
	{
		do_ok();
	} else {
		do_error();
	}
}

参考资料

  • ©GitHub, Inc.
  • 条款
  • 隐私