Skip to content

Commit af1a932

Browse files
siimsamsr1tsuu
andauthored
fix(db-postgres): bump drizzle-orm to 0.45.2 to resolve an SQL injection vulnerability and pg to 8.20.0 (#16168)
### What? Upgrade `drizzle-orm` from 0.44.7 to 0.45.2 and `pg` from 8.16.3 to 8.20.0 (with `@types/pg` 8.10.2 → 8.20.0) across all database adapter packages. ### Why? **Security:** [`drizzle-orm@0.45.2`](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.2) patches an SQL injection vulnerability (CWE-89) in `sql.identifier()` and `sql.as()` where values were not properly escaped. **Maintenance:** Bringing `pg` / `@types/pg` current picks up upstream fixes and keeps the adapters aligned with the types the rest of the monorepo already resolves. The [`@vercel/postgres`](https://www.npmjs.com/package/@vercel/postgres) → [`@neondatabase/serverless`](https://www.npmjs.com/package/@neondatabase/serverless) migration has been split out into a separate PR for independent review. siimsams#1 ### How? - **`drizzle-orm` 0.44.7 → 0.45.2** in `db-postgres`, `db-sqlite`, `db-d1-sqlite`, `db-vercel-postgres`, `drizzle` - **`pg` 8.16.3 → 8.20.0** and **`@types/pg` 8.10.2 → 8.20.0** in `db-postgres`, `db-vercel-postgres`, `drizzle` - **`db-postgres/src/types.ts`:** Fix `PgDependency` type to `typeof import('pg').default` — `@types/pg@8.20.0` added an `index.d.mts` with ESM types where `PG` is a module-level declaration, making the old `typeof import('pg')` incompatible with the default import - **`db-vercel-postgres/src/connect.ts`:** Cast `client` to `pg.Pool` at the two `drizzle()` call sites. `drizzle-orm@0.45.2` tightened `NodePgClient` to `pg.Pool | PoolClient | Client`, and `VercelPool` extends `@neondatabase/serverless`'s `Pool` (not `pg`'s), so the cast is required to satisfy the stricter type while preserving runtime behavior. --------- Co-authored-by: Sasha Rakhmatulin <sasha@ritsuko.dev>
1 parent ac01e82 commit af1a932

9 files changed

Lines changed: 198 additions & 87 deletions

File tree

packages/db-d1-sqlite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@
7474
"@payloadcms/drizzle": "workspace:*",
7575
"console-table-printer": "2.12.1",
7676
"drizzle-kit": "0.31.7",
77-
"drizzle-orm": "0.44.7",
77+
"drizzle-orm": "0.45.2",
7878
"prompts": "2.4.2",
7979
"to-snake-case": "1.0.0",
8080
"uuid": "11.1.0"
8181
},
8282
"devDependencies": {
8383
"@payloadcms/eslint-config": "workspace:*",
84-
"@types/pg": "8.10.2",
84+
"@types/pg": "8.20.0",
8585
"@types/to-snake-case": "1.0.0",
8686
"payload": "workspace:*"
8787
},

