CVE-2022-29256: Sharp Sharp Vulnerable To Command Injection Vulnerability

MODERATE
Advisory Identifier: GHSA-gp95-ppv5-3jc5
CVSS 6.5
CWE-78 CWE-77
Published
Advisory Summary

CVE-2022-29256 is a MODERATE (CVSS 6.5) sharp vulnerable to command injection vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Sharp libraries in the npm ecosystem. The issue involves sharp vulnerable to command injection in post-installation over build environment. Remediation is available by upgrading affected packages to version 0.30.5.

CVE-2022-29256 at a Glance

CVE Identifier CVE-2022-29256
GHSA Identifier GHSA-gp95-ppv5-3jc5
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product Sharp
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required High (PR:H)
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-2022-29256

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

sharp fixed: 0.30.5
npm install sharp@0.30.5
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 sharp

How to Check if You Are Affected

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

npm ls sharp

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

Note: The npm ls sharp 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-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. In Sharp, 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

There's a possible vulnerability in logic that is run only at `npm install` time when installing versions of `sharp` prior to the latest v0.30.5. This is not part of any runtime code, does not affect Windows users at all, and is unlikely to affect anyone that already cares about the security of their build environment. However, out of an abundance of caution, I've created this advisory. If an attacker has the ability to set the value of the `PKG_CONFIG_PATH` environment variable in a build environment then they might be able to use this to inject an arbitrary command at `npm install` time. I've used the Common Vulnerability Scoring System (CVSS) calculator to determine the maximum possible impact, which suggests a "medium" score of 5.9, but for most people the real impact will be dealing with the noise from automated security tooling that this advisory will bring. [`AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H/E:P/RL:O/RC:C/CR:X/IR:X/AR:X/MAV:X/MAC:X/MPR:X/MUI:R/MS:X/MC:X/MI:X/MA:X`](https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?vector=AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H/E:P/RL:O/RC:C/CR:X/IR:X/AR:X/MAV:X/MAC:X/MPR:X/MUI:R/MS:X/MC:X/MI:X/MA:X&version=3.1) This problem was fixed in commit a6aeef6 and published as part of `sharp` v0.30.5. Thank you very much to @dwisiswant0 for the responsible disclosure. Remember: if an attacker has control over environment variables in your build environment then you have a bigger problem to deal with than this issue.

CVE-2022-29256 Affected Sharp Versions

1 component(s)
Fixed Versions:
0.30.5
Product / Package Ecosystem Affected Versions Fixed Version
sharp
npm
< 0.30.5
0.30.5

References

Frequently Asked Questions

What is CVE-2022-29256?
CVE-2022-29256 is a security vulnerability in Sharp involving sharp vulnerable to Command Injection in post-installation over build environment under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which Sharp versions are affected?
Affected versions include releases prior to 0.30.5 across affected packages: sharp.
What version fixes CVE-2022-29256?
Upgrading to 0.30.5 (or the latest patched release for your respective branch) resolves the vulnerability.
Is sharp affected?
Yes, sharp is affected in releases prior to 0.30.5. Upgrade your dependency to 0.30.5 or later.
What is the CVSS score of CVE-2022-29256?
CVE-2022-29256 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-29256?
CVE-2022-29256 is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.).
How can I check npm dependencies for CVE-2022-29256?
Run the dependency tree command: 'npm ls sharp'. 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-gp95-ppv5-3jc5",
  "modified" : "2022-09-15T01:24:15Z",
  "published" : "2022-06-01T19:58:29Z",
  "aliases" : [ "CVE-2022-29256" ],
  "summary" : "sharp vulnerable to Command Injection in post-installation over build environment",
  "details" : "There's a possible vulnerability in logic that is run only at `npm install` time when installing versions of `sharp` prior to the latest v0.30.5.\n\nThis is not part of any runtime code, does not affect Windows users at all, and is unlikely to affect anyone that already cares about the security of their build environment. However, out of an abundance of caution, I've created this advisory.\n\nIf an attacker has the ability to set the value of the `PKG_CONFIG_PATH` environment variable in a build environment then they might be able to use this to inject an arbitrary command at `npm install` time.\n\nI've used the Common Vulnerability Scoring System (CVSS) calculator to determine the maximum possible impact, which suggests a \"medium\" score of 5.9, but for most people the real impact will be dealing with the noise from automated security tooling that this advisory will bring.\n\n[`AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H/E:P/RL:O/RC:C/CR:X/IR:X/AR:X/MAV:X/MAC:X/MPR:X/MUI:R/MS:X/MC:X/MI:X/MA:X`](https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator?vector=AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H/E:P/RL:O/RC:C/CR:X/IR:X/AR:X/MAV:X/MAC:X/MPR:X/MUI:R/MS:X/MC:X/MI:X/MA:X&version=3.1)\n\nThis problem was fixed in commit a6aeef6 and published as part of `sharp` v0.30.5.\n\nThank you very much to @dwisiswant0 for the responsible disclosure.\n\nRemember: if an attacker has control over environment variables in your build environment then you have a bigger problem to deal with than this issue.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "sharp"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.30.5"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/lovell/sharp/security/advisories/GHSA-gp95-ppv5-3jc5"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-29256"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/lovell/sharp/commit/a6aeef612be50f5868a77481848b1de674216f0c"
  }, {
    "type" : "WEB",
    "url" : "https://advisory.dw1.io/54"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/lovell/sharp"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77", "CWE-78" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-06-01T19:58:29Z",
    "nvd_published_at" : "2022-05-25T22:15:00Z"
  }
}