Join the Cyber Forum: Threat Intel on May 12, 2026 to learn how AI is reshaping threat defense.Join the Virtual Cyber Forum: Threat IntelRegister Now
Experiencing a Breach?Blog
Get StartedContact Us
SentinelOne
  • Platform
    Platform Overview
    • Singularity Platform
      Welcome to Integrated Enterprise Security
    • AI for Security
      Leading the Way in AI-Powered Security Solutions
    • Securing AI
      Accelerate AI Adoption with Secure AI Tools, Apps, and Agents.
    • How It Works
      The Singularity XDR Difference
    • Singularity Marketplace
      One-Click Integrations to Unlock the Power of XDR
    • Pricing & Packaging
      Comparisons and Guidance at a Glance
    Data & AI
    • Purple AI
      Accelerate SecOps with Generative AI
    • Singularity Hyperautomation
      Easily Automate Security Processes
    • AI-SIEM
      The AI SIEM for the Autonomous SOC
    • AI Data Pipelines
      Security Data Pipeline for AI SIEM and Data Optimization
    • Singularity Data Lake
      AI-Powered, Unified Data Lake
    • Singularity Data Lake for Log Analytics
      Seamlessly Ingest Data from On-Prem, Cloud or Hybrid Environments
    Endpoint Security
    • Singularity Endpoint
      Autonomous Prevention, Detection, and Response
    • Singularity XDR
      Native & Open Protection, Detection, and Response
    • Singularity RemoteOps Forensics
      Orchestrate Forensics at Scale
    • Singularity Threat Intelligence
      Comprehensive Adversary Intelligence
    • Singularity Vulnerability Management
      Application & OS Vulnerability Management
    • Singularity Identity
      Identity Threat Detection and Response
    Cloud Security
    • Singularity Cloud Security
      Block Attacks with an AI-Powered CNAPP
    • Singularity Cloud Native Security
      Secure Cloud and Development Resources
    • Singularity Cloud Workload Security
      Real-Time Cloud Workload Protection Platform
    • Singularity Cloud Data Security
      AI-Powered Threat Detection for Cloud Storage
    • Singularity Cloud Security Posture Management
      Detect and Remediate Cloud Misconfigurations
    Securing AI
    • Prompt Security
      Secure AI Tools Across Your Enterprise
  • Why SentinelOne?
    Why SentinelOne?
    • Why SentinelOne?
      Cybersecurity Built for What’s Next
    • Our Customers
      Trusted by the World’s Leading Enterprises
    • Industry Recognition
      Tested and Proven by the Experts
    • About Us
      The Industry Leader in Autonomous Cybersecurity
    Compare SentinelOne
    • Arctic Wolf
    • Broadcom
    • CrowdStrike
    • Cybereason
    • Microsoft
    • Palo Alto Networks
    • Sophos
    • Splunk
    • Trellix
    • Trend Micro
    • Wiz
    Verticals
    • Energy
    • Federal Government
    • Finance
    • Healthcare
    • Higher Education
    • K-12 Education
    • Manufacturing
    • Retail
    • State and Local Government
  • Services
    Managed Services
    • Managed Services Overview
      Wayfinder Threat Detection & Response
    • Threat Hunting
      World-Class Expertise and Threat Intelligence
    • Managed Detection & Response
      24/7/365 Expert MDR Across Your Entire Environment
    • Incident Readiness & Response
      DFIR, Breach Readiness, & Compromise Assessments
    Support, Deployment, & Health
    • Technical Account Management
      Customer Success with Personalized Service
    • SentinelOne GO
      Guided Onboarding & Deployment Advisory
    • SentinelOne University
      Live and On-Demand Training
    • Services Overview
      Comprehensive Solutions for Seamless Security Operations
    • SentinelOne Community
      Community Login
  • Partners
    Our Network
    • MSSP Partners
      Succeed Faster with SentinelOne
    • Singularity Marketplace
      Extend the Power of S1 Technology
    • Cyber Risk Partners
      Enlist Pro Response and Advisory Teams
    • Technology Alliances
      Integrated, Enterprise-Scale Solutions
    • SentinelOne for AWS
      Hosted in AWS Regions Around the World
    • Channel Partners
      Deliver the Right Solutions, Together
    • SentinelOne for Google Cloud
      Unified, Autonomous Security Giving Defenders the Advantage at Global Scale
    • Partner Locator
      Your Go-to Source for Our Top Partners in Your Region
    Partner Portal→
  • Resources
    Resource Center
    • Case Studies
    • Data Sheets
    • eBooks
    • Reports
    • Videos
    • Webinars
    • Whitepapers
    • Events
    View All Resources→
    Blog
    • Feature Spotlight
    • For CISO/CIO
    • From the Front Lines
    • Identity
    • Cloud
    • macOS
    • SentinelOne Blog
    Blog→
    Tech Resources
    • SentinelLABS
    • Ransomware Anthology
    • Cybersecurity 101
  • About
    About SentinelOne
    • About SentinelOne
      The Industry Leader in Cybersecurity
    • Investor Relations
      Financial Information & Events
    • SentinelLABS
      Threat Research for the Modern Threat Hunter
    • Careers
      The Latest Job Opportunities
    • Press & News
      Company Announcements
    • Cybersecurity Blog
      The Latest Cybersecurity Threats, News, & More
    • FAQ
      Get Answers to Our Most Frequently Asked Questions
    • DataSet
      The Live Data Platform
    • S Foundation
      Securing a Safer Future for All
    • S Ventures
      Investing in the Next Generation of Security, Data and AI
  • Pricing
