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(connection): keep the Oracle TNS_ADMIN directory in plaintext exports (#12723)
弈秋b168508b9f5d
diff --git a/apps/desktop/src/lib/connection/connectionConfigTransfer.oracleTns.spec.ts b/apps/desktop/src/lib/connection/connectionConfigTransfer.oracleTns.spec.tsnew file mode 100644index 0000000000..2c99f0cc9a--- /dev/null+++ b/apps/desktop/src/lib/connection/connectionConfigTransfer.oracleTns.spec.ts@@ -0,0 +1,97 @@+import { describe, expect, it } from "vitest";+import { parseConnectionConfigObject, prepareConnectionConfigImport, scrubConnectionForPlaintextExport } from "./connectionConfigTransfer";+import { buildOracleTnsConnectionString, parseOracleTnsConnectionString } from "./oracleTnsConnection";++/**+ * An Oracle TNS connection stores its alias in `database` and the+ * `jdbc:oracle:thin:@<alias>?TNS_ADMIN=<dir>` string that resolves it in+ * `connection_string`. A plaintext export must keep that directory: without it+ * a re-imported connection cannot resolve the alias and has to be reconfigured+ * (issue #12672). Credentials still live in their own fields, so the alias and+ * the directory are safe to keep — nothing else is.+ */+describe("Oracle TNS plaintext exports", () => {+ const tnsAdmin = "C:\\oracle network\\admin";+ const tnsConnectionString = buildOracleTnsConnectionString("DBX_FAILOVER", tnsAdmin);++ function tnsConnection(overrides: Record<string, unknown> = {}) {+ return {+ id: "tns",+ name: "prod",+ db_type: "oracle" as const,+ host: "10.0.0.1",+ port: 1521,+ username: "scott",+ password: "tiger",+ database: "DBX_FAILOVER",+ oracle_connection_type: "tns" as const,+ driver_profile: "oracle",+ connection_string: tnsConnectionString,+ ...overrides,+ };+ }++ it("keeps the TNS_ADMIN directory that resolves the alias", () => {+ const exported = scrubConnectionForPlaintextExport(tnsConnection());++ expect(exported.connection_string).toBe(tnsConnectionString);+ expect(exported.database).toBe("DBX_FAILOVER");+ expect(parseOracleTnsConnectionString(exported.connection_string)).toEqual({ alias: "DBX_FAILOVER", tnsAdmin });+ });++ it("still removes the stored password", () => {+ const exported = scrubConnectionForPlaintextExport(tnsConnection());++ expect(exported.password).toBe("");+ expect(JSON.stringify(exported)).not.toContain("tiger");+ });++ it("re-imports a re-usable connection instead of an alias that cannot resolve", () => {+ const exported = scrubConnectionForPlaintextExport(tnsConnection());+ const parsed = parseConnectionConfigObject(JSON.parse(JSON.stringify({ connections: [exported] })));+ const imported = prepareConnectionConfigImport(parsed, [], [], () => "imported-id");++ expect(imported.connections[0]?.connection_string).toBe(tnsConnectionString);+ expect(parseOracleTnsConnectionString(imported.connections[0]?.connection_string)).toEqual({ alias: "DBX_FAILOVER", tnsAdmin });+ });++ it("keeps dropping every connection string that is not a TNS alias", () => {+ const exportedPostgres = scrubConnectionForPlaintextExport(tnsConnection({ db_type: "postgres", connection_string: "jdbc:postgresql://scott:tiger@host/db" }));+ const exportedUrl = scrubConnectionForPlaintextExport(tnsConnection({ connection_string: "postgres://scott:tiger@host/db" }));+ const exportedServiceName = scrubConnectionForPlaintextExport(tnsConnection({ oracle_connection_type: "service_name", connection_string: tnsConnectionString }));++ expect(exportedPostgres.connection_string).toBeUndefined();+ expect(exportedUrl.connection_string).toBeUndefined();+ expect(exportedServiceName.connection_string).toBeUndefined();+ });++ // The JDBC layer reads a query parameter as a credential when its *decoded*,+ // trimmed, lowercased name is `user` or `password`+ // (DbxJdbcPlugin.extractJdbcUrlCredentials). Matching raw names lets these through.+ it("drops every credential parameter, however its name is encoded", () => {+ const credentialStrings = [`${tnsConnectionString}&user=scott&password=tiger`, `${tnsConnectionString}&%70assword=tiger`, `${tnsConnectionString}&+password=tiger`, `${tnsConnectionString}&password%20=tiger`, `${tnsConnectionString}&%75ser=scott`];++ for (const connectionString of credentialStrings) {+ const exported = scrubConnectionForPlaintextExport(tnsConnection({ connection_string: connectionString }));++ expect(exported.connection_string).toBe(tnsConnectionString);+ expect(exported.connection_string).not.toContain("tiger");+ expect(exported.connection_string).not.toContain("scott");+ }+ });++ it("drops a TNS alias with no TNS_ADMIN directory to preserve", () => {+ const exported = scrubConnectionForPlaintextExport(tnsConnection({ connection_string: "jdbc:oracle:thin:@DBX_FAILOVER" }));++ expect(exported.connection_string).toBeUndefined();+ expect(exported.database).toBe("DBX_FAILOVER");+ });++ it("does not mutate the connection it was handed", () => {+ const source = tnsConnection({ connection_string: `${tnsConnectionString}&password=tiger` });+ scrubConnectionForPlaintextExport(source);++ expect(source.connection_string).toBe(`${tnsConnectionString}&password=tiger`);+ expect(source.password).toBe("tiger");+ });+});diff --git a/apps/desktop/src/lib/connection/connectionConfigTransfer.ts b/apps/desktop/src/lib/connection/connectionConfigTransfer.tsindex bf07f5d818..d66ed45c69 100644--- a/apps/desktop/src/lib/connection/connectionConfigTransfer.ts+++ b/apps/desktop/src/lib/connection/connectionConfigTransfer.ts@@ -1,5 +1,6 @@import type { ConnectionConfig, SidebarLayout, TunnelProfile } from "@/types/database";import { filterSidebarLayoutByConnectionIds as filterLayoutByConnectionIds, remapSidebarLayoutConnectionIds } from "@/lib/sidebar/sidebarLayout";+import { buildOracleTnsConnectionString, parseOracleTnsConnectionString } from "@/lib/connection/oracleTnsConnection";export type ConnectionExportProtection = { mode: "encrypted"; passphrase: string } | { mode: "plaintext" };@@ -66,7 +67,12 @@ export function scrubConnectionForPlaintextExport(connection: ConnectionConfig):scrubbed.password = "";scrubbed.url_params = scrubUrlParams(scrubbed.url_params);scrubbed.init_script = undefined;- scrubbed.connection_string = undefined;+ // An Oracle TNS connection keeps its alias and the TNS_ADMIN directory that+ // resolves it in `connection_string`. Blanking it drops the directory, so a+ // re-imported link cannot resolve the alias and has to be reconfigured from+ // scratch (issue #12672). The value DBX builds carries no credentials, and+ // the guard below refuses to keep anything else.+ scrubbed.connection_string = preservedOracleTnsConnectionString(connection);scrubbed.redis_sentinel_password = "";scrubbed.connection_secrets = {};scrubbed.transport_layers = (scrubbed.transport_layers ?? []).map((layer) => {@@ -128,6 +134,26 @@ function scrubUrlParams(value: string | undefined): string | undefined {.join("&");}+/**+ * The only `connection_string` a plaintext bundle keeps: a DBX-built Oracle TNS+ * string (`jdbc:oracle:thin:@<alias>?TNS_ADMIN=<dir>`), which holds no+ * credentials of its own — username and password live in their own fields.+ * Anything else (JDBC URLs, DSNs, ad-hoc strings) is credential-bearing and is+ * still dropped.+ */+function preservedOracleTnsConnectionString(connection: ConnectionConfig): string | undefined {+ if (connection.db_type !== "oracle" || connection.oracle_connection_type !== "tns") return undefined;+ const parsed = parseOracleTnsConnectionString(connection.connection_string);+ if (!parsed?.tnsAdmin) return undefined;+ // Rebuild the string from the only two fields a plaintext bundle may carry+ // instead of forwarding the stored one. A query name only has to *decode* to+ // `user`/`password` to be read as a credential by the JDBC layer, which decodes+ // every name with URLDecoder and trims it (`?%70assword=`, `?+password=`,+ // `?password%20=`), so matching names in the raw text cannot prove the string+ // credential-free. Rebuilding drops every parameter but TNS_ADMIN.+ return buildOracleTnsConnectionString(parsed.alias, parsed.tnsAdmin);+}+export function buildConnectionConfigBundle(connections: ConnectionConfig[], layout: SidebarLayout | null | undefined, tunnelProfiles: TunnelProfile[], selectedIds?: Iterable<string>): ConnectionConfigBundle {const selectedConnections = filterConnectionsByIds(connections, selectedIds);const selectedConnectionIds = selectedConnections.map((connection) => connection.id);