Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 8 min read Opinion mediumAdept

Why Postgres needs better connection security defaults

Postgres's widely used sslmode=require encrypts connections but never authenticates the server, leaving them open to trivial MITM attacks via a self-signed certificate and DNS poisoning. The Postgres 16 option sslrootcert=system should verify servers against system CA roots, but it still fails on Windows because OpenSSL's default verify paths don't include the Windows certificate store, and it initially failed on Docker and several macOS builds. Neon's workaround is SCRAM-SHA-256-PLUS channel binding (channel_binding=require), where the client signs a hash of the server certificate with password-derived proof, defeating MITM even with rogue CA-issued certs. It works with libpq-based clients but is ignored by most non-libpq drivers. The post argues Postgres should rename require to something like insecure and add a secure default combining verify-full with system roots.

Related posts

  • MITM attacks are easier to avoid with psql (Postgres) 16

    Neon mediumAdept

    Postgres 16's psql adds `sslrootcert=system`, which uses the OS's trusted CA store and implies `sslmode=verify-full`. Together with the new `require_auth` option, it closes a MITM hole that `sslmode=require` leaves open. `require` encrypts the connection but never checks the server certificate. An attacker who spoofs DNS can then request a cleartext password, and libpq will hand it over even if the real server uses SCRAM-SHA-256. A proof-of-concept Ruby proxy under 100 lines, combined with bettercap DNS spoofing, captured credentials and proxied the session in a few hours. The recommendation is to connect with `sslrootcert=system` (or `verify-full` plus a CA bundle on older psql) and set `PGSSLROOTCERT`, `PGSSLMODE` and `PGREQUIREAUTH=scram-sha-256` as environment defaults.

  • Shipping psql without psql: a pure-TypeScript Postgres client in neonctl

    Neon mediumAdept

    neonctl now embeds a pure-TypeScript reimplementation of psql that activates when no native psql is on the PATH. It covers the REPL, all backslash commands, output formats, connection options, SCRAM and TLS, with no native dependencies, and it was written almost entirely by Claude Code under human review. Correctness rests on a conformance harness that fetches PostgreSQL's own regression scripts and diffs output byte-for-byte against a containerized server across PG 14–18, plus an adversarial security review that caught plausible-looking bugs such as a silent sslmode downgrade and a skippable SCRAM mutual-auth check. Lessons include regression-suite hidden setup (prerequisite tables, injected settings), fixing the first diff mismatch rather than the last, and runtime-dependent TLS behavior (BoringSSL under Bun vs OpenSSL under Node).

  • How Does psql -h pg.neon.tech Work?

    Neon mediumAdept

    Neon's passwordless `psql -h pg.neon.tech` connects to a "Link Proxy", a server that speaks the Postgres wire protocol, rather than to a real Postgres instance. The proxy answers the client's startup message with AuthenticationOk followed by a NoticeResponse, which psql prints as a welcome message containing an auth URL. Visiting that URL opens a control-plane UI where the user picks a project and endpoint. The control plane then sends the connection details for that request ID back to the data-plane proxy, which connects to the chosen compute and relays all traffic to psql.

  • Security Disclosure Recommendation: Rotate PostgreSQL Database Credentials

    Railway mediumAdept

    After Railway's October 21, 2026 security disclosure, PostgreSQL users on the Railway template should regenerate the database password from the Database View, which changes it inside PostgreSQL and updates POSTGRES_PASSWORD and the variables that reference it in one step. Dependent services must then be redeployed because containers only read variables at startup, and pasted connection strings should be replaced with reference variables. Afterwards, verify with pg_stat_activity, terminate unknown sessions, disable public TCP proxy access if unneeded, and check audit logs, failed-auth logs, unexpected roles and modified data for misuse. Editing password variables or running ALTER USER by hand leaves the variable and the database out of sync, so avoid it.

  • Better Postgres with Prisma Experience

    Neon mediumAdept

    Prisma users on Neon can now use a single pooled Postgres connection string for both serverless queries and schema migrations, replacing separate pooled, direct and shadow database URLs. PgBouncer 1.22.0 added support for prepared statements and DISCARD ALL/DEALLOCATE ALL, which fixes the "prepared statement already exists" errors `prisma migrate` used to hit through the pooler, and the `pgbouncer=true` parameter is no longer needed. Neon also enabled role and database management via SQL, and Prisma 5.10.0 added DROP DATABASE WITH (FORCE), so `prisma migrate dev` can create and drop its own shadow database without manual setup.

The quest for software engineering knowledge.

Look:
Layout: