From 6f1a5b427e9c364363dda0f6fa78c6be856be7b8 Mon Sep 17 00:00:00 2001 From: Nicholas Ellul <15018469+NEllusion@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:55:23 +0000 Subject: [PATCH] fix(security): verify PlanetScale TLS in drizzle-kit configs (SEC-1104) The console and stats drizzle configs passed ssl: { rejectUnauthorized: false } to mysql2, so migrations and studio accepted any certificate. Setting rejectUnauthorized: true alone checks the chain but not the hostname: mysql2 only checks the hostname with verifyIdentity, and drizzle-kit 1.0.0-rc.2 strips that key from dbCredentials.ssl. Pass the credentials as a URL whose ssl parameter mysql2 parses directly, with both rejectUnauthorized and verifyIdentity set. --- packages/console/core/drizzle.config.ts | 13 +++++-------- packages/stats/core/drizzle.config.ts | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/console/core/drizzle.config.ts b/packages/console/core/drizzle.config.ts index 0b7c4417e809..dab3df03d95d 100644 --- a/packages/console/core/drizzle.config.ts +++ b/packages/console/core/drizzle.config.ts @@ -1,6 +1,10 @@ import { Resource } from "sst" import { defineConfig } from "drizzle-kit" +// drizzle-kit drops ssl options it does not list, including mysql2's verifyIdentity, and mysql2 skips the +// hostname check without it. Options in the URL reach mysql2 unchanged. +const ssl = encodeURIComponent(JSON.stringify({ rejectUnauthorized: true, verifyIdentity: true })) + export default defineConfig({ out: "./migrations/", strict: true, @@ -8,13 +12,6 @@ export default defineConfig({ verbose: true, dialect: "mysql", dbCredentials: { - database: Resource.Database.database, - host: Resource.Database.host, - user: Resource.Database.username, - password: Resource.Database.password, - port: Resource.Database.port, - ssl: { - rejectUnauthorized: false, - }, + url: `mysql://${encodeURIComponent(Resource.Database.username)}:${encodeURIComponent(Resource.Database.password)}@${Resource.Database.host}:${Resource.Database.port}/${Resource.Database.database}?ssl=${ssl}`, }, }) diff --git a/packages/stats/core/drizzle.config.ts b/packages/stats/core/drizzle.config.ts index 6fca8235afbd..aeb30c6da83e 100644 --- a/packages/stats/core/drizzle.config.ts +++ b/packages/stats/core/drizzle.config.ts @@ -1,6 +1,10 @@ import { Resource } from "sst/resource" import { defineConfig } from "drizzle-kit" +// drizzle-kit drops ssl options it does not list, including mysql2's verifyIdentity, and mysql2 skips the +// hostname check without it. Options in the URL reach mysql2 unchanged. +const ssl = encodeURIComponent(JSON.stringify({ rejectUnauthorized: true, verifyIdentity: true })) + export default defineConfig({ dialect: "mysql", schema: ["./src/database/schema.ts"], @@ -9,13 +13,6 @@ export default defineConfig({ strict: true, verbose: true, dbCredentials: { - database: Resource.StatsDatabase.database, - host: Resource.StatsDatabase.host, - user: Resource.StatsDatabase.username, - password: Resource.StatsDatabase.password, - port: Resource.StatsDatabase.port, - ssl: { - rejectUnauthorized: false, - }, + url: `mysql://${encodeURIComponent(Resource.StatsDatabase.username)}:${encodeURIComponent(Resource.StatsDatabase.password)}@${Resource.StatsDatabase.host}:${Resource.StatsDatabase.port}/${Resource.StatsDatabase.database}?ssl=${ssl}`, }, })