Cloudanix VulnDB

CVE-2024-45389

Medium · 5.4

CVSS

5.4

EPSS

0.4%

Published

Sep 3, 2024

CISA due date

—

Cloudanix analysis

Monitor only SSVC: Track

A search feature on websites could be tricked into loading code from the wrong place if someone is already able to add certain types of content to the page, giving them more control than they should have.

Chainable
Exploitation
Requires User Interaction
Attacker needs
User Interaction
Complexity
Moderate
Impact
Privilege Gain
Component
Library
Class
XSS
Remediation
Upgrade
Effort
Low
Patch risk
Low

What it actually does

The vulnerability allows an attacker with partial HTML injection capability to manipulate document.currentScript.src lookup, causing Pagefind to resolve and load its JavaScript and WebAssembly dependencies from an attacker-controlled external domain instead of the intended location.

Why it matters to the business

Organizations hosting sites that use Pagefind face increased risk of client-side code execution attacks if an attacker can already inject limited HTML, potentially leading to unauthorized access to user data or site functionality on production websites.

How an attack unfolds

An attacker who can inject benign HTML elements such as img tags with a name attribute on a live site uses this to clobber the script source resolution performed by Pagefind. This causes the library to fetch its dynamic files from a malicious domain, escalating the attacker's privileges to full script execution without directly adding a script tag.

How to fix it

Upgrade Pagefind to version 1.1.1 or later (commit 70012fba86ca51bf1f476c3c64d840a81c60e9cb) to enforce loading only from a valid script element. For Debian packages, update webkit2gtk to version 2.22.0-2 or newer on affected releases.

How to confirm the fix worked

Verify the deployed Pagefind version is 1.1.1 or higher and inspect the initialization code to confirm it validates the script element before resolving the source URL. Test by attempting HTML clobbering on a staging site and confirming dependencies load only from the expected origin.

Typical attack path

  1. Identify a page using Pagefind on a target site
  2. Inject HTML elements with name attributes that interfere with document.currentScript.src resolution
  3. Trigger Pagefind initialization
  4. Force loading of Pagefind dependencies from attacker-controlled domain
  5. Execute arbitrary JavaScript in the victim's browser context

How to detect it

Examine web server and application logs for unexpected external domains in script requests during Pagefind initialization. Review page source and rendered HTML for suspicious img or other elements with name attributes near search script includes. No known in-the-wild exploitation has been reported.

What your security team should do

  • Prioritize upgrade of all Pagefind instances to 1.1.1 or later within standard change windows
  • Review sites for any HTML injection vectors that could enable this escalation
  • Monitor for unusual external script loads originating from Pagefind initialization
  • Apply the fix even on low-EPSS vulnerabilities when the library processes untrusted page content

The record

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.

Affected packages

Ecosystem Package Introduced Fixed
crates.io pagefind 0 1.1.1
npm @pagefind/default-ui 0 1.1.1
npm @pagefind/modular-ui 0 1.1.1
npm pagefind 0 1.1.1
npm vite 0 3.2.11
npm vite 4.0.0 4.5.4
npm vite 5.0.0 5.1.8
npm vite 5.0.0 5.2.14
npm vite 5.2.0 5.2.14
npm vite 5.3.0 5.3.6
npm vite 5.4.0 5.4.6
npm webpack 5.0.0-alpha.0 5.94.0
Debian:11 node-webpack 0 No fix
Debian:12 node-webpack 0 No fix
Debian:13 node-webpack 0 5.94.0+dfsg1+~cs11.18.26-2
Debian:14 node-webpack 0 5.94.0+dfsg1+~cs11.18.26-2

Related vulnerabilities