# RUSTSEC-2021-0158: XSS in ammonia via SVG `animateMotion`, `animateTransform`, and/or `animateColor` tags

> Attackers can execute arbitrary JavaScript via unsanitized SVG animation tags if specific tags are explicitly allowed, requiring user interaction.

- **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:** 10 Oct 2021
- **Also known as:** GHSA-f2pc-rwv3-69mv

## What is RUSTSEC-2021-0158?

RUSTSEC-2021-0158 is a cross-site scripting vulnerability in ammonia, published on 10 Oct 2021. 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

The neutralization that ammonia applied to `animate` and `set` was not applied to other forms of SVG animation, which can be used for XSS.

The following SVG will produce a link with a javascript scheme.
If the user clicks this link, they will run it.

```xml
<svg xmlns="http://www.w3.org/2000/svg">
  <a>
    <animateMotion attributeName="href" to="javascript:alert('SET_XSS')"></animateMotion>
    <text y="30">Click set</text>
  </a>
</svg>
```

Ammonia did not apply attribute filters based on `attributeName`,
so the contents of the `to`, `from`, and `values` tags were not sanitized as URLs.

Applications that do not explicitly allow any of these tags should not be affected,
since none are allowed by default.

---

This vulnerability was reported by [ucsurf](https://uc.surf).

## Which versions are affected by RUSTSEC-2021-0158?

1 open source package ship an affected version, including ammonia.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `ammonia` | crates.io | From 0.0.0-0 | 4.1.7, 4.2.3 |

## How do I fix RUSTSEC-2021-0158?

Upgrade ammonia to a fixed version for your release line: 4.1.7 or 4.2.3.

## Is RUSTSEC-2021-0158 being exploited?

There is no known exploitation of RUSTSEC-2021-0158 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for RUSTSEC-2021-0158 and fix it if it is affected.

What it is: RUSTSEC-2021-0158 is a cross-site scripting vulnerability in ammonia, published on 10 Oct 2021. 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 RUSTSEC-2021-0158 in the wild and no public exploit code.

Affected packages and fixed versions:
- ammonia (crates.io): affected from 0.0.0-0; fixed in 4.1.7, 4.2.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/RUSTSEC-2021-0158/ (Markdown: https://insights.sbomify.com/RUSTSEC-2021-0158/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/RUSTSEC-2021-0158

---
From sbomify Insights: https://insights.sbomify.com/RUSTSEC-2021-0158/
Summaries are generated and may contain mistakes; the official description above is the record.
