# GHSA-95m2-chm4-mq7m: PHP-Textile has persistent XSS vulnerability in image link handling

> Persistent XSS in PHP-Textile allows attackers to inject JavaScript via image links in restricted mode, requiring user interaction to execute.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 7 Jan 2025

## What is GHSA-95m2-chm4-mq7m?

GHSA-95m2-chm4-mq7m is a cross-site scripting vulnerability in netcarver/textile, published on 7 Jan 2025. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.

### Official description

### Details

Persistent XSS vulnerability in image link handling of PHP-Textile versions 4.1.2 and older, when running the parser in restricted mode. In restricted mode it is expected that the input would be sanitized, allowing user-input (such as user comments) to be parsed and handled safely by the PHP-Textile library.

In restricted mode, the version 4.1.2 of the library does not sanitize or validate user-controllable href input in image links, but allows any link protocol or JavaScriptt links to be used. The vulnerability allows an attacker to add malicious JavaScript code to the page which is then executed when an unexpecting user clicks the link.

In non-restricted mode, the library allows mixed HTML input, and any link protocol by design. In restricted mode, text links were already handled correctly and the vulnerability only affects image links.

### Resolution

This issue was fixed in PHP-Textile version 4.1.3. Version 4.1.3 disallows use of JavaScript in image links when the parser is ran in restricted mode. Restricted mode can be enabled with `Parser::setRestricted()` method prior to calling the `parse` method. For more information, see **Parsing unstructed input** in the project's [README](https://github.com/textile/php-textile?tab=readme-ov-file#parsing-untrusted-input).

### PoC

The following Textile input:

```
!securing.pl(Click Tu)!:javascript:document.innerHTML='<script>alert(1);</script>'+document.cookie)
```

Would render as the following HTML even in restricted mode:

`<p><a href="javascript:document.innerHTML=&#39;&lt;script&gt;alert(1);&lt;/script&gt;&#39;+document.cookie"><img alt="Click Tu" src="securing.pl" title="Click Tu"></a>)</p>`

### Impact

The attacker can perform any operation in the application with user’s privileges or remotely control user’s browser with automated tools.

## Which versions are affected by GHSA-95m2-chm4-mq7m?

2 open source packages ship an affected version, including netcarver/textile.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `netcarver/textile` | Packagist | All versions | 4.1.3 |
| `netcarver/textile` | Packagist | All versions | 4.1.3 |

## How do I fix GHSA-95m2-chm4-mq7m?

Upgrade netcarver/textile to 4.1.3 or later.

## Is GHSA-95m2-chm4-mq7m being exploited?

There is no known exploitation of GHSA-95m2-chm4-mq7m in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-95m2-chm4-mq7m and fix it if it is affected.

What it is: GHSA-95m2-chm4-mq7m is a cross-site scripting vulnerability in netcarver/textile, published on 7 Jan 2025. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-95m2-chm4-mq7m in the wild and no public exploit code.

Affected packages and fixed versions:
- netcarver/textile (Packagist): affected all versions; fixed in 4.1.3
- netcarver/textile (Packagist): affected all versions; fixed in 4.1.3

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-95m2-chm4-mq7m/ (Markdown: https://insights.sbomify.com/GHSA-95m2-chm4-mq7m/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-95m2-chm4-mq7m

---
From sbomify Insights: https://insights.sbomify.com/GHSA-95m2-chm4-mq7m/
Summaries are generated and may contain mistakes; the official description above is the record.
