CVE-2020-4038: Graphql playground html Cross-Site Scripting Vulnerability

HIGH
Advisory Identifier: GHSA-4852-vrh7-28rf
CVSS 7.4
CWE-79
Published
Advisory Summary

CVE-2020-4038 is a HIGH (CVSS 7.4) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Graphql playground html libraries in the npm ecosystem. The issue involves reflected xss in graphql playground. Remediation is available by upgrading affected packages to version 1.6.22.

CVE-2020-4038 at a Glance

CVE Identifier CVE-2020-4038
GHSA Identifier GHSA-4852-vrh7-28rf
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Graphql playground html
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.4

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

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2020-4038

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

graphql-playground-html fixed: 1.6.22
npm install graphql-playground-html@1.6.22
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 graphql-playground-html

How to Check if You Are Affected

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

npm ls graphql-playground-html

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

Note: The npm ls graphql-playground-html 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-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Graphql playground html, 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

### Impact **directly impacted:** - `graphql-playground-html@<1.6.22` - all unsanitized user input for `renderPlaygroundPage()` **all of our consuming packages** of `graphql-playground-html` are impacted: - `graphql-playground-middleware-express@<1.7.16` - unsanitized user input to `expressPlayground()` - `graphql-playground-middleware-koa@<1.6.15` - unsanitized user input to `koaPlayground()` - `graphql-playground-middleware-lambda@<1.7.17` - unsanitized user input to `lambdaPlayground()` - `graphql-playground-middleware-hapi@<1.6.13` - unsanitized user input to `hapiPlayground()` as well as ***any other packages*** that use these methods with unsanitized user input. **not impacted:** - `graphql-playground-electron` - uses `renderPlaygroundPage()` statically for a webpack build for electron bundle, no dynamic user input - `graphql-playground-react` - usage of the component directly in a react application does not expose reflected XSS vulnerabilities. only the demo in `public/` contains the vulnerability, because it uses an old version of the html pacakge. ### Patches upgrading to the above mentioned versions will solve the issue. If you're using `graphql-playground-html` directly, then: ``` yarn add graphql-playground-html@^1.6.22 ``` or ``` npm install --save graphql-playground-html@^1.6.22 ``` Then, similar steps need to be taken for each middleware: - [Upgrade Express Middleware](https://www.npmjs.com/package/graphql-playground-middleware-express#security-upgrade-steps) - [Upgrade Koa Middleware](https://www.npmjs.com/package/graphql-playground-middleware-koa#security-upgrade-steps) - [Upgrade Lambda Middleware](https://www.npmjs.com/package/graphql-playground-middleware-lambda#security-upgrade-steps) - [Upgrade Hapi Middleware](https://www.npmjs.com/package/graphql-playground-middleware-hapi#security-upgrade-steps) ### Workarounds Ensure you properly sanitize *all* user input for options you use for whatever function to initialize GraphQLPlayground: for example, with `graphql-playground-html` and express: ```js const { sanitizeUrl } = require('@braintree/sanitize-url'); const qs = require('querystringify'); const { renderPlaygroundPage } = require('graphql-playground-html'); module.exports = (req, res, next) => { const { endpoint } = qs.parse(req.url) res.html(renderPlaygroundPage({endpoint: sanitizeUrl(endpoint) })).status(200) next() } ``` or, with `graphql-playground-express`: ```js const { expressPlayground } = require('graphql-playground-middleware-express'); const { sanitizeUrl } = require('@braintree/sanitize-url'); const qs = require('querystringify'); const { renderPlaygroundPage } = require('graphql-playground-html'); module.exports = (req, res, next) => { const { endpoint } = qs.parse(req.url) res.html(expressPlayground({endpoint: sanitizeUrl(endpoint) })).status(200) next() } ``` ### References - [OWASP: How to Test for CSS Reflection Attacks](https://github.com/OWASP/wstg/blob/master/document/4-Web_Application_Security_Testing/07-Input_Validation_Testing/01-Testing_for_Reflected_Cross_Site_Scripting.md) - [Original Report from Cure53](https://user-images.githubusercontent.com/1368727/84191028-dfb7b980-aa65-11ea-8e18-4b8706f538e2.jpg) (jpg) ### Credits Masato Kinugawa of Cure53 ### For more information If you have any questions or comments about this advisory: * Open an issue in [graphql-playground](https://github.com/prisma-labs/graphql-playground/issues/new/choose) * Email us at [rikki.schulte@gmail.com](mailto:rikki.schulte@gmail.com)

CVE-2020-4038 Affected Graphql playground html Versions

1 component(s)
Fixed Versions:
1.6.22
Product / Package Ecosystem Affected Versions Fixed Version
graphql-playground-html
npm
< 1.6.22
1.6.22

References

Frequently Asked Questions

