Summary
XSS vulnerability in GraphQL Playground from untrusted schemas
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.
1. Impact
All versions of graphql-playground-react older than [email protected] 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 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 [email protected] 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 for details.
3. Patches
[email protected] 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
innerHTMLAPI 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
descriptionanddeprecationReasonfields, and the web app renders them to HTML using themarkdown-itlibrary. Prior to[email protected], GraphQL Playground used two separate libraries to render Markdown:markdown-itandmarked. As part of the development of[email protected], we verified that our use ofmarkdown-itprevents the inclusion of arbitrary HTML. We usemarkdown-itwithout settinghtml: true, so we are comfortable relying onmarkdown-it's HTML escaping here. We considered running a second level of sanitization over all rendered Markdown using a library such asdompurifybut believe that is unnecessary asmarkdown-it's sanitization appears to be adequate.[email protected]does update to the latest version ofmarkdown-it(v12, from v10) so that any security fixes in v11 and v12 will take effect. On the other hand,markedrecommends the use of a separate HTML sanitizer if its input is untrusted. In this release, we switch the one component which usesmarkedto usemarkdown-itlike 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 [email protected] 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, thank you! :1st_place_medal:
Others who contributed:
- extensive help from @glasser at Apollo
- @acao
- @imolorhe
- @divyenduz
- @dotansimha
- @timsuchanek
- @benjie and many others who provided morale support
6. For more information
If you have any questions or comments about this advisory:
- The
graphiqladvisory document contains more information about how both the client-side and server-side vulnerabilities work - Open an issue in the graphql-playground repo
Impact
Untrusted input is rendered as active markup in a victim's browser, which can run script in their session. Typical impact: session or credential theft, and actions taken as the user.
CVE-2021-41249 has a CVSS score of 7.1 (High). The vector is network-reachable, no privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (1.7.28); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2021-41249? CVE-2021-41249 is a high-severity cross-site scripting (XSS) vulnerability in graphql-playground-react (npm), affecting versions < 1.7.28. It is fixed in 1.7.28. Untrusted input is rendered as active markup in a victim's browser, which can run script in their session.
- How severe is CVE-2021-41249? CVE-2021-41249 has a CVSS score of 7.1 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of graphql-playground-react are affected by CVE-2021-41249? graphql-playground-react (npm) versions < 1.7.28 is affected.
- Is there a fix for CVE-2021-41249? Yes. CVE-2021-41249 is fixed in 1.7.28. Upgrade to this version or later.
- Is CVE-2021-41249 exploitable, and should I be worried? Whether CVE-2021-41249 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2021-41249 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2021-41249? Upgrade
graphql-playground-reactto 1.7.28 or later.