# GHSA-4m3g-6r7g-jv4f: Arbitrary JavaScript execution due to using outdated libraries

> Attackers can execute arbitrary JavaScript by uploading malicious PDFs to applications using the vulnerable gradio-pdf library.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 5 Jun 2024

## What is GHSA-4m3g-6r7g-jv4f?

GHSA-4m3g-6r7g-jv4f is a cross-site scripting vulnerability in gradio-pdf, published on 5 Jun 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

### Summary
gradio-pdf projects with dependencies on the pdf.js library are vulnerable to CVE-2024-4367, which allows arbitrary JavaScript execution.

### PoC
1. Generate a pdf file with a malicious script in the fontmatrix. (This will run `alert(‘XSS’)`.)
[poc.pdf](https://github.com/user-attachments/files/15516798/poc.pdf)

2. Run the app. In this PoC, I've used the demo for a simple proof.
![1](https://github.com/freddyaboulton/gradio-pdf/assets/114328108/d1bb7626-3d0f-4984-8873-297658d6e77e)

3. Upload a PDF file containing the script.
![2](https://github.com/freddyaboulton/gradio-pdf/assets/114328108/803d8080-c946-446e-bb34-cf5640e1b4de)

4. Check that the script is running.
![3](https://github.com/freddyaboulton/gradio-pdf/assets/114328108/4956b95f-acca-4bb1-a3c2-7dfc96adf890)

### Impact
Malicious scripts can be injected into the code, and when linked with vulnerabilities such as CSRF, it can cause even greater damage. In particular, It can become a source of further attacks, especially when linked to social engineering.

### Mitigation
Upgrade the pdf.js to v4.2.67, which removes the vulnerability. (or set the option `isEvalSupported` to `false`.)

### Reference
1. https://codeanlabs.com/blog/research/cve-2024-4367-arbitrary-js-execution-in-pdf-js/
2. https://github.com/mozilla/pdf.js/pull/18015

## Which versions are affected by GHSA-4m3g-6r7g-jv4f?

2 open source packages ship an affected version, including gradio-pdf and gradio_pdf.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `gradio-pdf` | PyPI | All versions | 0.0.10 |
| `gradio_pdf` | PyPI | All versions | 0.0.10 |

## How do I fix GHSA-4m3g-6r7g-jv4f?

Upgrade gradio-pdf to 0.0.10 or later.

## Is GHSA-4m3g-6r7g-jv4f being exploited?

There is no known exploitation of GHSA-4m3g-6r7g-jv4f in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-4m3g-6r7g-jv4f and fix it if it is affected.

What it is: GHSA-4m3g-6r7g-jv4f is a cross-site scripting vulnerability in gradio-pdf, published on 5 Jun 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-4m3g-6r7g-jv4f in the wild and no public exploit code.

Affected packages and fixed versions:
- gradio-pdf (PyPI): affected all versions; fixed in 0.0.10
- gradio_pdf (PyPI): affected all versions; fixed in 0.0.10

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/GHSA-4m3g-6r7g-jv4f/ (Markdown: https://insights.sbomify.com/GHSA-4m3g-6r7g-jv4f/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-4m3g-6r7g-jv4f

---
From sbomify Insights: https://insights.sbomify.com/GHSA-4m3g-6r7g-jv4f/
Summaries are generated and may contain mistakes; the official description above is the record.
