Skip to content

Reject sslrootcert and unknown sslmode values in PostgreSQL DSNs - #442

Merged
tianzhou merged 1 commit into
mainfrom
claude/verdict-issue-439-cmg9zq
Sep 28, 2026
Merged

tianzhou merged 1 commit into
mainfrom
claude/verdict-issue-439-cmg9zq

Conversation

@tianzhou

Copy link
Copy Markdown
Member

Follow-up to bytebase/dbhub#441.

Problem

A DSN passed with --dsn or the DSN env var skips TOML validation, so the PostgreSQL DSN parser is the only check. The parser silently dropped sslrootcert unless sslmode was verify-ca or verify-full:

DSN Before
sslmode=require&sslrootcert=ca.pem Encrypted, server not verified, CA never read
sslmode=disable&sslrootcert=ca.pem Plaintext, CA ignored
sslrootcert=ca.pem (no sslmode) No TLS, CA ignored

The first case is the dangerous one. libpq treats require plus a root CA as verify-ca, so a connection string copied from psql expects the server to be verified. DBHub connected unverified and gave no warning. The same DSN inside a TOML [[sources]] was already rejected.

The parser had a second silent fallback. An unrecognised sslmode (libpq's allow/prefer, or a typo) became ssl: true, which verifies against the system CA store and never falls back to plaintext. That is the opposite of what allow/prefer mean. TOML already rejects unknown modes.

Change

In src/connectors/postgres/index.ts:

  • sslrootcert with sslmode=require, disable or no sslmode now throws: sslrootcert requires sslmode 'verify-ca' or 'verify-full' (got '…'). Use sslmode=verify-ca …
  • Any sslmode other than disable / require / verify-ca / verify-full now throws Unsupported sslmode '…'. Valid values: …. The ssl: true fallback is removed.

Both rules match what TOML validation already enforces, so the DSN and TOML paths now accept exactly the same inputs. This is the same fail-fast choice #441 made for sslcert/sslkey.

Behaviour change: a --dsn that uses either combination now fails at startup with a clear message instead of connecting. That's intended, but worth a line in the release notes.

Tests / docs

  • dsn-parser.test.ts: replaced the two tests that asserted the silent-ignore behaviour. The new tests cover rejection with require, disable and unset, rejection of prefer/allow/verify_full/true, and that no sslmode still leaves ssl unset.
  • docs/config/command-line.mdx: the sslrootcert row, plus a note on how DBHub differs from libpq here (no automatic require → verify-ca upgrade, no allow/prefer).
  • pnpm test:unit: 1156 passed; pnpm run build OK.

🤖 Generated with Claude Code

https://claude.ai/code/session_012UzToxWXzC7oQ9xMnhM192


Generated by Claude Code

On the DSN-only path (--dsn / DSN env), which bypasses TOML validation,
the PostgreSQL parser silently dropped sslrootcert unless sslmode was
verify-ca or verify-full. libpq treats require + a root CA as verify-ca,
so a connection string copied from psql connected with no server
verification and no warning. The same DSN inside a TOML source was
already rejected.

- sslrootcert with sslmode=require, disable or unset now fails with a
  message pointing at sslmode=verify-ca, matching TOML validation.
- Unrecognised sslmode values (libpq's allow/prefer, typos) no longer
  fall through to `ssl: true`, which verified against the system CA store
  and never fell back to plaintext. They are rejected with the list of
  valid modes, as TOML already does.

Replaces the two tests that asserted the silent-ignore behaviour and
documents the difference from libpq in docs/config/command-line.mdx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012UzToxWXzC7oQ9xMnhM192
Copilot AI lite review requested due to automatic review settings September 28, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Explicitly empty sslmode and sslrootcert values bypass validation and need coverage.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR makes PostgreSQL DSN SSL validation consistent with TOML validation and documents the supported behavior.

Changes:

  • Rejects unsupported sslmode values.
  • Rejects incompatible sslrootcert combinations.
  • Updates tests and command-line documentation.
File Summary
src/​connectors/​postgres/​index.ts Adds strict SSL mode and root certificate validation.
src/​connectors/​__tests__/​dsn-parser.test.ts Tests rejection behavior and defaults.
docs/​config/​command-line.mdx Documents PostgreSQL SSL restrictions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/connectors/postgres/index.ts
@tianzhou
tianzhou merged commit f1fdbc3 into main Sep 28, 2026
4 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.

3 participants