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(oracle): keep JDBC credentials verbatim and hide unsafe ones

弈秋c3f1af515761
diff --git a/apps/desktop/src/lib/__tests__/connection/connectionUrlBuilder.spec.ts b/apps/desktop/src/lib/__tests__/connection/connectionUrlBuilder.spec.ts
index fba47bc1ab..5058a47c60 100644
--- a/apps/desktop/src/lib/__tests__/connection/connectionUrlBuilder.spec.ts
+++ b/apps/desktop/src/lib/__tests__/connection/connectionUrlBuilder.spec.ts
@@ -202,6 +202,27 @@ describe("buildConnectionUrlCopy JDBC URL", () => {
expect(buildConnectionUrlCopy({ ...oracle, oracle_connection_type: "sid" }, "jdbcUrl")).toBe("jdbc:oracle:thin:@ora.example.com:1521:ORCLPDB1");
});
+ it("keeps Oracle credentials verbatim when they are safe to embed", () => {
+ const oracle = config({ db_type: "oracle", host: "ora.example.com", port: 1521, database: "ORCLPDB1", username: "app_user", password: "p^ss%40#y" });
+ expect(buildConnectionUrlCopy(oracle, "jdbcUrlWithCredentials")).toBe("jdbc:oracle:thin:@//ora.example.com:1521/ORCLPDB1?user=app_user&password=p^ss%40#y");
+ expect(connectionUrlCopyFormats(oracle)).toContain("jdbcUrlWithCredentials");
+ });
+
+ it("omits the Oracle with-credentials item when the password would break the property grammar", () => {
+ const oracle = config({ db_type: "oracle", host: "ora.example.com", port: 1521, database: "ORCLPDB1", username: "app_user", password: "p@ss&word" });
+ expect(buildConnectionUrlCopy(oracle, "jdbcUrlWithCredentials")).toBeNull();
+ expect(connectionUrlCopyFormats(oracle)).not.toContain("jdbcUrlWithCredentials");
+ // The plain JDBC URL without credentials stays available.
+ expect(buildConnectionUrlCopy(oracle, "jdbcUrl")).toBe("jdbc:oracle:thin:@//ora.example.com:1521/ORCLPDB1");
+ });
+
+ it("omits the Oracle with-credentials item when the username would break the property grammar", () => {
+ const oracle = config({ db_type: "oracle", host: "ora.example.com", port: 1521, database: "ORCLPDB1", username: "app@user", password: "secret" });
+ expect(buildConnectionUrlCopy(oracle, "jdbcUrlWithCredentials")).toBeNull();
+ expect(connectionUrlCopyFormats(oracle)).not.toContain("jdbcUrlWithCredentials");
+ expect(buildConnectionUrlCopy(oracle, "jdbcUrl")).toBe("jdbc:oracle:thin:@//ora.example.com:1521/ORCLPDB1");
+ });
+
it("redacts explicit jdbc: strings for the plain item and keeps them verbatim for the credentials item", () => {
const jdbcConfig = config({ db_type: "jdbc", host: "", port: 0, username: "", password: "", database: undefined, connection_string: "jdbc:hive2://zk1:2181,zk2:2181/default;serviceDiscoveryMode=zooKeeper;password=s3cret" });
expect(buildConnectionUrlCopy(jdbcConfig, "jdbcUrl")).toBe("jdbc:hive2://zk1:2181,zk2:2181/default;serviceDiscoveryMode=zooKeeper;password=***");
diff --git a/apps/desktop/src/lib/connection/connectionUrlBuilder.ts b/apps/desktop/src/lib/connection/connectionUrlBuilder.ts
index 3ed05002fc..106440f62d 100644
--- a/apps/desktop/src/lib/connection/connectionUrlBuilder.ts
+++ b/apps/desktop/src/lib/connection/connectionUrlBuilder.ts
@@ -297,6 +297,18 @@ function jdbcCredentialParams(config: ConnectionUrlCopyConfig, withCredentials:
* Returns `undefined` when the type is not a special dialect, `null` when the
* dialect is special but cannot be built from this config.
*/
+/**
+ * Oracle Easy Connect Plus property values are not URI-decoded by the driver,
+ * so percent-encoding credentials produces a URL that silently changes the
+ * password. Only values that can be embedded verbatim without breaking the
+ * `?key=value&key=value` grammar are safe to offer as a with-credentials URL.
+ */
+const ORACLE_SAFE_PROPERTY_VALUE = /^[A-Za-z0-9^%#_\-+!*'()]+$/;
+
+function isOracleSafePropertyValue(value: string): boolean {
+ return ORACLE_SAFE_PROPERTY_VALUE.test(value);
+}
+
function buildSpecialJdbcUrl(config: ConnectionUrlCopyConfig, database: string, withCredentials: boolean): string | null | undefined {
const host = config.host?.trim() ?? "";
const rawParams = (config.url_params ?? "").trim();
@@ -323,7 +335,18 @@ function buildSpecialJdbcUrl(config: ConnectionUrlCopyConfig, database: string,
return explicit ? explicit : null;
}
const portPart = shouldAppendPort(config) ? `:${config.port}` : "";
- const query = joinNonEmpty("&", [...credentials, rawParams.replace(/^[?&]+/, "")]);
+ // Oracle Easy Connect Plus does not URI-decode credentials. Offer the
+ // with-credentials item only when the stored values can be embedded
+ // verbatim; otherwise the copied URL would silently change the password.
+ let oracleCredentials: string[] = [];
+ if (withCredentials) {
+ const user = effectiveUsername(config);
+ const password = config.password ?? "";
+ if (user && !isOracleSafePropertyValue(user)) return null;
+ if (password && !isOracleSafePropertyValue(password)) return null;
+ oracleCredentials = jdbcCredentialParams(config, true, (value) => value);
+ }
+ const query = joinNonEmpty("&", [...oracleCredentials, rawParams.replace(/^[?&]+/, "")]);
if (connectionType === "sid") {
return `jdbc:oracle:thin:@${formatHostForUrl(host)}${portPart}:${database}${query ? `?${query}` : ""}`;
}