# GHSA-p2g9-94wh-65c2: Space bug in `clean_text`

> Attackers can inject HTML attributes via unquoted fields due to incorrect whitespace handling in the clean_text function.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 19 Jan 2022
- **Also known as:** RUSTSEC-2022-0003

## What is GHSA-p2g9-94wh-65c2?

GHSA-p2g9-94wh-65c2 is a cross-site scripting vulnerability in ammonia, published on 19 Jan 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

An incorrect mapping from HTML specification to ASCII codes was used.
Because HTML treats the Form Feed as whitespace, code like this has an injection bug:

    let html = format!("<div title={}>", clean_text(user_supplied_string));

Applications are not affected if they quote their attributes, or if they don't use `clean_text` at all.

## Which versions are affected by GHSA-p2g9-94wh-65c2?

3 open source packages ship an affected version, including ammonia.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `ammonia` | crates.io | From 3.0.0 | 3.1.3 |
| `ammonia` | crates.io | From 3.0.0 | 3.1.3 |
| `ammonia` | crates.io | From 3.0.0 | 3.1.3 |

## How do I fix GHSA-p2g9-94wh-65c2?

Upgrade ammonia to 3.1.3 or later.

## Is GHSA-p2g9-94wh-65c2 being exploited?

There is no known exploitation of GHSA-p2g9-94wh-65c2 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-p2g9-94wh-65c2 and fix it if it is affected.

What it is: GHSA-p2g9-94wh-65c2 is a cross-site scripting vulnerability in ammonia, published on 19 Jan 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-p2g9-94wh-65c2 in the wild and no public exploit code.

Affected packages and fixed versions:
- ammonia (crates.io): affected from 3.0.0; fixed in 3.1.3
- ammonia (crates.io): affected from 3.0.0; fixed in 3.1.3
- ammonia (crates.io): affected from 3.0.0; fixed in 3.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-p2g9-94wh-65c2/ (Markdown: https://insights.sbomify.com/GHSA-p2g9-94wh-65c2/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-p2g9-94wh-65c2

---
From sbomify Insights: https://insights.sbomify.com/GHSA-p2g9-94wh-65c2/
Summaries are generated and may contain mistakes; the official description above is the record.
