Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(mysql): disable TLS by default

t8y25c37c0ad0d0c
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue
index 15902ab360..58205d44fe 100644
--- a/apps/desktop/src/components/connection/ConnectionDialog.vue
+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue
@@ -1680,7 +1680,7 @@ const postgresTlsMode = computed({
},
set: (value: string) => {
form.value.ssl = value !== "disable";
- form.value.url_params = setUrlParam(form.value.url_params, "sslmode", value === "prefer" ? "" : value);
+ form.value.url_params = setUrlParam(form.value.url_params, "sslmode", value);
},
});
const postgresRootCertPath = computed({
@@ -2350,7 +2350,7 @@ function mysqlTlsModeFromParams(params: string | undefined, ssl: boolean | undef
return "verify_identity";
}
- if (!ssl && getUrlParam(params, "require_ssl").toLowerCase() !== "true") return "preferred";
+ if (!ssl && getUrlParam(params, "require_ssl").toLowerCase() !== "true") return "disabled";
if (getUrlParam(params, "verify_identity").toLowerCase() === "true") return "verify_identity";
if (getUrlParam(params, "verify_ca").toLowerCase() === "true") return "verify_ca";
return "required";
@@ -2362,7 +2362,7 @@ function applyMysqlTlsMode(params: string | undefined, mode: string): string {
return setUrlParam(next, "ssl-mode", "disabled");
}
if (mode === "preferred") {
- return next;
+ return setUrlParam(next, "ssl-mode", "preferred");
}
next = setUrlParam(next, "require_ssl", "true");
@@ -4488,8 +4488,8 @@ function openExternalUrl(url: string) {
<SelectValue />
</SelectTrigger>
<SelectContent>
- <SelectItem value="preferred">{{ t("connection.mysqlTlsModePreferred") }}</SelectItem>
<SelectItem value="disabled">{{ t("connection.mysqlTlsModeDisabled") }}</SelectItem>
+ <SelectItem value="preferred">{{ t("connection.mysqlTlsModePreferred") }}</SelectItem>
<SelectItem value="required">{{ t("connection.mysqlTlsModeRequired") }}</SelectItem>
<SelectItem value="verify_ca">{{ t("connection.mysqlTlsModeVerifyCa") }}</SelectItem>
<SelectItem value="verify_identity">{{ t("connection.mysqlTlsModeVerifyIdentity") }}</SelectItem>
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index fa899c43c0..cf1d994793 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -3499,7 +3499,7 @@ mod tests {
assert_eq!(
mysql_metadata_fallback_url(&config, &metadata, &config.host, config.port),
- Some("mysql://root:[email protected]:3306/app?ssl-mode=preferred&charset=utf8mb4".to_string())
+ Some("mysql://root:[email protected]:3306/app?ssl-mode=disabled&charset=utf8mb4".to_string())
);
}
diff --git a/crates/dbx-core/src/db/mysql.rs b/crates/dbx-core/src/db/mysql.rs
index 797d583d4a..3dacbb16b3 100644
--- a/crates/dbx-core/src/db/mysql.rs
+++ b/crates/dbx-core/src/db/mysql.rs
@@ -824,6 +824,9 @@ fn mysql_error_should_retry_without_ssl(error: &str) -> bool {
|| error.contains("handshake")
|| error.contains("tls connection")
|| error.contains("server closed session")
+ // Some MySQL-compatible servers report a preferred-TLS attempt as a
+ // normal server error instead of a TLS handshake error.
+ || (error.contains("client asked for ssl") && error.contains("server does not have this capability"))
}
fn mysql_error_should_retry_with_text_protocol(error: &str) -> bool {
@@ -3604,6 +3607,14 @@ UNIQUE KEY(`tenant_id`, `name``part`)
assert!(mysql_error_should_retry_without_ssl(error));
}
+ #[test]
+ fn mysql_server_without_ssl_capability_retries_without_ssl() {
+ let error =
+ "MySQL connection failed: Driver error: `Client asked for SSL but server does not have this capability'";
+
+ assert!(mysql_error_should_retry_without_ssl(error));
+ }
+
#[test]
fn mysql_tcp_keepalive_uses_milliseconds_not_seconds() {
assert_eq!(MYSQL_TCP_KEEPALIVE_MS, 30_000);
diff --git a/crates/dbx-core/src/models/connection.rs b/crates/dbx-core/src/models/connection.rs
index 0241e4296a..5b458f6529 100644
--- a/crates/dbx-core/src/models/connection.rs
+++ b/crates/dbx-core/src/models/connection.rs
@@ -1294,7 +1294,9 @@ fn normalize_mysql_url_params(value: &str, force_tls: bool, accept_invalid_certs
} else if !parts.iter().any(|part| {
url_param_key_is(part, "ssl-mode") || url_param_key_is(part, "sslmode") || url_param_key_is(part, "require_ssl")
}) {
- parts.insert(0, "ssl-mode=preferred".to_string());
+ // Default MySQL connections keep TLS off unless the user explicitly
+ // enables a TLS mode.
+ parts.insert(0, "ssl-mode=disabled".to_string());
}
if !parts.iter().any(|part| url_param_key_is(part, "charset")) {
@@ -2024,7 +2026,7 @@ mod tests {
assert_eq!(
config.connection_url(),
- "mysql://user%40tenant%23cluster:[email protected]:2883?ssl-mode=preferred&charset=utf8mb4"
+ "mysql://user%40tenant%23cluster:[email protected]:2883?ssl-mode=disabled&charset=utf8mb4"
);
}
@@ -2178,7 +2180,7 @@ mod tests {
assert_eq!(
config.connection_url(),
- "mysql://root:p%40ss%3Aword%[email protected]:2883/db%2Fname?ssl-mode=preferred&charset=utf8mb4"
+ "mysql://root:p%40ss%3Aword%[email protected]:2883/db%2Fname?ssl-mode=disabled&charset=utf8mb4"
);
}
@@ -2187,10 +2189,7 @@ mod tests {
let mut config = mysql_config("root", "secret", Some("test"));
config.url_params = Some("charset=utf8mb4".to_string());
- assert_eq!(
- config.connection_url(),
- "mysql://root:[email protected]:2883/test?ssl-mode=preferred&charset=utf8mb4"
- );
+ assert_eq!(config.connection_url(), "mysql://root:[email protected]:2883/test?ssl-mode=disabled&charset=utf8mb4");
}
#[test]
@@ -2200,7 +2199,7 @@ mod tests {
assert_eq!(
config.connection_url(),
- "mysql://root:[email protected]:2883/test?ssl-mode=preferred&charset=utf8mb4&enable_cleartext_plugin=true"
+ "mysql://root:[email protected]:2883/test?ssl-mode=disabled&charset=utf8mb4&enable_cleartext_plugin=true"
);
}
@@ -2211,7 +2210,7 @@ mod tests {
assert_eq!(
config.connection_url(),
- "mysql://root:[email protected]:2883/test?ssl-mode=preferred&charset=utf8mb4&enable_cleartext_plugin=true"
+ "mysql://root:[email protected]:2883/test?ssl-mode=disabled&charset=utf8mb4&enable_cleartext_plugin=true"
);
}
@@ -2223,7 +2222,7 @@ mod tests {
assert_eq!(
config.connection_url(),
- "mysql://root:[email protected]:2883/test?ssl-mode=preferred&charset=utf8mb4&enable_cleartext_plugin=true"
+ "mysql://root:[email protected]:2883/test?ssl-mode=disabled&charset=utf8mb4&enable_cleartext_plugin=true"
);
}
@@ -2232,10 +2231,7 @@ mod tests {
let mut config = mysql_config("root", "secret", Some("test"));
config.url_params = Some("allowCleartextPasswords=false&enable_cleartext_plugin=&charset=utf8mb4".to_string());
- assert_eq!(
- config.connection_url(),
- "mysql://root:[email protected]:2883/test?ssl-mode=preferred&charset=utf8mb4"
- );
+ assert_eq!(config.connection_url(), "mysql://root:[email protected]:2883/test?ssl-mode=disabled&charset=utf8mb4");
}
#[test]
@@ -2249,6 +2245,17 @@ mod tests {
);
}
+ #[test]
+ fn mysql_explicit_preferred_tls_mode_is_preserved() {
+ let mut config = mysql_config("root", "secret", Some("test"));
+ config.url_params = Some("ssl-mode=preferred".to_string());
+
+ assert_eq!(
+ config.connection_url(),
+ "mysql://root:[email protected]:2883/test?ssl-mode=preferred&charset=utf8mb4"
+ );
+ }
+
#[test]
fn mysql_tls_switch_uses_ca_cert_for_ca_validation() {
let mut config = mysql_config("root", "secret", Some("test"));
@@ -2497,7 +2504,7 @@ mod tests {
let url = config.redacted_connection_url();
- assert_eq!(url, "mysql://10.1.2.3:2883/db%2Fname?ssl-mode=preferred&charset=utf8mb4");
+ assert_eq!(url, "mysql://10.1.2.3:2883/db%2Fname?ssl-mode=disabled&charset=utf8mb4");
assert!(!url.contains("user"));
assert!(!url.contains("p%40ss"));
assert!(!url.contains("p@ss"));
diff --git a/packages/node-core/src/database.ts b/packages/node-core/src/database.ts
index 8f1c2a93b6..b53d7ed058 100644
--- a/packages/node-core/src/database.ts
+++ b/packages/node-core/src/database.ts
@@ -515,7 +515,7 @@ function normalizeMysqlUrlParams(value: string, forceTls: boolean, acceptInvalid
urlParamKeyIs(part, "ssl-mode") || urlParamKeyIs(part, "sslmode") || urlParamKeyIs(part, "require_ssl"),
)
) {
- parts.unshift("ssl-mode=preferred");
+ parts.unshift("ssl-mode=disabled");
}
if (!parts.some((part) => urlParamKeyIs(part, "charset"))) {
parts.push("charset=utf8mb4");
diff --git a/packages/node-core/tests/mysql-url.test.ts b/packages/node-core/tests/mysql-url.test.ts
new file mode 100644
index 0000000000..6cf2b850c6
--- /dev/null
+++ b/packages/node-core/tests/mysql-url.test.ts
@@ -0,0 +1,34 @@
+import assert from "node:assert/strict";
+import { test } from "vitest";
+import type { ConnectionConfig } from "../src/connections.js";
+import { buildConnectionUrl } from "../src/database.js";
+
+function mysqlConfig(overrides: Partial<ConnectionConfig> = {}): ConnectionConfig {
+ return {
+ id: "mysql-test",
+ name: "mysql",
+ db_type: "mysql",
+ host: "mysql.example.com",
+ port: 3306,
+ username: "root",
+ password: "secret",
+ database: "app",
+ ssl: false,
+ ...overrides,
+ };
+}
+
+test("mysql MCP URL does not enable TLS by default", () => {
+ const url = buildConnectionUrl(mysqlConfig(), { host: "mysql.example.com", port: 3306 });
+
+ assert.equal(url, "mysql://root:[email protected]:3306/app");
+});
+
+test("mysql MCP URL preserves explicit preferred TLS mode", () => {
+ const url = buildConnectionUrl(mysqlConfig({ url_params: "ssl-mode=preferred" }), {
+ host: "mysql.example.com",
+ port: 3306,
+ });
+
+ assert.equal(url, "mysql://root:[email protected]:3306/app?ssl-mode=preferred");
+});