Vulnerabilities in pkg:npm/pg

PACKAGE
Advisory Identifier: GHSA-wc9v-mj63-m9g5
Advisory Summary

CVE-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.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/pg

1 Known Advisory Record(s)

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

CVE Identifier CVE-2017-16082
GHSA Identifier GHSA-wc9v-mj63-m9g5
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Pg
Package Ecosystem npm
Published Date
Last Updated

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).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (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.

pg fixed: 4.5.7
npm install pg@4.5.7
pg fixed: 2.11.2
npm install pg@2.11.2
pg fixed: 3.6.4
npm install pg@3.6.4
pg fixed: 5.2.1
npm install pg@5.2.1
pg fixed: 6.0.5
npm install pg@6.0.5
pg fixed: 6.1.6
npm install pg@6.1.6
pg fixed: 6.2.5
npm install pg@6.2.5
pg fixed: 6.3.3
npm install pg@6.3.3
pg fixed: 6.4.2
npm install pg@6.4.2
pg fixed: 7.0.2
npm install pg@7.0.2
pg fixed: 7.1.2
npm install pg@7.1.2
Verify Direct and Transitive Dependencies

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

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. )

CVE-2017-16082 Affected Pg Versions

11 component(s)
Fixed Versions:
4.5.72.11.23.6.45.2.16.0.56.1.66.2.56.3.36.4.27.0.27.1.2
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?
CVE-2017-16082 is a security vulnerability in Pg involving Remote Code Execution in pg under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Pg versions are affected?
Affected versions include releases prior to 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 across affected packages: pg.
What version fixes CVE-2017-16082?
Upgrading to 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 (or the latest patched release for your respective branch) resolves the vulnerability.
Is pg affected?
Yes, pg is affected in releases prior to 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. Upgrade your dependency to 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 or later.
What is the CVSS score of CVE-2017-16082?
CVE-2017-16082 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2017-16082?
CVE-2017-16082 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (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.).
How can I check npm dependencies for CVE-2017-16082?
Run the dependency tree command: 'npm ls pg'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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
  }
}