CVE-2018-5158: Pdfjs dist Malicious PDF Can Inject JavaScript Vulnerability

HIGH
Advisory Identifier: GHSA-7jg2-jgv3-fmr4
CVSS 8.8
CWE-94
Published
Advisory Summary

CVE-2018-5158 is a HIGH (CVSS 8.8) malicious pdf can inject javascript vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Pdfjs dist libraries in the npm ecosystem. The issue involves malicious pdf can inject javascript into pdf viewer. Remediation is available by upgrading affected packages to version 2.0.550, 1.10.100.

CVE-2018-5158 at a Glance

CVE Identifier CVE-2018-5158
GHSA Identifier GHSA-7jg2-jgv3-fmr4
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Pdfjs dist
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.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:R/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 Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2018-5158

To remediate this vulnerability, upgrade all affected Pdfjs dist dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

pdfjs-dist fixed: 2.0.550
npm install pdfjs-dist@2.0.550
pdfjs-dist fixed: 1.10.100
npm install pdfjs-dist@1.10.100
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 pdfjs-dist

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2018-5158, inspect your project dependencies using npm:

npm ls pdfjs-dist

Analyze the terminal output to locate any version of Pdfjs dist in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.550), your application is affected.

Note: The npm ls pdfjs-dist 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 Pdfjs dist, 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

The PDF viewer does not sufficiently sanitize PostScript calculator functions, allowing malicious JavaScript to be injected through a crafted PDF file. This JavaScript can then be run with the permissions of the PDF viewer by its worker. This vulnerability affects Firefox ESR < 52.8, Firefox < 60 and PDF.js < 2.0.550.

CVE-2018-5158 Affected Pdfjs dist Versions

2 component(s)
Fixed Versions:
2.0.5501.10.100
Product / Package Ecosystem Affected Versions Fixed Version
pdfjs-dist
npm
≥ 2.0.0
< 2.0.550
2.0.550
pdfjs-dist
npm
< 1.10.100
1.10.100

References

Frequently Asked Questions

What is CVE-2018-5158?
CVE-2018-5158 is a security vulnerability in Pdfjs dist involving Malicious PDF can inject JavaScript into PDF Viewer under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Pdfjs dist versions are affected?
Affected versions include releases prior to 2.0.550, 1.10.100 across affected packages: pdfjs-dist.
What version fixes CVE-2018-5158?
Upgrading to 2.0.550, 1.10.100 (or the latest patched release for your respective branch) resolves the vulnerability.
Is pdfjs-dist affected?
Yes, pdfjs-dist is affected in releases prior to 2.0.550, 1.10.100. Upgrade your dependency to 2.0.550, 1.10.100 or later.
What is the CVSS score of CVE-2018-5158?
CVE-2018-5158 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2018-5158?
CVE-2018-5158 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-2018-5158?
Run the dependency tree command: 'npm ls pdfjs-dist'. 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-7jg2-jgv3-fmr4",
  "modified" : "2024-05-28T20:43:53Z",
  "published" : "2022-05-14T01:22:02Z",
  "aliases" : [ "CVE-2018-5158" ],
  "summary" : "Malicious PDF can inject JavaScript into PDF Viewer",
  "details" : "The PDF viewer does not sufficiently sanitize PostScript calculator functions, allowing malicious JavaScript to be injected through a crafted PDF file. This JavaScript can then be run with the permissions of the PDF viewer by its worker. This vulnerability affects Firefox ESR < 52.8, Firefox < 60 and PDF.js < 2.0.550.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "pdfjs-dist"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.0.550"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "pdfjs-dist"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.10.100"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2018-5158"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mozilla/pdf.js/pull/9659"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mozilla/pdf.js/commit/2dc4af525d1612c98afcd1e6bee57d4788f78f97"
  }, {
    "type" : "WEB",
    "url" : "https://access.redhat.com/errata/RHSA-2018:1414"
  }, {
    "type" : "WEB",
    "url" : "https://access.redhat.com/errata/RHSA-2018:1415"
  }, {
    "type" : "WEB",
    "url" : "https://bugzilla.mozilla.org/show_bug.cgi?id=1452075"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mozilla/pdf.js"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2018/05/msg00007.html"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/201810-01"
  }, {
    "type" : "WEB",
    "url" : "https://usn.ubuntu.com/3645-1"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2018/dsa-4199"
  }, {
    "type" : "WEB",
    "url" : "https://www.mozilla.org/security/advisories/mfsa2018-11"
  }, {
    "type" : "WEB",
    "url" : "https://www.mozilla.org/security/advisories/mfsa2018-12"
  }, {
    "type" : "WEB",
    "url" : "http://www.securityfocus.com/bid/104136"
  }, {
    "type" : "WEB",
    "url" : "http://www.securitytracker.com/id/1040896"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-05-28T20:43:53Z",
    "nvd_published_at" : "2018-06-11T21:29:00Z"
  }
}