# CVE-2024-45389: Pagefind DOM clobbering could escalate to Cross-site Scripting (XSS)

> Attacker with HTML injection capability can escalate to XSS by clobbering script source resolution in Pagefind static search library.

- **Severity:** Medium 6.4 (`CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:H`)
- **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:** 3 Sep 2024
- **Updated:** 3 Sep 2024
- **Also known as:** GHSA-gprj-6m2f-j9hx

## What is CVE-2024-45389?

CVE-2024-45389 is a medium-severity cross-site scripting vulnerability in CloudCannon pagefind, published on 3 Sep 2024. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Pagefind, a fully static search library, initializes its dynamic JavaScript and WebAssembly files relative to the location of the first script the user loads. This information is gathered by looking up the value of `document.currentScript.src`. Prior to Pagefind version 1.1.1, it is possible to "clobber" this lookup with otherwise benign HTML on the page. This will cause `document.currentScript.src` to resolve as an external domain, which will then be used by Pagefind to load dependencies. This exploit would only work in the case that an attacker could inject HTML to a live, hosted, website. In these cases, this would act as a way to escalate the privilege available to an attacker. This assumes they have the ability to add some elements to the page (for example, `img` tags with a `name` attribute), but not others, as adding a `script` to the page would itself be the cross-site scripting vector. Pagefind has tightened this resolution in version 1.1.1 by ensuring the source is loaded from a valid script element. There are no reports of this being exploited in the wild via Pagefind.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2024-45389?

8 open source packages ship an affected version, including pagefind, @pagefind/default-ui and @pagefind/modular-ui. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `pagefind` | crates.io | All versions | 1.1.1 |
| `pagefind` | crates.io | All versions | 1.1.1 |
| `pagefind` | npm | All versions | 1.1.1 |
| `pagefind` | npm | All versions | 1.1.1 |
| `@pagefind/default-ui` | npm | All versions | 1.1.1 |
| `@pagefind/default-ui` | npm | All versions | 1.1.1 |
| `@pagefind/modular-ui` | npm | All versions | 1.1.1 |
| `@pagefind/modular-ui` | npm | All versions | 1.1.1 |

Products: Pagefind Pagefind.

## How do I fix CVE-2024-45389?

Upgrade pagefind to 1.1.1 or later.

## Is CVE-2024-45389 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-45389 and fix it if it is affected.

What it is: CVE-2024-45389 is a medium-severity cross-site scripting vulnerability in CloudCannon pagefind, published on 3 Sep 2024. 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-2024-45389 exists.

Affected packages and fixed versions:
- pagefind (crates.io): affected all versions; fixed in 1.1.1
- pagefind (crates.io): affected all versions; fixed in 1.1.1
- pagefind (npm): affected all versions; fixed in 1.1.1
- pagefind (npm): affected all versions; fixed in 1.1.1
- @pagefind/default-ui (npm): affected all versions; fixed in 1.1.1
- @pagefind/default-ui (npm): affected all versions; fixed in 1.1.1
- @pagefind/modular-ui (npm): affected all versions; fixed in 1.1.1
- @pagefind/modular-ui (npm): affected all versions; fixed in 1.1.1

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-2024-45389/ (Markdown: https://insights.sbomify.com/CVE-2024-45389/index.md)
```

## Sources

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

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