What is CVE-2020-4038?
CVE-2020-4038 is a security vulnerability in Graphql playground html involving Reflected XSS in GraphQL Playground under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Graphql playground html versions are affected?
Affected versions include releases prior to 1.6.22 across affected packages: graphql-playground-html.
What version fixes CVE-2020-4038?
Upgrading to 1.6.22 (or the latest patched release for your respective branch) resolves the vulnerability.
Is graphql-playground-html affected?
Yes, graphql-playground-html is affected in releases prior to 1.6.22. Upgrade your dependency to 1.6.22 or later.
What is the CVSS score of CVE-2020-4038?
CVE-2020-4038 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N.
What CWE is associated with CVE-2020-4038?
CVE-2020-4038 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2020-4038?
Run the dependency tree command: 'npm ls graphql-playground-html'. 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-4852-vrh7-28rf",
  "modified" : "2021-11-04T17:11:46Z",
  "published" : "2020-06-09T00:24:57Z",
  "aliases" : [ "CVE-2020-4038" ],
  "summary" : "Reflected XSS in GraphQL Playground",
  "details" : "### Impact\n\n**directly impacted:**\n\n- `graphql-playground-html@<1.6.22` - all unsanitized user input for `renderPlaygroundPage()`\n\n**all of our consuming packages** of `graphql-playground-html` are impacted:\n\n- `graphql-playground-middleware-express@<1.7.16` - unsanitized user input to `expressPlayground()`\n- `graphql-playground-middleware-koa@<1.6.15` - unsanitized user input to `koaPlayground()`\n- `graphql-playground-middleware-lambda@<1.7.17` - unsanitized user input to `lambdaPlayground()`\n- `graphql-playground-middleware-hapi@<1.6.13` - unsanitized user input to `hapiPlayground()`\n\nas well as ***any other packages*** that use these methods with unsanitized user input.\n\n**not impacted:**\n\n- `graphql-playground-electron` - uses `renderPlaygroundPage()` statically for a webpack build for electron bundle, no dynamic user input\n- `graphql-playground-react` - usage of the component directly in a react application does not expose reflected XSS vulnerabilities. only the demo in `public/` contains the vulnerability, because it uses an old version of the html pacakge.\n\n### Patches\n\nupgrading to the above mentioned versions will solve the issue.\n\nIf you're using `graphql-playground-html` directly, then:\n\n```\nyarn add graphql-playground-html@^1.6.22\n```\n\nor\n\n```\nnpm install --save graphql-playground-html@^1.6.22\n```\n\nThen, similar steps need to be taken for each middleware:\n\n- [Upgrade Express Middleware](https://www.npmjs.com/package/graphql-playground-middleware-express#security-upgrade-steps)\n- [Upgrade Koa Middleware](https://www.npmjs.com/package/graphql-playground-middleware-koa#security-upgrade-steps)\n- [Upgrade Lambda Middleware](https://www.npmjs.com/package/graphql-playground-middleware-lambda#security-upgrade-steps)\n- [Upgrade Hapi Middleware](https://www.npmjs.com/package/graphql-playground-middleware-hapi#security-upgrade-steps)\n\n### Workarounds\n\nEnsure you properly sanitize *all* user input for options you use for whatever function to initialize GraphQLPlayground:\n\nfor example, with `graphql-playground-html` and express:\n\n```js\nconst { sanitizeUrl } = require('@braintree/sanitize-url');\n\nconst qs = require('querystringify');\n\nconst { renderPlaygroundPage } = require('graphql-playground-html');\n\nmodule.exports = (req, res, next) => {\n\tconst { endpoint } = qs.parse(req.url)\n\tres.html(renderPlaygroundPage({endpoint: sanitizeUrl(endpoint) })).status(200)\n\tnext()\n}\n```\n\nor, with `graphql-playground-express`:\n\n```js\nconst { expressPlayground } = require('graphql-playground-middleware-express');\nconst { sanitizeUrl } = require('@braintree/sanitize-url');\n\nconst qs = require('querystringify');\n\nconst { renderPlaygroundPage } = require('graphql-playground-html');\n\nmodule.exports = (req, res, next) => {\n\tconst { endpoint } = qs.parse(req.url)\n\tres.html(expressPlayground({endpoint: sanitizeUrl(endpoint) })).status(200)\n\tnext()\n}\n```\n\n### References\n\n- [OWASP: How to Test for CSS Reflection Attacks](https://github.com/OWASP/wstg/blob/master/document/4-Web_Application_Security_Testing/07-Input_Validation_Testing/01-Testing_for_Reflected_Cross_Site_Scripting.md)\n- [Original Report from Cure53](https://user-images.githubusercontent.com/1368727/84191028-dfb7b980-aa65-11ea-8e18-4b8706f538e2.jpg) (jpg)\n\n\n### Credits\n\nMasato Kinugawa of Cure53\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [graphql-playground](https://github.com/prisma-labs/graphql-playground/issues/new/choose)\n* Email us at [rikki.schulte@gmail.com](mailto:rikki.schulte@gmail.com)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "graphql-playground-html"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.6.22"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/graphql/graphql-playground/security/advisories/GHSA-4852-vrh7-28rf"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/prisma-labs/graphql-playground/security/advisories/GHSA-4852-vrh7-28rf"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2020-4038"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/prisma-labs/graphql-playground/commit/bf1883db538c97b076801a60677733816cb3cfb7"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/prisma-labs/graphql-playground#security-details"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-06-08T20:27:53Z",
    "nvd_published_at" : null
  }
}