2017-08-12 - code execution vulnerability

Today @sehrope found and reported a code execution vulnerability in node-postgres. This affects all versions from [email protected] through [email protected].

I have published a fix on the tip of each major version branch of all affected versions as well as a fix on each minor version branch of [email protected] and [email protected]:


The following versions have been published to npm & contain a patch to fix the vulnerability:

[email protected]2.11.2
[email protected]3.6.4
[email protected]4.5.7
[email protected]5.2.1
[email protected]6.0.5
[email protected]6.1.6
[email protected]6.2.5
[email protected]6.3.3
[email protected]6.4.2
[email protected]7.0.2
[email protected]7.1.3


To demonstrate the issue & see if you are vunerable execute the following in node:

const { Client } = require('pg')
const client = new Client()

const sql = `SELECT 1 AS "\\'/*", 2 AS "\\'*/\n + console.log(process.env)] = null;\n//"`

client.query(sql, (err, res) => {

You will see your environment variables printed to your console. An attacker can use this exploit to execute any arbitrary node code within your process.


This vulnerability likely does not impact you if you are connecting to a database you control and not executing user-supplied sql. Still, you should absolutely upgrade to the most recent patch version as soon as possible to be safe.

Two attack vectors we quickly thought of:

  • 1 - executing unsafe, user-supplied sql which contains a malicious column name like the one above.
  • 2 - connecting to an untrusted database and executing a query which returns results where any of the column names are malicious.


I have created an issue you can use to discuss the vulnerability with me or ask questions, and I have reported this issue on twitter and directly to Heroku and nodesecurity.io.

I take security very seriously. If you or your company benefit from node-postgres please sponsor my work: this type of issue is one of the many things I am responsible for, and I want to be able to continue to tirelessly provide a world-class PostgreSQL experience in node for years to come.


  1. How I found a persistent XSS affecting thousands of career sites
  2. [ANNOUNCE] Git v2.14.1, v2.13.5, and others
  3. EdOverflow - Bug Bounty FAQ
  4. David Vieira-Kurz a.k.a. @secalert on security
  5. EdOverflow/bugbounty-cheatsheet: A list of interesting payloads, tips and tricks for bug bounty hunters.

原文链接: node-postgres.com