25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(mysql): require TLS for TiDB Cloud connections (#911)
Holata Seminole70dad4e00b8c
diff --git a/apps/desktop/src/lib/connectionUrl.ts b/apps/desktop/src/lib/connectionUrl.tsindex d4e700588a..53b2332c8c 100644--- a/apps/desktop/src/lib/connectionUrl.ts+++ b/apps/desktop/src/lib/connectionUrl.ts@@ -205,6 +205,10 @@ function urlParamsRequireTls(dbType: DatabaseType, params: string): boolean {return false;}+function isTidbCloudHost(host: string): boolean {+ return host.toLowerCase().endsWith(".tidbcloud.com");+}+export function connectionProfileForScheme(scheme: string, preferredProfile?: string): ConnectionProfile | undefined {if ((scheme === "http" || scheme === "https") && preferredProfile) {return HTTP_SELECTED_PROFILES[preferredProfile];@@ -433,7 +437,11 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Papassword: mysqlCredentials?.password ?? decodeUrlPart(parsed.password),database: databaseFromPath(parsed.pathname),urlParams: effectiveUrlParams,- ssl: scheme === "rediss" || scheme === "https" || urlParamsRequireTls(profile.type, effectiveUrlParams),+ ssl:+ scheme === "rediss" ||+ scheme === "https" ||+ urlParamsRequireTls(profile.type, effectiveUrlParams) ||+ (profile.type === "mysql" && isTidbCloudHost(parsed.hostname)),};}diff --git a/crates/dbx-core/src/models/connection.rs b/crates/dbx-core/src/models/connection.rsindex cb3e74aa56..6d4327e45e 100644--- a/crates/dbx-core/src/models/connection.rs+++ b/crates/dbx-core/src/models/connection.rs@@ -921,7 +921,9 @@ impl ConnectionConfig {return normalize_bare_mysql_url_params(value);}match self.db_type {- DatabaseType::Mysql => normalize_mysql_url_params(value, self.ssl, self.ca_cert_path.trim().is_empty()),+ DatabaseType::Mysql => {+ normalize_mysql_url_params(value, self.mysql_uses_tls(), self.ca_cert_path.trim().is_empty())+ }DatabaseType::Doris | DatabaseType::StarRocks | DatabaseType::Databend => {normalize_bare_mysql_url_params(value)}@@ -935,6 +937,10 @@ impl ConnectionConfig {self.ssl || url_params_contains_flag(self.url_params.as_deref(), "secure", "true")}+ fn mysql_uses_tls(&self) -> bool {+ self.ssl || self.host.to_ascii_lowercase().ends_with(".tidbcloud.com")+ }+fn redis_tls_insecure_fragment(&self) -> &'static str {if self.ssl && self.redis_tls_insecure() {"#insecure"@@ -987,10 +993,12 @@ fn normalize_mysql_url_params(value: &str, force_tls: bool, accept_invalid_certslet mut parts: Vec<String> = value.split('&').filter(|part| !part.is_empty()).map(str::to_string).collect();if force_tls {- parts.retain(|part| !url_param_key_is(part, "ssl-mode") && !url_param_key_is(part, "sslmode"));- if !parts.iter().any(|part| url_param_key_is(part, "require_ssl")) {- parts.insert(0, "require_ssl=true".to_string());- }+ parts.retain(|part| {+ !url_param_key_is(part, "ssl-mode")+ && !url_param_key_is(part, "sslmode")+ && !url_param_key_is(part, "require_ssl")+ });+ parts.insert(0, "require_ssl=true".to_string());if accept_invalid_certs && !parts.iter().any(|part| url_param_key_is(part, "verify_ca")) {parts.push("verify_ca=false".to_string());}@@ -1668,6 +1676,19 @@ mod tests {);}+ #[test]+ fn tidb_cloud_mysql_url_requires_tls() {+ let mut config = mysql_config("root", "secret", Some("test"));+ config.host = "gateway01.us-west-2.prod.aws.tidbcloud.com".to_string();+ config.port = 4000;+ config.url_params = Some("require_ssl=false&charset=utf8mb4".to_string());++ assert_eq!(+ config.connection_url(),+ "mysql://root:[email protected]:4000/test?require_ssl=true&verify_ca=false&verify_identity=false&charset=utf8mb4"+ );+ }+#[test]fn postgres_url_appends_custom_params() {let mut config = mysql_config("postgres", "secret", Some("test"));diff --git a/packages/app-tests/connectionUrl.test.ts b/packages/app-tests/connectionUrl.test.tsindex 151e5bacc8..f81ba44f78 100644--- a/packages/app-tests/connectionUrl.test.ts+++ b/packages/app-tests/connectionUrl.test.ts@@ -50,6 +50,15 @@ test("parses mysql TLS URL params into the SSL switch state", () => {assert.equal(parseConnectionUrl("mysql://[email protected]:4000/test?require_ssl=true").ssl, true);});+test("parses TiDB Cloud MySQL URLs as TLS connections", () => {+ const parsed = parseConnectionUrl(+ "mysql://root:[email protected]:4000/test",+ );++ assert.equal(parsed.dbType, "mysql");+ assert.equal(parsed.ssl, true);+});+test("parses MySQL JDBC user and password URL params as credentials", () => {const parsed = parseConnectionUrl("jdbc:mysql://127.0.0.1:1234/example?user=admin&password=pwd&useUnicode=true&characterEncoding=UTF8&useSSL=false",