Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: add hostname verification to TLS certificate validation (#17868)
Vincent Huang48738edc1423
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.goindex e91f83485f..5850c94b02 100644--- a/backend/plugin/db/mysql/mysql.go+++ b/backend/plugin/db/mysql/mysql.go@@ -229,7 +229,7 @@ func (d *Driver) getRDSConnection(ctx context.Context, connCfg db.ConnectionConfRootCAs: rootCertPool,InsecureSkipVerify: true, // We use custom verification}- tlsConfig.VerifyPeerCertificate = util.CreateCertificateVerifier(rootCertPool)+ tlsConfig.VerifyPeerCertificate = util.CreateCertificateVerifier(rootCertPool, connCfg.DataSource.Host)} else {// Backward compatible config without verificationtlsConfig = &tls.Config{diff --git a/backend/plugin/db/util/ssl.go b/backend/plugin/db/util/ssl.goindex 4b6c17bb1b..1efcce7467 100644--- a/backend/plugin/db/util/ssl.go+++ b/backend/plugin/db/util/ssl.go@@ -57,13 +57,14 @@ func GetTLSConfig(ds *storepb.DataSource) (*tls.Config, error) {// - VerifyPeerCertificate implements custom verification that handles intermediate certificates// - This pattern allows proper verification even when servers send certificates out of ordercfg.InsecureSkipVerify = true- cfg.VerifyPeerCertificate = CreateCertificateVerifier(rootCertPool)+ cfg.VerifyPeerCertificate = CreateCertificateVerifier(rootCertPool, ds.GetHost())return cfg, nil}-// CreateCertificateVerifier returns a verification function that properly handles intermediate certificates.+// CreateCertificateVerifier returns a verification function that properly handles intermediate certificates+// and validates the hostname matches the certificate.// This is exported for use by database drivers that need custom certificate verification.-func CreateCertificateVerifier(rootCertPool *x509.CertPool) func([][]byte, [][]*x509.Certificate) error {+func CreateCertificateVerifier(rootCertPool *x509.CertPool, hostname string) func([][]byte, [][]*x509.Certificate) error {return func(rawCerts [][]byte, _ [][]*x509.Certificate) error {if len(rawCerts) == 0 {return errors.Errorf("empty certificate to verify")@@ -83,10 +84,11 @@ func CreateCertificateVerifier(rootCertPool *x509.CertPool) func([][]byte, [][]*intermediatePool.AddCert(cert)}- // Verify the certificate chain+ // Verify the certificate chain and hostnameopts := x509.VerifyOptions{Roots: rootCertPool,Intermediates: intermediatePool,+ DNSName: hostname,}if _, err = cert.Verify(opts); err != nil {return errors.Wrap(err, "SSL cert failed to verify")