CriticalGHSA-wc9v-mj63-m9g5CVE-2017-16082

Remote Code Execution in pg

Published 24 Jul 2018 · Updated 8 Nov 2023

Affected packages

pgnpm
Affected
<2.11.2
Fixed in
2.11.2
Update to the fixed version for your release line, for example:npm install pg@2.11.2
pgnpm
Affected
>=3.0.0 <3.6.4
Fixed in
3.6.4
Update to the fixed version for your release line, for example:npm install pg@3.6.4
pgnpm
Affected
>=4.0.0 <4.5.7
Fixed in
4.5.7
Update to the fixed version for your release line, for example:npm install pg@4.5.7
pgnpm
Affected
>=5.0.0 <5.2.1
Fixed in
5.2.1
Update to the fixed version for your release line, for example:npm install pg@5.2.1
pgnpm
Affected
>=6.0.0 <6.0.5
Fixed in
6.0.5
Update to the fixed version for your release line, for example:npm install pg@6.0.5
pgnpm
Affected
>=6.1.0 <6.1.6
Fixed in
6.1.6
Update to the fixed version for your release line, for example:npm install pg@6.1.6
pgnpm
Affected
>=6.2.0 <6.2.5
Fixed in
6.2.5
Update to the fixed version for your release line, for example:npm install pg@6.2.5
pgnpm
Affected
>=6.3.0 <6.3.3
Fixed in
6.3.3
Update to the fixed version for your release line, for example:npm install pg@6.3.3
pgnpm
Affected
>=6.4.0 <6.4.2
Fixed in
6.4.2
Update to the fixed version for your release line, for example:npm install pg@6.4.2
pgnpm
Affected
>=7.0.0 <7.0.2
Fixed in
7.0.2
Update to the fixed version for your release line, for example:npm install pg@7.0.2
pgnpm
Affected
>=7.1.0 <7.1.2
Fixed in
7.1.2
Update to the fixed version for your release line, for example:npm install pg@7.1.2

Details

Affected versions of pg contain a remote code execution vulnerability that occurs when the remote database or query specifies a crafted column name.

There are two specific scenarios in which it is likely for an application to be vulnerable: 1. The application executes unsafe, user-supplied sql which contains malicious column names. 2. The application connects to an untrusted database and executes a query returning results which contain a malicious column name.

Proof of Concept

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

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

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

Recommendation

  • Version 2.x.x: Update to version 2.11.2 or later.
  • Version 3.x.x: Update to version 3.6.4 or later.
  • Version 4.x.x: Update to version 4.5.7 or later.
  • Version 5.x.x: Update to version 5.2.1 or later.
  • Version 6.x.x: Update to version 6.4.2 or later. ( Note that versions 6.1.6, 6.2.5, and 6.3.3 are also patched. )
  • Version 7.x.x: Update to version 7.1.2 or later. ( Note that version 7.0.2 is also patched. )

Is GHSA-wc9v-mj63-m9g5 in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected pg, and gives you the command that fixes it.

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.