TLS query parameters (sslmode, ssl) in clientUrl are ignored, so the connection is not encrypted
Description
Impact
The clientUrl option (also set via MIKRO_ORM_CLIENT_URL) is split into separate connection options (host, port, user, password, database) in the PostgreSQL, MySQL and MariaDB drivers. The query string was not processed apart from the schema parameter, so TLS parameters such as sslmode, sslrootcert or ssl had no effect.
A URL like postgresql://user:password@db.example.com:5432/app?sslmode=verify-full therefore opened an unencrypted connection, without any warning or error, as long as the database server accepted one. An attacker able to intercept the traffic between the application and the database could read or modify it, including the credentials sent during authentication.
Applications are affected only if all of the following apply:
- the connection is configured via
clientUrlwith TLS parameters in its query string, - TLS is not configured via
driverOptions, - the database server accepts unencrypted connections.
Servers that enforce TLS reject such a connection, so the misconfiguration is visible there right away. The MongoDB and Oracle drivers pass the clientUrl to the client as is and are not affected.
Patches
Fixed in 7.2.13 and 6.6.20. The TLS parameters from clientUrl are now mapped to the ssl option of the database client: sslmode, ssl, sslcert, sslkey and sslrootcert in PostgreSQL, and ssl in MySQL and MariaDB. In MySQL and MariaDB, the unsupported sslmode parameter now throws an error.
After upgrading, a connection that used to be established without encryption will negotiate TLS, and will fail if the server does not support it.
Workarounds
Configure TLS via driverOptions, which takes precedence over the URL:
MikroORM.init({
clientUrl: 'postgresql://user:password@db.example.com:5432/app',
driverOptions: { ssl: true }, // `{ connection: { ssl: true } }` in v6
});Enforcing TLS on the database server also prevents the unencrypted connection.