# CVE-2023-22491: gatsby-transformer-remark vulnerable to unsanitized JavaScript code injection

> Attackers can execute arbitrary JavaScript on the build server by injecting code into Markdown files processed by the Gatsby remark plugin.

- **Severity:** High 8.1 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 13 Jan 2023
- **Updated:** 11 Mar 2025
- **Also known as:** GHSA-7ch4-rr99-cqcw, UBUNTU-CVE-2023-22491

## What is CVE-2023-22491?

CVE-2023-22491 is a high-severity code injection vulnerability in gatsbyjs gatsby, published on 13 Jan 2023. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Gatsby is a free and open source framework based on React that helps developers build websites and apps. The gatsby-transformer-remark plugin prior to versions 5.25.1 and 6.3.2 passes input through to the `gray-matter` npm package, which is vulnerable to JavaScript injection in its default configuration, unless input is sanitized.  The vulnerability is present in gatsby-transformer-remark when passing input in data mode (querying MarkdownRemark nodes via GraphQL).  Injected JavaScript executes in the context of the build server. To exploit this vulnerability untrusted/unsanitized input would need to be sourced by or added into a file processed by gatsby-transformer-remark. A patch has been introduced in `gatsby-transformer-remark@5.25.1` and `gatsby-transformer-remark@6.3.2` which mitigates the issue by disabling the `gray-matter` JavaScript Frontmatter engine. As a workaround, if an older version of `gatsby-transformer-remark` must be used, input passed into the plugin should be sanitized ahead of processing. It is encouraged for  projects to upgrade to the latest major release branch for all Gatsby plugins to ensure the latest security updates and bug fixes are received in a timely manner.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation), CWE-89 (Improper Neutralization of Special Elements used in an SQL Command), CWE-20 (Improper Input Validation)

## Which versions are affected by CVE-2023-22491?

4 open source packages ship an affected version, including gatsby-transformer-remark. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `gatsby-transformer-remark` | npm | All versions | 5.25.1 |
| `gatsby-transformer-remark` | npm | All versions | 5.25.1 |
| `gatsby-transformer-remark` | npm | From 6.0.0 | 6.3.2 |
| `gatsby-transformer-remark` | npm | From 6.0.0 | 6.3.2 |

Products: Gatsbyjs Gatsby-Transformer-Remark.

## How do I fix CVE-2023-22491?

Upgrade gatsby-transformer-remark to a fixed version for your release line: 5.25.1 or 6.3.2.

## Is CVE-2023-22491 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2023-22491 exists.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-22491 and fix it if it is affected.

What it is: CVE-2023-22491 is a high-severity code injection vulnerability in gatsbyjs gatsby, published on 13 Jan 2023. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2023-22491 exists.

Affected packages and fixed versions:
- gatsby-transformer-remark (npm): affected all versions; fixed in 5.25.1
- gatsby-transformer-remark (npm): affected all versions; fixed in 5.25.1
- gatsby-transformer-remark (npm): affected from 6.0.0; fixed in 6.3.2
- gatsby-transformer-remark (npm): affected from 6.0.0; fixed in 6.3.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2023-22491/ (Markdown: https://insights.sbomify.com/CVE-2023-22491/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2023-22491
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2023-22491
- OSV: https://osv.dev/vulnerability/CVE-2023-22491

---
From sbomify Insights: https://insights.sbomify.com/CVE-2023-22491/
Summaries are generated and may contain mistakes; the official description above is the record.
