|
| 1 | +--- |
| 2 | +gem: rails-html-sanitizer |
| 3 | +cve: 2022-23519 |
| 4 | +ghsa: 9h9g-93gc-623h |
| 5 | +url: https://github.com/rails/rails-html-sanitizer/security/advisories/GHSA-9h9g-93gc-623h |
| 6 | +title: "Possible XSS vulnerability with certain configurations of rails-html-sanitizer" |
| 7 | +date: 2022-12-13 |
| 8 | +description: | |
| 9 | + ## Summary |
| 10 | +
|
| 11 | + There is a possible XSS vulnerability with certain configurations of Rails::Html::Sanitizer. |
| 12 | +
|
| 13 | + - Versions affected: ALL |
| 14 | + - Not affected: NONE |
| 15 | + - Fixed versions: 1.4.4 |
| 16 | +
|
| 17 | +
|
| 18 | + ## Impact |
| 19 | +
|
| 20 | + A possible XSS vulnerability with certain configurations of Rails::Html::Sanitizer may allow an attacker to inject content if the application developer has overridden the sanitizer's allowed tags in either of the following ways: |
| 21 | +
|
| 22 | + - allow both "math" and "style" elements, |
| 23 | + - or allow both "svg" and "style" elements |
| 24 | +
|
| 25 | + Code is only impacted if allowed tags are being overridden. Applications may be doing this in four different ways: |
| 26 | +
|
| 27 | + 1. using application configuration: |
| 28 | +
|
| 29 | + ```ruby |
| 30 | + # In config/application.rb |
| 31 | + config.action_view.sanitized_allowed_tags = ["math", "style"] |
| 32 | + # or |
| 33 | + config.action_view.sanitized_allowed_tags = ["svg", "style"] |
| 34 | + ``` |
| 35 | +
|
| 36 | + see https://guides.rubyonrails.org/configuring.html#configuring-action-view |
| 37 | +
|
| 38 | + 2. using a `:tags` option to the Action View helper `sanitize`: |
| 39 | +
|
| 40 | + ``` |
| 41 | + <%= sanitize @comment.body, tags: ["math", "style"] %> |
| 42 | + <%# or %> |
| 43 | + <%= sanitize @comment.body, tags: ["svg", "style"] %> |
| 44 | + ``` |
| 45 | +
|
| 46 | + see https://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize |
| 47 | +
|
| 48 | + 3. using Rails::Html::SafeListSanitizer class method `allowed_tags=`: |
| 49 | +
|
| 50 | + ```ruby |
| 51 | + # class-level option |
| 52 | + Rails::Html::SafeListSanitizer.allowed_tags = ["math", "style"] |
| 53 | + # or |
| 54 | + Rails::Html::SafeListSanitizer.allowed_tags = ["svg", "style"] |
| 55 | + ``` |
| 56 | +
|
| 57 | + 4. using a `:tags` options to the Rails::Html::SafeListSanitizer instance method `sanitize`: |
| 58 | +
|
| 59 | + ```ruby |
| 60 | + # instance-level option |
| 61 | + Rails::Html::SafeListSanitizer.new.sanitize(@article.body, tags: ["math", "style"]) |
| 62 | + # or |
| 63 | + Rails::Html::SafeListSanitizer.new.sanitize(@article.body, tags: ["svg", "style"]) |
| 64 | + ``` |
| 65 | +
|
| 66 | + All users overriding the allowed tags by any of the above mechanisms to include (("math" or "svg") and "style") should either upgrade or use one of the workarounds immediately. |
| 67 | +
|
| 68 | +
|
| 69 | + ## Workarounds |
| 70 | +
|
| 71 | + Remove "style" from the overridden allowed tags, or remove "math" and "svg" from the overridden allowed tags. |
| 72 | +
|
| 73 | +
|
| 74 | + ## References |
| 75 | +
|
| 76 | + - [CWE - CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (4.9)](https://cwe.mitre.org/data/definitions/79.html) |
| 77 | + - https://hackerone.com/reports/1656627 |
| 78 | +
|
| 79 | +
|
| 80 | + ## Credit |
| 81 | +
|
| 82 | + This vulnerability was responsibly reported by Dominic Breuker. |
| 83 | +patched_versions: |
| 84 | + - ">= 1.4.4" |
0 commit comments