packages/db-postgres/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@
7575
},
7676
"dependencies": {
7777
"@payloadcms/drizzle": "workspace:*",
78-
"@types/pg": "8.10.2",
78+
"@types/pg": "8.20.0",
7979
"console-table-printer": "2.12.1",
8080
"drizzle-kit": "0.31.7",
81-
"drizzle-orm": "0.44.7",
82-
"pg": "8.16.3",
81+
"drizzle-orm": "0.45.2",
82+
"pg": "8.20.0",
8383
"prompts": "2.4.2",
8484
"to-snake-case": "1.0.0",
8585
"uuid": "11.1.0"

packages/db-postgres/src/types.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1+
import type { DrizzleAdapter } from '@payloadcms/drizzle'
12
import type {
23
BasePostgresAdapter,
34
GenericEnum,
45
MigrateDownArgs,
56
MigrateUpArgs,
67
PostgresSchemaHook,
78
} from '@payloadcms/drizzle/postgres'
8-
import type { DrizzleAdapter } from '@payloadcms/drizzle/types'
9-
import type { DrizzleConfig, ExtractTablesWithRelations } from 'drizzle-orm'
9+
import type { DrizzleConfig } from 'drizzle-orm'
1010
import type { NodePgDatabase } from 'drizzle-orm/node-postgres'
11-
import type {
12-
PgDatabase,
13-
PgQueryResultHKT,
14-
PgSchema,
15-
PgTableFn,
16-
PgTransactionConfig,
17-
PgWithReplicas,
18-
} from 'drizzle-orm/pg-core'
11+
import type { PgSchema, PgTableFn, PgTransactionConfig, PgWithReplicas } from 'drizzle-orm/pg-core'
1912
import type { Pool, PoolConfig } from 'pg'
2013

21-
type PgDependency = typeof import('pg')
14+
type PgDependency = typeof import('pg').default
2215

2316
export type Args = {
2417
/**

packages/db-sqlite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@
7676
"@payloadcms/drizzle": "workspace:*",
7777
"console-table-printer": "2.12.1",
7878
"drizzle-kit": "0.31.7",
79-
"drizzle-orm": "0.44.7",
79+
"drizzle-orm": "0.45.2",
8080
"prompts": "2.4.2",
8181
"to-snake-case": "1.0.0",
8282
"uuid": "11.1.0"
8383
},
8484
"devDependencies": {
8585
"@payloadcms/eslint-config": "workspace:*",
86-
"@types/pg": "8.10.2",
86+
"@types/pg": "8.20.0",
8787
"@types/to-snake-case": "1.0.0",
8888
"payload": "workspace:*"
8989
},

packages/db-vercel-postgres/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@
7575
},
7676
"dependencies": {
7777
"@payloadcms/drizzle": "workspace:*",
78-
"@vercel/postgres": "^0.9.0",
78+
"@vercel/postgres": "^0.10.0",
7979
"console-table-printer": "2.12.1",
8080
"drizzle-kit": "0.31.7",
81-
"drizzle-orm": "0.44.7",
82-
"pg": "8.16.3",
81+
"drizzle-orm": "0.45.2",
82+
"pg": "8.20.0",
8383
"prompts": "2.4.2",
8484
"to-snake-case": "1.0.0",
8585
"uuid": "11.1.0"
8686
},
8787
"devDependencies": {
8888
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
8989
"@payloadcms/eslint-config": "workspace:*",
90-
"@types/pg": "8.10.2",
90+
"@types/pg": "8.20.0",
9191
"@types/to-snake-case": "1.0.0",
9292
"esbuild": "0.27.1",
9393
"payload": "workspace:*"

packages/db-vercel-postgres/src/connect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const connect: Connect = async function connect(
4242
// Passed the poolOptions if provided,
4343
// else have vercel/postgres detect the connection string from the environment
4444
this.drizzle = drizzle({
45-
client,
45+
client: client as pg.Pool,
4646
logger,
4747
schema: this.schema,
4848
})
@@ -55,7 +55,7 @@ export const connect: Connect = async function connect(
5555
connectionString,
5656
}
5757
const pool = new VercelPool(options)
58-
return drizzle({ client: pool, logger, schema: this.schema })
58+
return drizzle({ client: pool as unknown as pg.Pool, logger, schema: this.schema })
5959
})
6060
const myReplicas = withReplicas(this.drizzle, readReplicas as any)
6161
this.drizzle = myReplicas

packages/drizzle/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@
5959
"dependencies": {
6060
"console-table-printer": "2.12.1",
6161
"dequal": "2.0.3",
62-
"drizzle-orm": "0.44.7",
62+
"drizzle-orm": "0.45.2",
6363
"prompts": "2.4.2",
6464
"to-snake-case": "1.0.0",
6565
"uuid": "11.1.0"
6666
},
6767
"devDependencies": {
6868
"@libsql/client": "0.14.0",
6969
"@payloadcms/eslint-config": "workspace:*",
70-
"@types/pg": "8.10.2",
70+
"@types/pg": "8.20.0",
7171
"@types/to-snake-case": "1.0.0",
7272
"payload": "workspace:*"
7373
},

0 commit comments

Comments
 (0)