Get StartedContact Us
CVE Vulnerability Database
Vulnerability Database/CVE-2021-23222

CVE-2021-23222: PostgreSQL Information Disclosure Flaw

CVE-2021-23222 is an information disclosure vulnerability in PostgreSQL that allows man-in-the-middle attackers to inject false responses despite SSL encryption. This article covers technical details, impact, and mitigation.

Published: February 25, 2026

CVE-2021-23222 Overview

CVE-2021-23222 is a man-in-the-middle vulnerability affecting PostgreSQL that allows attackers to inject false responses to the client's first few queries, despite the use of SSL certificate verification and encryption. This vulnerability exploits a timing window during the SSL/GSS encryption handshake process, where a network-positioned attacker can perform a buffer-stuffing attack to inject malicious data before the encrypted channel is fully established.

Critical Impact

Attackers positioned in a man-in-the-middle position can bypass SSL protections and inject unauthorized responses to PostgreSQL clients, potentially compromising data confidentiality even when encryption is enabled.

Affected Products

  • PostgreSQL versions prior to security patches
  • PostgreSQL 14.0
  • Multiple PostgreSQL version branches with libpq client library

Discovery Timeline

  • 2022-03-02 - CVE CVE-2021-23222 published to NVD
  • 2024-11-21 - Last updated in NVD database

Technical Details for CVE-2021-23222

Vulnerability Analysis

This vulnerability resides in the PostgreSQL client library (libpq) and involves improper handling of data received during the SSL/GSS encryption handshake initialization. The core issue stems from how the frontend handles the transition from unencrypted to encrypted communication.

When SSL encryption is initiated, the server sends a single S byte to indicate SSL readiness, then waits for the frontend to begin the SSL handshake. However, a man-in-the-middle attacker can exploit this transition window by injecting additional bytes into the connection before the SSL handshake completes. These injected bytes are then processed by the client as if they were legitimate server responses.

The vulnerability is classified under CWE-522 (Insufficiently Protected Credentials), as the attack allows credential-related data and query responses to be manipulated before encryption protections are fully in place.

Root Cause

The root cause of CVE-2021-23222 lies in the libpq client library's failure to validate that no extraneous data exists in the connection buffer after the SSL response byte is received but before the SSL handshake completes. The library would process data that arrived during this unencrypted window as if it were legitimate encrypted responses from the server.

The vulnerable code path did not check whether conn->inCursor != conn->inEnd after the SSL handshake completed, meaning any pre-buffered data from an attacker would be trusted and processed.

Attack Vector

This network-based attack requires the attacker to be positioned between the PostgreSQL client and server (man-in-the-middle position). The attack sequence involves:

  1. Intercepting the initial SSL negotiation between client and server
  2. Allowing the legitimate S byte response to pass through
  3. Injecting malicious payload data into the connection stream before SSL is fully established
  4. The client processes the injected data as legitimate server responses

The attack does not require authentication and does not require user interaction, though it does require the high complexity of achieving a man-in-the-middle position.

text
// Documentation patch showing the buffer-stuffing attack vector
     and proceed without requesting <acronym>SSL</acronym>.
    </para>
 
+   <para>
+    When <acronym>SSL</acronym> encryption can be performed, the server
+    is expected to send only the single <literal>S</literal> byte and then
+    wait for the frontend to initiate an <acronym>SSL</acronym> handshake.
+    If additional bytes are available to read at this point, it likely
+    means that a man-in-the-middle is attempting to perform a
+    buffer-stuffing attack
+    (<ulink url="https://www.postgresql.org/support/security/CVE-2021-23222/">CVE-2021-23222</ulink>).
+    Frontends should be coded either to read exactly one byte from the
+    socket before turning the socket over to their SSL library, or to
+    treat it as a protocol violation if they find they have read additional
+    bytes.
+   </para>
+
    <para>
     An initial SSLRequest can also be used in a connection that is being
     opened to send a CancelRequest message.

Source: GitHub PostgreSQL Commit

Detection Methods for CVE-2021-23222

Indicators of Compromise

  • Connection reset or error messages indicating "received unencrypted data after SSL response" in PostgreSQL client logs
  • Unexpected query responses or data returned from initial database queries
  • Network traffic analysis showing additional payload data between SSL negotiation byte and handshake packets
  • Anomalous connection behavior during SSL/TLS establishment with PostgreSQL servers

Detection Strategies

  • Deploy network intrusion detection systems (NIDS) to monitor for suspicious traffic patterns during PostgreSQL SSL handshakes
  • Implement SSL/TLS traffic inspection at network boundaries to detect injection attempts
  • Enable verbose client-side logging in libpq to capture connection establishment anomalies
  • Monitor for PostgreSQL client error messages related to SSL handshake failures or unexpected data

