CVE-2021-41249 (published 2021-11-04T20:15Z)

GraphQL Playground is a GraphQL IDE for development of graphQL focused applications. All versions of graphql-playground-react older than graphql-playground-react@1.7.28 are vulnerable to compromised HTTP schema introspection responses or schema prop values with malicious GraphQL type names, exposing a dynamic XSS attack surface that can allow code injection on operation autocomplete. In order for the attack to take place, the user must load a malicious schema in graphql-playground. There are several ways this can occur, including by specifying the URL to a malicious schema in the endpoint query parameter. If a user clicks on a link to a GraphQL Playground installation that specifies a malicious server, arbitrary JavaScript can run in the user's browser, which can be used to exfiltrate user credentials or other harmful goals. If you are using graphql-playground-react directly in your client app, upgrade to version 1.7.28 or later.

Severity: LOW
CVSS v2 base score: 2.6 (AV:N/AC:H/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 4.7, MEDIUM (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: 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.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/graphql/graphql-playground
commit_details: repo_url: https://github.com/graphql/graphql-playground
author: Rikki Schulte
author_date: 2021-11-04 18:55:09+01:00
msg: Merge pull request from GHSA-59r9-6jp6-jcm7

This change fixes an XSS vulnerability that has been present since the first
commit of GraphQL Playground when used with an untrusted GraphQL server. It applies three
strategies to fix via defense-in-depth: HTML escaping a string in a context
that uses innerHTML; validating incoming schemas with graphql-js validateSchema;
and using a single up-to-date Markdown library.

See docs/security/2021-introspection-schema-xss.md for more details.
repository: repo_url: https://github.com/graphql/graphql-playground
repo_name: graphql/graphql-playground
description: 🎮  GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
repo_language: TypeScript
owner: graphql
file_changes: filename: SECURITY.md
change_type: ModificationType.MODIFY
diff: @@ -1,138 +1,4 @@
 # Known Vulnerabilities
 
-## XSS Reflection Vulnerability
-
-the origin of the vulnerability is in `renderPlaygroundPage`, found in `graphql-playground-html`
-
-### Impact
-
-When using
-
-- `renderPlaygroundPage()`,
-- `koaPlayground()`
-- `expressPlayground()`
-- `koaPlayground()`
-- `lambdaPlayground()`
-- any downstream dependent packages that use these functions
-
-without sanitization of user input, your application is vulnerable to an XSS Reflecton Attack. This is a serious vulnerability that could allow for exfiltration of data or user credentials, or to disrupt systems.
-
-We've provided ['an example of the xss using the express middleware]('https://github.com/prisma-labs/graphql-playground/tree/main/packages/graphql-playground-middleware-express/examples/xss-attack')
-
-### Impacted Packages
-
-**All versions of these packages are impacted until those specified below**, which are now safe for user defined input:
-
-- `graphql-playground-html`: **☔ safe** @ `1.6.22`
-- `graphql-playground-express` **☔ safe** @ `1.7.16`
-- `graphql-playground-koa` **☔ safe** @ `1.6.15`
-- `graphql-playground-hapi` **☔ safe** @ `1.6.13`
-- `graphql-playground-lambda` **☔ safe** @ `1.7.17`
-
-### Static input was always safe
-
-These examples are safe for _all versions_ **because input is static**
-
-with `express` and `renderPlaygroundPage`:
-
-```js
-app.get('/playground', (req) => {
-  res.html(
-    renderPlaygroundPage({
-      endpoint: `/our/graphql`,
-    }),
-  )
-  next()
-})
-```
-
-with `expressPlayground`:
-
-```js
-// params
-app.get('/playground', (req) =>
-  expressPlayground({
-    endpoint: `/our/graphql`,
-    settings: { 'editor.theme': req.query.darkMode ? 'dark' : 'light' },
-  }),
-)
-```
-
-with `koaPlayground`:
-
-```js
-const koa = require('koa')
-const koaRouter = require('koa-router')
-const koaPlayground = require('graphql-playground-middleware-koa')
-
-const app = new koa()
-const router = new koaRouter()
-
-router.all('/playground', koaPlayground({ endpoint: '/graphql' }))
-```
-
-### Vulnerable Examples
-
-Here are some examples where the vulnerability would be present before the patch, because of unfiltered user input
-
-```js
-const express = require('express')
-const expressPlayground = require('graphql-playground-middleware-express')
-  .default
-
-const app = express()
-
-app.use(express.json())
-
-// params
-app.get('/playground/:id', (req) =>
-  expressPlayground({
-    endpoint: `/our/graphql/${req.params.id}`,
-  }),
-)
-
-// params
-app.get('/playground', (req) =>
-  expressPlayground({
-    endpoint: `/our/graphql`,
-    // any settings that are unsanitized user input, not just `endpoint`
-    settings: { 'editor.fontFamily': req.query.font },
-  }),
-)
-```
-
-[See a proof of concept](packages/graphql-playground-html/examples/xss-attack) to understand the vulnerability better
-
-### Workaround
-
-To fix this issue without the update, you can sanitize however you want.
-
-We suggest using [`xss`](https://www.npmjs.com/package/xss) (what we use for our own fix)
-
-For example, with `graphql-playground-middleware-express`:
-
-```js
-const express = require('express')
-const { filterXSS } = require('xss')
-const expressPlayground = require('graphql-playground-middleware-express')
-  .default
-
-
-const app = express()
-
-const filter = (val) => filterXSS(val, {
-  whitelist: [],
-  stripIgnoreTag: true,
-  stripIgnoreTagBody: ['script']
-})
-
-// simple example
-app.get('/playground/:id', (req) =>
-  expressPlayground({ endpoint: `/graphql/${filter(req.params.id)}` })
-
-// advanced params
-app.get('/playground', (req) =>
-  expressPlayground(JSON.parse(filter(JSON.stringify(req.query))))
-```
-
-[See a proof of concept workaround](packages/graphql-playground-html/examples/xss-attack), example #3
+- [2021: Introspection Schema Phishing Attack XSS Vulnerability](docs/security/2021-schema-xss-phishing-attack.md)
+- [2020: XSS Reflection Vulnerability](docs/security/2020-xss-template-injection.md)

programming_language: Markdown
filename: 2020-xss-template-injection.md
change_type: ModificationType.ADD
diff: @@ -0,0 +1,136 @@
+## XSS Reflection Vulnerability
+
+the origin of the vulnerability is in `renderPlaygroundPage`, found in `graphql-playground-html`
+
+### Impact
+
+When using
+
+- `renderPlaygroundPage()`,
+- `koaPlayground()`
+- `expressPlayground()`
+- `koaPlayground()`
+- `lambdaPlayground()`
+- any downstream dependent packages that use these functions
+
+without sanitization of user input, your application is vulnerable to an XSS Reflection Attack. This is a serious vulnerability that could allow for exfiltration of data or user credentials, or to disrupt systems.
+
+We've provided ['an example of the xss using the express middleware]('https://github.com/prisma-labs/graphql-playground/tree/main/packages/graphql-playground-middleware-express/examples/xss-attack')
+
+### Impacted Packages
+
+**All versions of these packages are impacted until those specified below**, which are now safe for user defined input:
+
+- `graphql-playground-html`: **☔ safe** @ `1.6.22`
+- `graphql-playground-express` **☔ safe** @ `1.7.16`
+- `graphql-playground-koa` **☔ safe** @ `1.6.15`
+- `graphql-playground-hapi` **☔ safe** @ `1.6.13`
+- `graphql-playground-lambda` **☔ safe** @ `1.7.17`
+
+### Static input was always safe
+
+These examples are safe for _all versions_ **because input is static**
+
+with `express` and `renderPlaygroundPage`:
+
+```js
+app.get('/playground', (req) => {
+  res.html(
+    renderPlaygroundPage({
+      endpoint: `/our/graphql`,
+    }),
+  )
+  next()
+})
+```
+
+with `expressPlayground`:
+
+```js
+// params
+app.get('/playground', (req) =>
+  expressPlayground({
+    endpoint: `/our/graphql`,
+    settings: { 'editor.theme': req.query.darkMode ? 'dark' : 'light' },
+  }),
+)
+```
+
+with `koaPlayground`:
+
+```js
+const koa = require('koa')
+const koaRouter = require('koa-router')
+const koaPlayground = require('graphql-playground-middleware-koa')
+
+const app = new koa()
+const router = new koaRouter()
+
+router.all('/playground', koaPlayground({ endpoint: '/graphql' }))
+```
+
+### Vulnerable Examples
+
+Here are some examples where the vulnerability would be present before the patch, because of unfiltered user input
+
+```js
+const express = require('express')
+const expressPlayground = require('graphql-playground-middleware-express')
+  .default
+
+const app = express()
+
+app.use(express.json())
+
+// params
+app.get('/playground/:id', (req) =>
+  expressPlayground({
+    endpoint: `/our/graphql/${req.params.id}`,
+  }),
+)
+
+// params
+app.get('/playground', (req) =>
+  expressPlayground({
+    endpoint: `/our/graphql`,
+    // any settings that are unsanitized user input, not just `endpoint`
+    settings: { 'editor.fontFamily': req.query.font },
+  }),
+)
+```
+
+[See a proof of concept](packages/graphql-playground-html/examples/xss-attack) to understand the vulnerability better
+
+### Workaround
+
+To fix this issue without the update, you can sanitize however you want.
+
+We suggest using [`xss`](https://www.npmjs.com/package/xss) (what we use for our own fix)
+
+For example, with `graphql-playground-middleware-express`:
+
+```js
+const express = require('express')
+const { filterXSS } = require('xss')
+const expressPlayground = require('graphql-playground-middleware-express')
+  .default
+
+
+const app = express()
+
+const filter = (val) => filterXSS(val, {
+  whitelist: [],
+  stripIgnoreTag: true,
+  stripIgnoreTagBody: ['script']
+})
+
+// simple example
+app.get('/playground/:id', (req) =>
+  expressPlayground({ endpoint: `/graphql/${filter(req.params.id)}` })
+
+// advanced params
+app.get('/playground', (req) =>
+  expressPlayground(JSON.parse(filter(JSON.stringify(req.query))))
+```
+
+[See a proof of concept workaround](packages/graphql-playground-html/examples/xss-attack), example #3

programming_language: Markdown
filename: 2021-schema-xss-phishing-attack.md
change_type: ModificationType.ADD
diff: @@ -0,0 +1,74 @@
+## GraphQL Playground introspection schema template injection attack: Advisory Statement
+
+This is a security advisory for an XSS vulnerability in `graphql-playground`.
+
+A similar vulnerability affects `graphiql`, the package from which `graphql-playground` was forked. There is a corresponding `graphiql` [advisory](https://github.com/graphql/graphiql/security/advisories/GHSA-x4r7-m2q9-69c8).
+
+- [1. Impact](#1-impact)
+- [2. Scope](#2-scope)
+- [3. Patches](#3-patches)
+- [4. Reproducing the exploit](#4-reproducing-the-exploit)
+- [5. Credit](#5-credit)
+- [6. For more information](#6-for-more-information)
+
+### 1. Impact
+
+All versions of `graphql-playground-react` older than `graphql-playground-react@1.7.28` are vulnerable to compromised HTTP schema introspection responses or `schema` prop values with malicious GraphQL type names, exposing a dynamic XSS attack surface that can allow code injection on operation autocomplete.
+
+In order for the attack to take place, the user must load a malicious schema in `graphql-playground`. There are several ways this can occur, including by specifying the URL to a malicious schema in the `endpoint` query parameter. If a user clicks on a link to a GraphQL Playground installation that specifies a malicious server, arbitrary JavaScript can run in the user's browser, which can be used to exfiltrate user credentials or other harmful goals.
+
+### 2. Scope
+
+This advisory describes the impact on the `graphql-playground-react` package. The vulnerability also affects `graphiql`, the package from which `graphql-playground` was forked, with a less severe impact; see the [`graphiql` advisory](https://github.com/graphql/graphiql/security/advisories/GHSA-x4r7-m2q9-69c8) for details. It affects all versions of `graphql-playground-react` older than `v1.7.28`.
+
+This vulnerability was introduced with the first public release of `graphql-playground`, so it impacts both the original legacy `graphql-playground` and the contemporary `graphql-playground-react` npm package. It is most easily exploited on `graphql-playground-react@1.7.0` and newer, as that release added functionality which made it possible to override the endpoint URL via query parameter even if it is explicitly specified in the code.
+
+`graphql-playground-react` is commonly loaded via the `graphql-playground-html` package or a middleware package that wraps it (`graphql-playground-express`, `graphql-playground-middleware-koa`, `graphql-playground-middleware-hapi`, or `graphql-playground-middleware-lambda`). By default, these packages render an HTML page which loads the *latest* version of `graphql-playground-react` through a CDN. If you are using one of these packages to install GraphQL Playground on your domain *and you do not explicitly pass the `version` option to `renderPlaygroundPage` or the middleware function*, then you do not need to take any action to resolve this vulnerability, as the latest version of the React app will automatically be loaded.
+
+`graphql-playground-react` is also commonly loaded via HTML served by Apollo Server. Apollo Server always pins a specific version of `graphql-playground-react`, so if you are using Apollo Server you do need to take action to resolve this vulnerability. See the [Apollo Server advisory](https://github.com/apollographql/apollo-server/security/advisories/GHSA-qm7x-rc44-rrqw) for details.
+
+
+### 3. Patches
+
+`graphql-playground-react@1.7.28` addresses this issue via defense in depth:
+
+- **HTML-escaping text** that should be treated as text rather than HTML. In most of the app, this happens automatically because React escapes all interpolated text by default. However, one vulnerable component uses the unsafe `innerHTML` API and interpolated type names directly into HTML. We now properly escape that type name, which fixes the known vulnerability.
+
+- **Validates the schema** upon receiving the introspection response or schema changes. Schemas with names that violate the GraphQL spec will no longer be loaded. (This includes preventing the Doc Explorer from loading.) This change is also sufficient to fix the known vulnerability.
+
+- **Ensuring that user-generated HTML is safe**. Schemas can contain Markdown in `description` and `deprecationReason` fields, and the web app renders them to HTML using the `markdown-it` library. Prior to `graphql-playground-react@1.7.28`, GraphQL Playground used two separate libraries to render Markdown: `markdown-it` and `marked`. As part of the development of `graphql-playground-react@1.7.28`, we verified that our use of `markdown-it` prevents the inclusion of arbitrary HTML. We use `markdown-it` without setting `html: true`, so we are comfortable relying on [`markdown-it`'s HTML escaping](https://github.com/markdown-it/markdown-it/blob/master/docs/security.md) here. We considered running a second level of sanitization over all rendered Markdown using a library such as `dompurify` but believe that is unnecessary as `markdown-it`'s sanitization appears to be adequate. `graphiql@1.4.3` does update to the latest version of `markdown-it` (v12, from v10) so that any security fixes in v11 and v12 will take effect. On the other hand, [`marked`](https://github.com/markedjs/marked) recommends the use of a separate HTML sanitizer if its input is untrusted. In this release, we switch the one component which uses `marked` to use `markdown-it` like the rest of the app.
+
+**If you are using `graphql-playground-react` directly in your client app**, upgrade to version 1.7.28 or later.
+
+**If you are using `graphql-playground-html` or a package which starts with `graphql-playground-middleware-` in your server** and you are passing the `version` option to a function imported from that package, change that `version` option to be at least `"1.7.28"`.
+
+**If you are using `graphql-playground-html` or a package which starts with `graphql-playground-middleware-` in your server** and you are **NOT** passing the `version` option to a function imported from that package, no action is necessary; your app automatically loads the latest version of `graphql-playground-react` from CDN.
+
+
+### 4. Reproducing the exploit
+
+We are hosting a "malicious" server at https://graphql-xss-schema.netlify.app/graphql . This server has a hard-coded introspection result that includes unsafe HTML in type names.
+
+If you manually change a GraphQL Playground installation to use that endpoint, clear the operation pane, and type `{x` into the operation pane, an alert will pop up; this demonstrates execution of code provided by the malicious server.
+
+An URL like https://YOUR-PLAYGROUND-SERVER/?endpoint=https%3A%2F%2Fgraphql-xss-schema.netlify.app%2Fgraphql&query=%7B will load already configured with the endpoint in question. (This URL-based exploit works on `graphql-playground-react@1.7.0` and newer; older versions may be protected from this particular URL-based exploit depending on their configuration.)
+### 5. Credit
+
+This vulnerability was discovered by [@Ry0taK](https://github.com/Ry0taK), thank you! :1st_place_medal:
+
+Others who contributed:
+
+- extensive help from [@glasser](https://github.com/glasser) at [Apollo](https://github.com/apollographql)
+- [@acao](https://github.com/acao)
+- [@imolorhe](https://github.com/imolorhe)
+- [@divyenduz](https://github.com/divyenduz)
+- [@dotansimha](https://github.com/dotansimha)
+- [@timsuchanek](http://github.com/timsuchanek)
+- [@benjie](https://github.com/Ry0taK) and many others who provided morale support
+
+### 6. For more information
+
+If you have any questions or comments about this advisory:
+
+- The `graphiql` advisory document contains [more information](https://github.com/graphql/graphiql/blob/main/docs/security/2021-introspection-schema-xss.md#2-more-details-on-the-vulnerability) about how both the client-side and server-side vulnerabilities work
+- Open an issue in the [graphql-playground repo](https://github.com/graphql/graphql-playground/new/issues)

programming_language: Markdown
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -52,7 +52,9 @@
     "@babel/preset-env": "^7.0.0",
     "@babel/preset-react": "^7.0.0",
     "@types/deasync": "0.1.0",
+    "@types/escape-html": "^1.0.1",
     "@types/jest": "22.2.3",
+    "@types/markdown-it": "^12.2.3",
     "@types/node": "12.12.34",
     "@types/react": "16.9.32",
     "@types/zen-observable": "^0.5.3",
@@ -119,6 +121,7 @@
     "copy-to-clipboard": "^3.0.8",
     "cryptiles": "4.1.2",
     "cuid": "^1.3.8",
+    "escape-html": "^1.0.3",
     "graphiql": "^0.17.5",
     "graphql": "^15.3.0",
     "immutable": "^4.0.0-rc.9",
@@ -128,8 +131,8 @@
     "keycode": "^2.1.9",
     "lodash": "^4.17.11",
     "lodash.debounce": "^4.0.8",
-    "markdown-it": "^8.4.1",
-    "marked": "^0.8.2",
+    "lru-cache": "^6.0.0",
+    "markdown-it": "^12.2.0",
     "prettier": "2.0.2",
     "prop-types": "^15.7.2",
     "query-string": "5",

programming_language: JavaScript
filename: index.test.tsx.snap
change_type: ModificationType.MODIFY
diff: @@ -94,7 +94,7 @@ exports[`test MiddleWareApp passed default headers 1`] = `
             class="sc-EHOje cIypmL"
           >
             <div
-              class="sc-ifAKCX dAtAHQ"
+              class="sc-ifAKCX cEPVvT"
             >
               <div
                 class="sc-cvbbAY kOflzg"
@@ -142,7 +142,7 @@ exports[`test MiddleWareApp passed default headers 1`] = `
                   class="sc-cMhqgX dUUizb"
                 >
                   <div
-                    class="sc-ifAKCX dAtAHQ"
+                    class="sc-ifAKCX cEPVvT"
                   >
                     <div
                       class="sc-bZQynM imcoIY"
@@ -403,7 +403,7 @@ exports[`test MiddleWareApp with tabs 1`] = `
             class="sc-EHOje cIypmL"
           >
             <div
-              class="sc-ifAKCX dAtAHQ"
+              class="sc-ifAKCX cEPVvT"
             >
               <div
                 class="sc-cvbbAY kOflzg"
@@ -451,7 +451,7 @@ exports[`test MiddleWareApp with tabs 1`] = `
                   class="sc-cMhqgX dUUizb"
                 >
                   <div
-                    class="sc-ifAKCX dAtAHQ"
+                    class="sc-ifAKCX cEPVvT"
                   >
                     <div
                       class="sc-bZQynM imcoIY"
@@ -712,7 +712,7 @@ exports[`test MiddleWareApp without tabs 1`] = `
             class="sc-EHOje cIypmL"
           >
             <div
-              class="sc-ifAKCX dAtAHQ"
+              class="sc-ifAKCX cEPVvT"
             >
               <div
                 class="sc-cvbbAY kOflzg"
@@ -760,7 +760,7 @@ exports[`test MiddleWareApp without tabs 1`] = `
                   class="sc-cMhqgX dUUizb"
                 >
                   <div
-                    class="sc-ifAKCX dAtAHQ"
+                    class="sc-ifAKCX cEPVvT"
                   >
                     <div
                       class="sc-bZQynM imcoIY"

programming_language: HTML
filename: Playground.tsx
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,7 @@ import {
 } from '../state/sessions/actions'
 import { setConfigString } from '../state/general/actions'
 import { initState } from '../state/workspace/actions'
-import { GraphQLSchema } from 'graphql'
+import { GraphQLSchema, validateSchema } from 'graphql'
 import { createStructuredSelector } from 'reselect'
 import {
   getIsConfigTab,
@@ -51,6 +51,7 @@ import { getSettings, getSettingsString } from '../state/workspace/reducers'
 import { Backoff } from './Playground/util/fibonacci-backoff'
 import { debounce } from 'lodash'
 import { cachedPrintSchema } from './util'
+import { InvalidSchemaError } from './Playground/util/InvalidSchemaError'
 
 export interface Response {
   resultID: string
@@ -182,6 +183,13 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
   constructor(props: Props & ReduxProps) {
     super(props)
 
+    if (props.schema) {
+      const validationErrors = validateSchema(props.schema)
+      if (validationErrors && validationErrors.length > 0) {
+        throw new InvalidSchemaError(validationErrors);
+      }  
+    }
+
     this.state = {
       schema: props.schema,
     }
@@ -247,6 +255,10 @@ export class Playground extends React.PureComponent<Props & ReduxProps, State> {
       this.props.setConfigString(nextProps.configString)
     }
     if (nextProps.schema !== this.props.schema) {
+      const validationErrors = validateSchema(nextProps.schema)
+      if (validationErrors && validationErrors.length > 0) {
+        throw new InvalidSchemaError(validationErrors);
+      }  
       this.setState({ schema: nextProps.schema })
     }
   }

programming_language: TypeScript
filename: SchemaFetcher.ts
change_type: ModificationType.MODIFY
diff: @@ -2,9 +2,12 @@ import {
   GraphQLSchema,
   getIntrospectionQuery,
   buildClientSchema,
+  validateSchema,
+  IntrospectionQuery,
 } from 'graphql'
 import { NoSchemaError } from './util/NoSchemaError'
-import { ApolloLink, execute } from 'apollo-link'
+import { InvalidSchemaError } from './util/InvalidSchemaError'
+import { ApolloLink, execute, toPromise } from 'apollo-link'
 import { Map, set } from 'immutable'
 import { makeOperation } from './util/makeOperation'
 import { parseHeaders } from './util/parseHeaders'
@@ -92,75 +95,76 @@ export class SchemaFetcher {
   hash(session: SchemaFetchProps) {
     return `${session.endpoint}~${session.headers || ''}`
   }
-  private getSchema(data: any) {
+  private getSchema(data: IntrospectionQuery) {
     const schemaString = JSON.stringify(data)
     const cachedSchema = this.schemaInstanceCache.get(schemaString)
     if (cachedSchema) {
       return cachedSchema
     }
 
-    const schema = buildClientSchema(data as any)
+    const schema = buildClientSchema(data)
 
+    const validationErrors = validateSchema(schema)
+    if (validationErrors && validationErrors.length > 0) {
+      throw new InvalidSchemaError(validationErrors)
+    }
     this.schemaInstanceCache.set(schemaString, schema)
 
     return schema
   }
-  private fetchSchema(
+  private async fetchSchema(
     session: SchemaFetchProps,
   ): Promise<{ schema: GraphQLSchema; tracingSupported: boolean } | null> {
     const hash = this.hash(session)
-    const { endpoint } = session
-    const headersTracing = {
-      ...parseHeaders(session.headers),
-      'X-Apollo-Tracing': '1',
-    }
-    const headersNoTracing = {
-      ...parseHeaders(session.headers),
-    }
-    const headers = session.useTracingHeader ? headersTracing : headersNoTracing
+    try {
+      const { endpoint } = session
+      const headersTracing = {
+        ...parseHeaders(session.headers),
+        'X-Apollo-Tracing': '1',
+      }
+      const headersNoTracing = {
+        ...parseHeaders(session.headers),
+      }
+      const headers = session.useTracingHeader
+        ? headersTracing
+        : headersNoTracing
 
-    const options = set(session, 'headers', headers) as any
+      const options = set(session, 'headers', headers) as any
 
-    const { link } = this.linkGetter(options)
+      const { link } = this.linkGetter(options)
 
-    const operation = makeOperation({ query: getIntrospectionQuery() })
+      const operation = makeOperation({ query: getIntrospectionQuery() })
 
-    return new Promise((resolve, reject) => {
-      execute(link, operation).subscribe({
-        next: schemaData => {
-          if (
-            schemaData &&
-            ((schemaData.errors && schemaData.errors.length > 0) ||
-              !schemaData.data)
-          ) {
-            throw new Error(JSON.stringify(schemaData, null, 2))
-          }
+      const schemaData = await toPromise(execute(link, operation))
+      if (
+        schemaData &&
+        ((schemaData.errors && schemaData.errors.length > 0) ||
+          !schemaData.data)
+      ) {
+        throw new Error(JSON.stringify(schemaData, null, 2))
+      }
 
-          if (!schemaData) {
-            throw new NoSchemaError(endpoint)
-          }
+      if (!schemaData) {
+        throw new NoSchemaError(endpoint)
+      }
 
-          const schema = this.getSchema(schemaData.data as any)
-          const tracingSupported =
-            (schemaData.extensions && Boolean(schemaData.extensions.tracing)) ||
-            false
-          const result: TracingSchemaTuple = {
-            schema,
-            tracingSupported,
-          }
-          this.sessionCache.set(this.hash(session), result)
-          resolve(result)
-          this.fetching = this.fetching.remove(hash)
-          const subscription = this.subscriptions.get(hash)
-          if (subscription) {
-            subscription(result.schema)
-          }
-        },
-        error: err => {
-          reject(err)
-          this.fetching = this.fetching.remove(this.hash(session))
-        },
-      })
-    })
+      const schema = this.getSchema(schemaData.data as IntrospectionQuery)
+
+      const tracingSupported =
+        (schemaData.extensions && Boolean(schemaData.extensions.tracing)) ||
+        false
+      const result: TracingSchemaTuple = {
+        schema,
+        tracingSupported,
+      }
+      this.sessionCache.set(this.hash(session), result)
+      const subscription = this.subscriptions.get(hash)
+      if (subscription) {
+        subscription(result.schema)
+      }
+      return result
+    } finally {
+      this.fetching.remove(hash)
+    }
   }
 }

programming_language: TypeScript
filename: onHasCompletion.tsx
change_type: ModificationType.MODIFY
diff: @@ -6,7 +6,10 @@
  *  LICENSE file in the root directory of this source tree.
  */
 
-import * as marked from 'marked'
+const escapeHTML = require('escape-html');
+import * as MD from 'markdown-it';
+
+const md = new MD();
 
 /**
  * Render a custom UI for CodeMirror's hint which includes additional info
@@ -101,7 +104,7 @@ export default function onHasCompletion(cm, data, onHintInformationRender) {
 
     // Now that the UI has been set up, add info to information.
     const description = ctx.description
-      ? marked(ctx.description, { sanitize: true })
+      ? md.render(ctx.description)
       : ''
     const type =
       ctx.type && ctx.type !== 'undefined'
@@ -117,7 +120,7 @@ export default function onHasCompletion(cm, data, onHintInformationRender) {
 
     if (ctx.isDeprecated) {
       const reason = ctx.deprecationReason
-        ? marked(ctx.deprecationReason, { sanitize: true })
+        ? md.render(ctx.deprecationReason)
         : ''
       deprecation.innerHTML =
         '<span class="deprecation-label">Deprecated</span>' + reason
@@ -134,5 +137,5 @@ export default function onHasCompletion(cm, data, onHintInformationRender) {
 }
 
 function renderType(type) {
-  return `<a class="typeName">${type}</a>`
+  return `<a class="typeName">${escapeHTML(type.toString())}</a>`
 }

programming_language: CoffeeScript
filename: InvalidSchemaError.ts
change_type: ModificationType.ADD
diff: @@ -0,0 +1,9 @@
+import type { GraphQLError } from "graphql";
+
+export class InvalidSchemaError extends Error {
+  constructor(validationErrors: readonly GraphQLError[]) {
+    super(
+      `Invalid schema Error:\n${validationErrors.join('\n')}`,
+    )
+  }
+}

programming_language: TypeScript
filename: yarn.lock
change_type: ModificationType.MODIFY
diff: @@ -2314,6 +2314,11 @@
   resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd"
   integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==
 
+"@types/escape-html@^1.0.1":
+  version "1.0.1"
+  resolved "https://registry.yarnpkg.com/@types/escape-html/-/escape-html-1.0.1.tgz#b19b4646915f0ae2c306bf984dc0a59c5cfc97ba"
+  integrity sha512-4mI1FuUUZiuT95fSVqvZxp/ssQK9zsa86S43h9x3zPOSU9BBJ+BfDkXwuaU7BfsD+e7U0/cUUfJFk3iW2M4okA==
+
 "@types/events@*":
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
@@ -2358,11 +2363,29 @@
   resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
   integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==
 
+"@types/linkify-it@*":
+  version "3.0.2"
+  resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.2.tgz#fd2cd2edbaa7eaac7e7f3c1748b52a19143846c9"
+  integrity sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA==
+
 "@types/lru-cache@^4.1.1":
   version "4.1.2"
   resolved "https://registry.yarnpkg.com/@types/lru-cache/-/lru-cache-4.1.2.tgz#528ba392658055dba78fc3be906ca338a1a2d1c5"
   integrity sha512-ve2IoUJClE+4S/sG2zoLGEHP6DCvqgyz7UkHZdiICdQaAYRaCXsRWfJlbL8B0KvUyo9lgzD+oR0YSy4YikFyFQ==
 
+"@types/markdown-it@^12.2.3":
+  version "12.2.3"
+  resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-12.2.3.tgz#0d6f6e5e413f8daaa26522904597be3d6cd93b51"
+  integrity sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==
+  dependencies:
+    "@types/linkify-it" "*"
+    "@types/mdurl" "*"
+
+"@types/mdurl@*":
+  version "1.0.2"
+  resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9"
+  integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==
+
 "@types/minimatch@*":
   version "3.0.3"
   resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -3092,6 +3115,11 @@ argparse@^1.0.7:
   dependencies:
     sprintf-js "~1.0.2"
 
+argparse@^2.0.1:
+  version "2.0.1"
+  resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
+  integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
+
 arr-diff@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf"
@@ -6918,6 +6946,11 @@ entities@^2.0.0, entities@~2.0.0:
   resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.0.tgz#68d6084cab1b079767540d80e56a39b423e4abf4"
   integrity sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==
 
+entities@~2.1.0:
+  version "2.1.0"
+  resolved "https://registry.yarnpkg.com/entities/-/entities-2.1.0.tgz#992d3129cf7df6870b96c57858c249a120f8b8b5"
+  integrity sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==
+
 env-paths@^2.2.0:
   version "2.2.0"
   resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-2.2.0.tgz#cdca557dc009152917d6166e2febe1f039685e43"
@@ -10701,6 +10734,13 @@ linkify-it@^2.0.0:
   dependencies:
     uc.micro "^1.0.1"
 
+linkify-it@^3.0.1:
+  version "3.0.3"
+  resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-3.0.3.tgz#a98baf44ce45a550efb4d49c769d07524cc2fa2e"
+  integrity sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==
+  dependencies:
+    uc.micro "^1.0.1"
+
 lint-staged@6.1.0:
   version "6.1.0"
   resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-6.1.0.tgz#28f600c10a6cbd249ceb003118a1552e53544a93"
@@ -11339,22 +11379,17 @@ markdown-it@^10.0.0:
     mdurl "^1.0.1"
     uc.micro "^1.0.5"
 
-markdown-it@^8.4.1:
-  version "8.4.2"
-  resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54"
-  integrity sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==
+markdown-it@^12.2.0:
+  version "12.2.0"
+  resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-12.2.0.tgz#091f720fd5db206f80de7a8d1f1a7035fd0d38db"
+  integrity sha512-Wjws+uCrVQRqOoJvze4HCqkKl1AsSh95iFAeQDwnyfxM09divCBSXlDR1uTvyUP3Grzpn4Ru8GeCxYPM8vkCQg==
   dependencies:
-    argparse "^1.0.7"
-    entities "~1.1.1"
-    linkify-it "^2.0.0"
+    argparse "^2.0.1"
+    entities "~2.1.0"
+    linkify-it "^3.0.1"
     mdurl "^1.0.1"
     uc.micro "^1.0.5"
 
-marked@^0.8.2:
-  version "0.8.2"
-  resolved "https://registry.yarnpkg.com/marked/-/marked-0.8.2.tgz#4faad28d26ede351a7a1aaa5fec67915c869e355"
-  integrity sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==
-
 math-expression-evaluator@^1.2.14:
   version "1.2.22"
   resolved "https://registry.yarnpkg.com/math-expression-evaluator/-/math-expression-evaluator-1.2.22.tgz#c14dcb3d8b4d150e5dcea9c68c8dad80309b0d5e"

programming_language: Shell