Vulnerabilities in pkg:npm/pg
PACKAGECVE-2017-16082 is a CRITICAL (CVSS 9.8) remote code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Pg libraries in the npm ecosystem. The issue involves remote code execution in pg. Remediation is available by upgrading affected packages to version 4.5.7, 2.11.2, 3.6.4, 5.2.1, 6.0.5, 6.1.6, 6.2.5, 6.3.3, 6.4.2, 7.0.2, 7.1.2.
pkg:npm/pg
Vulnerability advisories affecting package pkg:npm/pg. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-wc9v-mj63-m9g5 | CVE-2017-16082 | CRITICAL | Remote Code Execution in pg |
CVE-2017-16082 at a Glance
Security Impact
CVSS: 9.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2017-16082
To remediate this vulnerability, upgrade all affected Pg dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install pg@4.5.7
npm install pg@2.11.2
npm install pg@3.6.4
npm install pg@5.2.1
npm install pg@6.0.5
npm install pg@6.1.6
npm install pg@6.2.5
npm install pg@6.3.3
npm install pg@6.4.2
npm install pg@7.0.2
npm install pg@7.1.2
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls pg
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2017-16082, inspect your project dependencies using npm:
npm ls pg
Analyze the terminal output to locate any version of Pg in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.5.7), your application is affected.
Note: The npm ls pg command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Pg, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2017-16082 Affected Pg Versions
11 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
pg
|
npm |
≥ 4.0.0
< 4.5.7
|
4.5.7
|
|
pg
|
npm |
< 2.11.2
|
2.11.2
|
|
pg
|
npm |
≥ 3.0.0
< 3.6.4
|
3.6.4
|
|
pg
|
npm |
≥ 5.0.0
< 5.2.1
|
5.2.1
|
|
pg
|
npm |
≥ 6.0.0
< 6.0.5
|
6.0.5
|
|
pg
|
npm |
≥ 6.1.0
< 6.1.6
|
6.1.6
|
|
pg
|
npm |
≥ 6.2.0
< 6.2.5
|
6.2.5
|
|
pg
|
npm |
≥ 6.3.0
< 6.3.3
|
6.3.3
|
|
pg
|
npm |
≥ 6.4.0
< 6.4.2
|
6.4.2
|
|
pg
|
npm |
≥ 7.0.0
< 7.0.2
|
7.0.2
|
|
pg
|
npm |
≥ 7.1.0
< 7.1.2
|
7.1.2
|
References
Frequently Asked Questions
What is CVE-2017-16082?
Which Pg versions are affected?
What version fixes CVE-2017-16082?
Is pg affected?
What is the CVSS score of CVE-2017-16082?
What CWE is associated with CVE-2017-16082?
How can I check npm dependencies for CVE-2017-16082?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-wc9v-mj63-m9g5",
"modified" : "2023-09-11T18:31:10Z",
"published" : "2018-07-24T19:44:42Z",
"aliases" : [ "CVE-2017-16082" ],
"summary" : "Remote Code Execution in pg",
"details" : "Affected versions of `pg` contain a remote code execution vulnerability that occurs when the remote database or query specifies a crafted column name. \n\nThere are two specific scenarios in which it is likely for an application to be vulnerable:\n1. The application executes unsafe, user-supplied sql which contains malicious column names.\n2. The application connects to an untrusted database and executes a query returning results which contain a malicious column name.\n\n## Proof of Concept\n```\nconst { Client } = require('pg')\nconst client = new Client()\nclient.connect()\n\nconst sql = `SELECT 1 AS \"\\\\'/*\", 2 AS \"\\\\'*/\\n + console.log(process.env)] = null;\\n//\"`\n\nclient.query(sql, (err, res) => {\n client.end()\n})\n```\n\n\n## Recommendation\n\n* Version 2.x.x: Update to version 2.11.2 or later.\n* Version 3.x.x: Update to version 3.6.4 or later.\n* Version 4.x.x: Update to version 4.5.7 or later.\n* Version 5.x.x: Update to version 5.2.1 or later.\n* 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. )\n* Version 7.x.x: Update to version 7.1.2 or later. ( Note that version 7.0.2 is also patched. )",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.11.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "3.0.0"
}, {
"fixed" : "3.6.4"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "4.0.0"
}, {
"fixed" : "4.5.7"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "5.0.0"
}, {
"fixed" : "5.2.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.0.0"
}, {
"fixed" : "6.0.5"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.1.0"
}, {
"fixed" : "6.1.6"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.2.0"
}, {
"fixed" : "6.2.5"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.3.0"
}, {
"fixed" : "6.3.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.4.0"
}, {
"fixed" : "6.4.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "7.0.0"
}, {
"fixed" : "7.0.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "pg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "7.1.0"
}, {
"fixed" : "7.1.2"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2017-16082"
}, {
"type" : "ADVISORY",
"url" : "https://github.com/advisories/GHSA-wc9v-mj63-m9g5"
}, {
"type" : "WEB",
"url" : "https://node-postgres.com/announcements#2017-08-12-code-execution-vulnerability"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/advisories/521"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-94" ],
"severity" : "CRITICAL",
"github_reviewed" : true,
"github_reviewed_at" : "2020-06-16T22:00:03Z",
"nvd_published_at" : null
}
}