Skip to content

fix(db-postgres): bump drizzle-orm to 0.45.2 to resolve an SQL injection vulnerability and pg to 8.20.0#16168

Merged
r1tsuu merged 6 commits intopayloadcms:mainfrom
siimsams:upgrade-drizzle-and-pg-versions
Apr 9, 2026
Merged

fix(db-postgres): bump drizzle-orm to 0.45.2 to resolve an SQL injection vulnerability and pg to 8.20.0#16168
r1tsuu merged 6 commits intopayloadcms:mainfrom
siimsams:upgrade-drizzle-and-pg-versions

Conversation

@siimsams
Copy link
Copy Markdown
Contributor

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

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

@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
Contributor 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
r1tsuu
r1tsuu previously approved these changes Apr 7, 2026
@siimsams
Copy link
Copy Markdown
Contributor Author

siimsams commented Apr 7, 2026

Thank you for taking a look and approving. I'm wondering if these failing tests are flaky or did I break something? 🤔

@r1tsuu r1tsuu changed the title fix(db-postgres): patch SQL injection vulnerability by upgrading drizzle-orm and pg fix(db-postgres): bump drizzle-orm to 0.45.2 to resolve an SQL injection vulnerability and pg to 8.20.0 Apr 7, 2026
@r1tsuu r1tsuu enabled auto-merge (squash) April 7, 2026 14:33
@r1tsuu r1tsuu self-assigned this Apr 7, 2026
auto-merge was automatically disabled April 7, 2026 17:31

Head branch was pushed to by a user without write access

@siimsams
Copy link
Copy Markdown
Contributor Author

siimsams commented Apr 7, 2026

I solved the merge conflicts in package-lock.yaml.

EDIT:
I did it again. Messed up the PR message so force pushed the correct message.

@siimsams siimsams requested a review from r1tsuu April 7, 2026 18:39
@siimsams siimsams force-pushed the upgrade-drizzle-and-pg-versions branch from e5f4d6d to 8ef5efe Compare April 7, 2026 20:02
@siimsams
Copy link
Copy Markdown
Contributor Author

siimsams commented Apr 8, 2026

@r1tsuu can this be merged now that the release has happened?

@r1tsuu r1tsuu enabled auto-merge (squash) April 9, 2026 14:00
@siimsams
Copy link
Copy Markdown
Contributor Author

siimsams commented Apr 9, 2026

Thank you! ❤️

@r1tsuu r1tsuu merged commit af1a932 into payloadcms:main Apr 9, 2026
163 checks passed
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