Monitoring Recommendations

  • Configure logging on database clients to capture SSL negotiation events and errors
  • Implement network traffic baselining for PostgreSQL connections to identify anomalous handshake patterns
  • Deploy endpoint detection to monitor PostgreSQL client processes for unexpected behavior
  • Review firewall and network device logs for potential man-in-the-middle positioning indicators

How to Mitigate CVE-2021-23222

Immediate Actions Required

  • Update PostgreSQL client libraries (libpq) to patched versions immediately
  • Audit all systems using PostgreSQL client connections for vulnerable library versions
  • Implement network segmentation to reduce man-in-the-middle attack surfaces
  • Consider using VPN or other encrypted tunnels for PostgreSQL connections until patching is complete

Patch Information

PostgreSQL has released security patches that address this vulnerability by adding validation logic to detect and reject extraneous data received after the SSL response. The fix adds a check in fe-connect.c to verify that no buffered data exists after the SSL handshake completes:

c
// Security fix validating no unencrypted data in buffer after SSL handshake
				pollres = pqsecure_open_client(conn);
				if (pollres == PGRES_POLLING_OK)
				{
+					/*
+					 * At this point we should have no data already buffered.
+					 * If we do, it was received before we performed the SSL
+					 * handshake, so it wasn't encrypted and indeed may have
+					 * been injected by a man-in-the-middle.
+					 */
+					if (conn->inCursor != conn->inEnd)
+					{
+						appendPQExpBufferStr(&conn->errorMessage,
+											 libpq_gettext("received unencrypted data after SSL response\n"));
+						goto error_return;
+					}
+
					/* SSL handshake done, ready to send startup packet */
					conn->status = CONNECTION_MADE;
					return PGRES_POLLING_WRITING;

Source: GitHub PostgreSQL Commit

For detailed patch information, refer to the PostgreSQL Security Advisory and Gentoo Security Advisory.

Workarounds

  • Implement strict network access controls to minimize man-in-the-middle attack opportunities
  • Use network isolation for PostgreSQL server connections where possible
  • Deploy network monitoring to detect potential MITM attack attempts
  • Consider client-side certificate mutual authentication as an additional security layer
bash
# Configuration example - Verify PostgreSQL client library version
psql --version
# Check for patched libpq version in system
ldd $(which psql) | grep libpq
# Update PostgreSQL client packages on Debian/Ubuntu
sudo apt-get update && sudo apt-get upgrade postgresql-client libpq5
# Update on RHEL/CentOS
sudo yum update postgresql postgresql-libs

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

  • Vulnerability Details
  • TypeInformation Disclosure

  • Vendor/TechPostgresql

  • SeverityMEDIUM

  • CVSS Score5.9

  • EPSS Probability0.28%

  • Known ExploitedNo
  • CVSS Vector
  • CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N
  • Impact Assessment
  • ConfidentialityHigh
  • IntegrityNone
  • AvailabilityNone
  • CWE References
  • CWE-522
  • Technical References
  • Red Hat Bug Report

  • PostgreSQL Commit Diff

  • Gentoo Security Advisory
  • Vendor Resources
  • GitHub PostgreSQL Commit

  • PostgreSQL CVE Analysis
  • Related CVEs
  • CVE-2026-2003: PostgreSQL Information Disclosure Flaw

  • CVE-2023-5868: PostgreSQL Information Disclosure Flaw

  • CVE-2024-10977: PostgreSQL Information Disclosure Flaw

  • CVE-2024-4317: PostgreSQL Information Disclosure Flaw
Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the World’s Most Advanced Cybersecurity Platform

See how our intelligent, autonomous cybersecurity platform can protect your organization now and into the future.

Try SentinelOne
  • Get Started
  • Get a Demo
  • Product Tour
  • Why SentinelOne
  • Pricing & Packaging
  • FAQ
  • Contact
  • Contact Us
  • Customer Support
  • SentinelOne Status
  • Language
  • Platform
  • Singularity Platform
  • Singularity Endpoint
  • Singularity Cloud
  • Singularity AI-SIEM
  • Singularity Identity
  • Singularity Marketplace
  • Purple AI
  • Services
  • Wayfinder TDR
  • SentinelOne GO
  • Technical Account Management
  • Support Services
  • Verticals
  • Energy
  • Federal Government
  • Finance
  • Healthcare
  • Higher Education
  • K-12 Education
  • Manufacturing
  • Retail
  • State and Local Government
  • Cybersecurity for SMB
  • Resources
  • Blog
  • Labs
  • Case Studies
  • Videos
  • Product Tours
  • Events
  • Cybersecurity 101
  • eBooks
  • Webinars
  • Whitepapers
  • Press
  • News
  • Ransomware Anthology
  • Company
  • About Us
  • Our Customers
  • Careers
  • Partners
  • Legal & Compliance
  • Security & Compliance
  • Investor Relations
  • S Foundation
  • S Ventures

©2026 SentinelOne, All Rights Reserved.

Privacy Notice Terms of Use

English