#  CVE-2022-23520: Incomplete fix for CVE-2022-32209 (XSS in Rails::Html::Sanitizer under certain configurations)

Incomplete fix for CVE-2022-32209: SafeListSanitizer only stripped 'style' from per-call tags, not class-level allowed_tags, so config-set select+style still allowed XSS.

- Payout: $2,400
- Severity: medium
- Program: Internet Bug Bounty
- Found by: 0b5cur17y
- Disclosed: 2023-01-04
- CVE: CVE-2022-32209, CVE-2022-23520
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1805893
- Library page: https://bugbountylibrary.com/r/h1%3A1805893
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:medium tech:ruby technique:chained technique:incomplete-fix technique:source-review vuln:xss

**Target:** Rails::Html::SafeListSanitizer (rails-html-sanitizer gem)
**Root cause:** remove_safelist_tag_combinations was applied only to options[:tags] in allowed_tags, not to self.class.allowed_tags, so class-level allowlists (set via config.action_view.sanitized_allowed_tags or SafeListSanitizer.allowed_tags=) kept both select and style.
**Steps:**
1. Create Rails 7.0.3.1 app via `rails new`.
2. Add `config.action_view.sanitized_allowed_tags = ["select", "style"]` to config/application.rb.
3. Create endpoint reflecting sanitized param: `<p>Hello <%= sanitize @name %></p>`.
4. Send payload `<select><style><script>alert("XSS")</script></style></select>` as the parameter.
5. Observe alert fires on rails-html-sanitizer 1.4.2 and 1.4.3; 1.4.4 is the fixed version.
6. Confirm moving tags to `<p>Hello <%= sanitize @name, tags: ["select", "style"] %></p>` is fixed by 1.4.3, proving the class-level path was missed.
**How found:** While building a PoC for CVE-2022-32209, the researcher found updating 1.4.2→1.4.3 did not fix their app; they traced the fix commit and noticed remove_safelist_tag_combinations was only called on options[:tags], not self.class.allowed_tags, then confirmed via puts that config sets the class variable.
**Exploitation:** Attacker injects a select+style combination that the sanitizer fails to strip when the app uses class-level allowed tags; the nested script executes in victim browser, yielding XSS.
**Insight:** When a patch adds a sanitization/cleanup helper, check every code path that supplies the same input (per-call option vs class-level config vs default) — incomplete fixes often guard only the path named in the original report.

## Proof of concept (copied exactly from the original report)

**XSS payload for select/style sanitizer bypass**

```
When using the payload `<select><style><script>alert("XSS")</script></style></select>` for the parameter I got an alert no matter what the version of rails-html-sanitizer was.
```

**Vulnerable app config and ERB endpoint**

```
adding `config.action_view.sanitized_allowed_tags = ["select", "style"]` to the file `config/application.rb` and creating an endpoint that reflected a parameter after sanitizing it (ERB: `<p>Hello <%= sanitize @name %></p>`).
```

## Write-ups of the same bug (oldest first)
- 2022-06-27: [Rails::Html::SafeListSanitizer vulnerable to xss attack in an environment that allows the style tag](https://bugbountylibrary.com/r/h1%3A1599573) — windshock
- 2023-01-04: [ CVE-2022-23520: Incomplete fix for CVE-2022-32209 (XSS in Rails::Html::Sanitizer under certain configurations)](https://bugbountylibrary.com/r/h1%3A1805893) — 0b5cur17y (this one)

