Skip to content

fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and pg#16168

Open
siimsams wants to merge 1 commit intopayloadcms:mainfrom
siimsams:upgrade-drizzle-and-pg-versions
Open

fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and pg#16168
siimsams wants to merge 1 commit intopayloadcms:mainfrom
siimsams:upgrade-drizzle-and-pg-versions

Conversation

@siimsams
Copy link
Copy Markdown

@siimsams siimsams commented Apr 3, 2026

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 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@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.

@siimsams siimsams changed the title fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and migrating vercel-postgres to neon fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm, migrate deprecated vercel-postgres to neon Apr 3, 2026
@siimsams
Copy link
Copy Markdown
Author

siimsams commented Apr 3, 2026

I went a bit down a rabbit hole with this one.

The initial goal was just to use maxLifetimeSeconds from pg.Pool, but payload's pg type version was outdated. While looking into that, I checked the changelogs of pg and @types/pg and decided to upgrade to the latest version since I did not see any breaking changes.

After that, I noticed Drizzle had released a patch related to SQL injection, so I upgraded that as well. While doing that, I ran into type issues around @vercel/postgres and saw that it is deprecated, so I ended up addressing that too.

This ended up being a much larger set of changes than originally intended. Let me know or split this up yourself if needed.

@r1tsuu
Copy link
Copy Markdown
Member

r1tsuu commented Apr 3, 2026

Yeah let's make a PR which just updates PG and Drizzle, I'd like to review switching the package for vercel separately.

}
const pool = new VercelPool(options)
return drizzle({ client: pool, logger, schema: this.schema })
return drizzle({ client: pool as unknown as pg.Pool, logger, schema: this.schema })
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were needed as the types no longer match to the deprecated Vercel Postgres package.

Here are the changes fixing this uglyness.
siimsams#1

@siimsams siimsams changed the title fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm, migrate deprecated vercel-postgres to neon fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and pg Apr 5, 2026
@siimsams siimsams force-pushed the upgrade-drizzle-and-pg-versions branch from 58bfd66 to a13ef5d Compare April 5, 2026 08:12
@siimsams
Copy link
Copy Markdown
Author

siimsams commented Apr 5, 2026

@r1tsuu I split it out. The Neon one is here siimsams#1 I will switch base to payload as soon as this gets merged.

@siimsams siimsams changed the title fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and pg fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and pg Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants