Skip to content

fix: consume libpq SSL connection string parameters instead of forwarding them - #1551

Merged
sorenbs merged 2 commits into
mainfrom
fix/1433-sslrootcert
Jul 18, 2026
Merged

fix: consume libpq SSL connection string parameters instead of forwarding them#1551
sorenbs merged 2 commits into
mainfrom
fix/1433-sslrootcert

Conversation

@sorenbs

@sorenbs sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Fixes #1433

Root cause

postgres.js copies every URL query parameter it doesn't recognize into the startup-packet runtime parameters sent to the server. sslrootcert, sslcert, sslkey, and sslpassword aren't in its known-options list, so PostgreSQL rejects the connection with unrecognized configuration parameter "sslrootcert".

Fix

New createPostgresJSConnectionConfig(connectionString, { readFile? }) exported from @prisma/studio-core/data/postgresjs. It returns a stripped connection string plus postgres.js options:

  • sslrootcert → TLS ca (with system → Node system trust store, full verification, per libpq)
  • sslcert/sslkeycert/key file contents; sslpasswordpassphrase
  • sslmode mapped to libpq-compatible TLS semantics (disable, verify-full, verify-ca, require/prefer/allow, incl. the upgrade-to-verify-ca rule when a root cert is provided)
  • All five params stripped from the URL; other params preserved; unreadable files throw descriptive errors naming the param and path

Verification

15 new tests, the first reproducing the raw forwarding against real postgres.js (failing-first). Typecheck/lint clean; changeset included; documented in FEATURES.md.

Follow-up: the Prisma CLI (prisma/prisma) should call this helper before constructing its postgres.js client so prisma studio users get the fix.

🤖 Generated with Claude Code

PostgreSQL connection strings carrying the standard libpq SSL
parameters (sslrootcert, sslcert, sslkey, sslpassword) failed with
"unrecognized configuration parameter" errors because postgres.js
forwards unknown URL query parameters to the server as runtime
configuration parameters.

Add createPostgresJSConnectionConfig to
@prisma/studio-core/data/postgresjs, which consumes these parameters
client-side: certificate files are read from disk and mapped to TLS
options (honoring sslmode verification semantics, including the libpq
rule that a root certificate upgrades sslmode=require to verify-ca and
that sslrootcert=system forces full verification), and the parameters
are stripped from the connection string handed to postgres().

The ppg-dev demo runtime now routes external database URLs through the
helper.

Fixes #1433

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 26bf3755-94ae-4152-af8a-8a41f79ec456

📥 Commits

Reviewing files that changed from the base of the PR and between 503b0b6 and 4b2b5fb.

📒 Files selected for processing (3)
  • FEATURES.md
  • data/postgresjs/connection-options.test.ts
  • data/postgresjs/connection-options.ts

Walkthrough

Adds createPostgresJSConnectionConfig to consume PostgreSQL SSL parameters, read certificate files, configure TLS verification, and remove handled parameters from connection strings. Exports the helper and related types, integrates them into the default PostgresJS client creation path, adds comprehensive tests, and documents the behavior in feature and changeset files.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: consuming libpq SSL parameters instead of forwarding them to postgres.js.
Description check ✅ Passed The description is directly about the SSL parameter forwarding bug and the new client-side fix.
Linked Issues check ✅ Passed The PR addresses #1433 by supporting sslrootcert and related SSL parameters without forwarding them to the server.
Out of Scope Changes check ✅ Passed The tests, docs, changeset, and demo wiring all support the same SSL-parameter fix and do not appear out of scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1433-sslrootcert
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/1433-sslrootcert

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Compute preview deployed.

Branch: fix/1433-sslrootcert
Service: fix-1433-sslrootcert
Preview: https://ls2rn1zpwv33pvy69x7rt0hv.cdg.prisma.build

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@data/postgresjs/connection-options.test.ts`:
- Around line 202-218: Update createPostgresJSConnectionConfig to reject
sslrootcert=system when sslmode is require, verify-ca, disable, allow, or
prefer, matching libpq’s invalid-combination behavior instead of rewriting or
disabling TLS. Preserve the existing full-verification behavior for the
supported default/verify-full case, and add test coverage for each rejected
sslmode combination.
- Around line 262-272: Update the fixture path construction in the “reads ssl
files from disk by default” test to convert the file URL with fileURLToPath
instead of using URL.pathname, preserving correct decoding and cross-platform
behavior. Add or reuse the appropriate fileURLToPath import and keep the
existing SSL assertion unchanged.

In `@data/postgresjs/connection-options.ts`:
- Around line 91-103: Update the sslMode handling in the connection-string
parsing flow to validate the extracted value before deleting it or constructing
the stripped connection string. Reject any non-null sslmode value that is not
supported by the implementation, rather than silently removing it; preserve the
existing sslMode === "disable" behavior and normal handling for supported
values.
- Around line 141-151: The SSL configuration logic must preserve libpq’s
plaintext-first/fallback negotiation for sslMode “allow” and “prefer” even when
SSL files are configured. Update the surrounding connection-options handling so
these modes are not forced into an always-SSL postgres.js configuration, or
explicitly reject the unsupported combinations; keep existing verification
behavior for “verify-full” and “verify-ca” unchanged.

In `@FEATURES.md`:
- Around line 10-11: Update the PostgreSQL SSL documentation to clarify that
standalone sslmode is not stripped and remains available for postgres.js. State
that only SSL file parameters are removed, along with an accompanying sslmode
when those parameters are translated into client-side TLS configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 73f7ab00-02cd-4249-967f-0a7cb5d3b6e9

📥 Commits

Reviewing files that changed from the base of the PR and between 81354ff and 503b0b6.

📒 Files selected for processing (6)
  • .changeset/fix-sslrootcert-forwarding.md
  • FEATURES.md
  • data/postgresjs/connection-options.test.ts
  • data/postgresjs/connection-options.ts
  • data/postgresjs/index.ts
  • demo/ppg-dev/runtime.ts

Comment thread data/postgresjs/connection-options.test.ts
Comment thread data/postgresjs/connection-options.test.ts
Comment thread data/postgresjs/connection-options.ts Outdated
Comment thread data/postgresjs/connection-options.ts
Comment thread FEATURES.md Outdated
- Reject sslrootcert=system combined with any sslmode weaker than
  verify-full, matching libpq's "weak sslmode disallowed with system
  CA" behavior, instead of silently rewriting verification or letting
  sslmode=disable turn TLS off.
- Validate sslmode against the known libpq set (disable, allow,
  prefer, require, verify-ca, verify-full) and throw a descriptive
  error on unrecognized values instead of silently dropping them.
- Reject sslmode=allow/prefer combined with SSL file parameters:
  postgres.js can only honor plaintext-fallback negotiation for its
  built-in string modes, not with custom TLS options, so failing fast
  beats silently forcing TLS on.
- Use fileURLToPath(import.meta.url) for the on-disk test fixture path.
- Clarify in FEATURES.md that only SSL file parameters (plus an
  accompanying sslmode) are stripped; a standalone sslmode stays in
  the URL for postgres.js.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sorenbs
sorenbs merged commit 3e1c902 into main Jul 18, 2026
3 checks passed
@sorenbs
sorenbs deleted the fix/1433-sslrootcert branch July 18, 2026 13:01
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.

unrecognized configuration parameter "sslrootcert"

1 participant