# GHSA-gwpm-pm6x-h7rj: ZendFramework Cross-site Scripting vector in `Zend_Filter_StripTags`

> An XSS vulnerability in Zend_Filter_StripTags allows attackers to inject scripts via whitespace in attributes when using attribute whitelisting.

- **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:** 7 Jun 2024

## What is GHSA-gwpm-pm6x-h7rj?

GHSA-gwpm-pm6x-h7rj is a cross-site scripting vulnerability in zendframework/zendframework1, published on 7 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

`Zend_Filter_StripTags` is a filtering class analogous to PHP's `strip_tags()` function. In addition to stripping HTML tags and selectively keeping those provided in a whitelist, it also provides the ability to whitelist specific attributes to retain per whitelisted tag.

The reporter discovered that attributes that contained whitespace, and in paricular, line breaks, surrounding the attribute assignment operator would not be stripped, regardless of whether or not they were whitelisted. As examples of input affected:
```
<!-- newlines before and/or after assignment: -->
<a href="http://framework.zend.com/issues" onclick
=
"alert('Broken'); return false;">Issues</a>
```
When passed to the following code:
```
$filter = new Zend_Filter_StripTags(array('a' => array('href')));
$value  = $filter->($html);
```
then the "onclick" attribute would remain, even though it was not specified in the tag's whitelist. This could open potential cross-site scripting attack (XSS) vectors.

## Recommendations
If you were using `Zend_Filter_StripTags` and utlizing the attribute whitelisting functionality, you should immediately upgrade to Zend Framework 1.7.6 or above; regardless, it is always best to run the most current version of the framework.

Also, if relying on `Zend_Filter_StripTags` to prevent XSS, the only way to reliably do so is to strip all tags, and never to whitelist. If you are whitelisting, you should consider finding a reliable XSS filter through which to run your output; we recommend HTML Purifier.

## Which versions are affected by GHSA-gwpm-pm6x-h7rj?

2 open source packages ship an affected version, including zendframework/zendframework1.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `zendframework/zendframework1` | Packagist | From 1.7.0 | 1.7.6 |
| `zendframework/zendframework1` | Packagist | From 1.7.0 | 1.7.6 |

## How do I fix GHSA-gwpm-pm6x-h7rj?

Upgrade zendframework/zendframework1 to 1.7.6 or later.

## Is GHSA-gwpm-pm6x-h7rj being exploited?

There is no known exploitation of GHSA-gwpm-pm6x-h7rj in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-gwpm-pm6x-h7rj and fix it if it is affected.

What it is: GHSA-gwpm-pm6x-h7rj is a cross-site scripting vulnerability in zendframework/zendframework1, published on 7 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-gwpm-pm6x-h7rj in the wild and no public exploit code.

Affected packages and fixed versions:
- zendframework/zendframework1 (Packagist): affected from 1.7.0; fixed in 1.7.6
- zendframework/zendframework1 (Packagist): affected from 1.7.0; fixed in 1.7.6

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-gwpm-pm6x-h7rj/ (Markdown: https://insights.sbomify.com/GHSA-gwpm-pm6x-h7rj/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-gwpm-pm6x-h7rj

---
From sbomify Insights: https://insights.sbomify.com/GHSA-gwpm-pm6x-h7rj/
Summaries are generated and may contain mistakes; the official description above is the record.
