# CVE-2024-53985: Possible XSS vulnerability with certain configurations of rails-html-sanitizer 1.6.0

> Attackers can inject malicious scripts via XSS if developers override sanitizer tags to include math/svg and style elements.

- **Severity:** Low 2.3 (`CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N`)
- **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:** 2 Dec 2024
- **Updated:** 11 Dec 2024
- **Also known as:** GHSA-w8gc-x259-rc7x, UBUNTU-CVE-2024-53985

## What is CVE-2024-53985?

CVE-2024-53985 is a low-severity cross-site scripting vulnerability in rails-html-sanitizer, published on 2 Dec 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

rails-html-sanitizer is responsible for sanitizing HTML fragments in Rails applications. There is a possible XSS vulnerability with certain configurations of Rails::HTML::Sanitizer 1.6.0 when used with Rails >= 7.1.0 and Nokogiri < 1.15.7, or 1.16.x < 1.16.8. The XSS vulnerability with certain configurations of Rails::HTML::Sanitizer may allow an attacker to inject content if HTML5 sanitization is enabled and the application developer has overridden the sanitizer's allowed tags with both "math" and "style" elements or both both "svg" and "style" elements. This vulnerability is fixed in 1.6.1.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2024-53985?

2 open source packages ship an affected version, including rails-html-sanitizer. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `rails-html-sanitizer` | RubyGems | From 1.6.0 | 1.6.1 |
| `rails-html-sanitizer` | RubyGems | From 1.6.0 | 1.6.1 |

Products: Rubyonrails Rails Html Sanitizers.

## How do I fix CVE-2024-53985?

Upgrade rails-html-sanitizer to 1.6.1 or later.

## Is CVE-2024-53985 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-53985 exists.

## Other vulnerabilities in rails-html-sanitizer

- [CVE-2024-53986](https://insights.sbomify.com/CVE-2024-53986/): Possible XSS vulnerability with certain configurations of rails-html-sanitizer 1.6.0 (low 2.3)
- [CVE-2024-53987](https://insights.sbomify.com/CVE-2024-53987/): Possible XSS vulnerability with certain configurations of rails-html-sanitizer 1.6.0 (low 2.3)
- [CVE-2024-53988](https://insights.sbomify.com/CVE-2024-53988/): Possible XSS vulnerability with certain configurations of rails-html-sanitizer 1.6.0 (low 2.3)
- [CVE-2024-53989](https://insights.sbomify.com/CVE-2024-53989/): Possible XSS vulnerability with certain configurations of rails-html-sanitizer 1.6.0 (low 2.3)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-53985 and fix it if it is affected.

What it is: CVE-2024-53985 is a low-severity cross-site scripting vulnerability in rails-html-sanitizer, published on 2 Dec 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: It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-53985 exists.

Affected packages and fixed versions:
- rails-html-sanitizer (RubyGems): affected from 1.6.0; fixed in 1.6.1
- rails-html-sanitizer (RubyGems): affected from 1.6.0; fixed in 1.6.1

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/CVE-2024-53985/ (Markdown: https://insights.sbomify.com/CVE-2024-53985/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-53985
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-53985
- OSV: https://osv.dev/vulnerability/CVE-2024-53985

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