---
title: "MITM attacks are easier to avoid with psql (Postgres) 16"
description: "Postgres 16's psql adds `sslrootcert=system`, which uses the OS's trusted CA store and implies `sslmode=verify-full`."
url: "https://swe.quest/articles/mitm-attacks-are-easier-to-avoid-with-psql-postgres-16-ea4ca88c3d78880f"
canonical: "https://neon.com/blog/avoid-mitm-attacks-with-psql-postgres-16"
source: "Neon"
published: "2023-10-05"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["postgres","cryptography","security","identity-auth"]
---

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

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-10-05, 8 min read, How-to. Original: [https://neon.com/blog/avoid-mitm-attacks-with-psql-postgres-16](https://neon.com/blog/avoid-mitm-attacks-with-psql-postgres-16)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Cryptography](https://swe.quest/tags/cryptography.md) (Security)
- [Security](https://swe.quest/tags/security.md) (Security)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)

## Prerequisites

- TLS certificates and CAs ([easy posts on Cryptography](https://swe.quest/tags/cryptography.md?difficulty=easy))
- Postgres connection strings ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- DNS basics ([easy posts on DNS](https://swe.quest/tags/dns.md?difficulty=easy))

## Keywords

psql, Postgres 16, libpq, sslrootcert, sslmode, SCRAM-SHA-256, bettercap, Neon

## Related posts

- [Why Postgres needs better connection security defaults](https://swe.quest/articles/why-postgres-needs-better-connection-security-defaults-d78d4b6f863ed01c.md): Neon · 2025-06-25 · Medium · 8 min read · PostgreSQL, Cryptography, Identity & auth, Security
  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.
- [Shipping psql without psql: a pure-TypeScript Postgres client in neonctl](https://swe.quest/articles/shipping-psql-without-psql-a-pure-typescript-postgres-client-in-neonctl-621e0ac130c536d1.md): Neon · 2026-06-12 · Medium · 7 min read · PostgreSQL, TypeScript, Testing, AI for coding, Developer tools
  neonctl now embeds a pure-TypeScript reimplementation of psql that activates when no native psql is on the PATH.
- [Security Disclosure Recommendation: Rotate PostgreSQL Database Credentials](https://swe.quest/articles/security-disclosure-recommendation-rotate-postgresql-database-credentials-101ad2e32389050e.md): Railway · 2026-10-22 · Medium · 4 min read · PostgreSQL, Security, Identity & auth, Incidents & postmortems
  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.
- [Better Postgres with Prisma Experience](https://swe.quest/articles/better-postgres-with-prisma-experience-595f740758817ccf.md): Neon · 2024-03-07 · Medium · 4 min read · PostgreSQL, Schema migrations, Serverless, TypeScript
  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.
- [Defense in Depth for MCP Servers](https://swe.quest/articles/defense-in-depth-for-mcp-servers-841fdfa753be4c4a.md): Supabase · 2025-09-16 · Easy · 5 min read · AI agents, Application security, LLMs, PostgreSQL
  Stored prompt injection, where malicious instructions hidden in database rows trick an AI agent into reading private data and writing it somewhere visible, is a property of LLM tool calling generally, not an MCP-specific flaw.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
