|
| 1 | +--- |
| 2 | +gem: rails-html-sanitizer |
| 3 | +framework: rails |
| 4 | +cve: 2024-53985 |
| 5 | +ghsa: w8gc-x259-rc7x |
| 6 | +url: https://github.com/rails/rails-html-sanitizer/security/advisories/GHSA-w8gc-x259-rc7x |
| 7 | +title: rails-html-sanitizer has XSS vulnerability with certain configurations |
| 8 | +date: 2024-12-02 |
| 9 | +description: | |
| 10 | + ## Summary |
| 11 | +
|
| 12 | + There is a possible XSS vulnerability with certain configurations of |
| 13 | + Rails::HTML::Sanitizer 1.6.0 when used with Rails >= 7.1.0 and |
| 14 | + Nokogiri < 1.15.7, or 1.16.x < 1.16.8. |
| 15 | +
|
| 16 | + * Versions affected: 1.6.0 |
| 17 | + * Not affected: < 1.6.0 |
| 18 | + * Fixed versions: 1.6.1 |
| 19 | +
|
| 20 | + Please note that the fix in v1.6.1 is to update the dependency on |
| 21 | + Nokogiri to 1.15.7 or >= 1.16.8. |
| 22 | +
|
| 23 | + ## Impact |
| 24 | +
|
| 25 | + A possible XSS vulnerability with certain configurations of |
| 26 | + Rails::HTML::Sanitizer may allow an attacker to inject content if |
| 27 | + HTML5 sanitization is enabled and the application developer has |
| 28 | + overridden the sanitizer's allowed tags in either of the following ways: |
| 29 | +
|
| 30 | + * allow both "math" and "style" elements |
| 31 | + * or allow both "svg" and "style" elements |
| 32 | +
|
| 33 | + Code is only impacted if Rails is configured to use HTML5 sanitization, |
| 34 | + please see documentation for |
| 35 | + [`config.action_view.sanitizer_vendor`](https://guides.rubyonrails.org/configuring.html#config-action-view-sanitizer-vendor) |
| 36 | + and [`config.action_text.sanitizer_vendor`](https://guides.rubyonrails.org/configuring.html#config-action-text-sanitizer-vendor) |
| 37 | + for more information on these configuration options. |
| 38 | +
|
| 39 | + Code is only impacted if allowed tags are being overridden. |
| 40 | + Applications may be doing this in a few different ways: |
| 41 | +
|
| 42 | + 1. using application configuration to configure Action View |
| 43 | + sanitizers' allowed tags: |
| 44 | +
|
| 45 | + ```ruby |
| 46 | + # In config/application.rb |
| 47 | + config.action_view.sanitized_allowed_tags = ["math", "style"] |
| 48 | + # or |
| 49 | + config.action_view.sanitized_allowed_tags = ["svg", "style"] |
| 50 | + ``` |
| 51 | +
|
| 52 | + see https://guides.rubyonrails.org/configuring.html#configuring-action-view |
| 53 | +
|
| 54 | + 2. using a `:tags` option to the Action View helper `sanitize`: |
| 55 | +
|
| 56 | + ``` |
| 57 | + <= sanitize @comment.body, tags: ["math", "style"] > |
| 58 | + <# or> |
| 59 | + <= sanitize @comment.body, tags: ["svg", "style"] > |
| 60 | + ``` |
| 61 | +
|
| 62 | + see https://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize |
| 63 | +
|
| 64 | + 3. setting Rails::HTML5::SafeListSanitizer class attribute `allowed_tags`: |
| 65 | +
|
| 66 | + ```ruby |
| 67 | + # class-level option |
| 68 | + Rails::HTML5::SafeListSanitizer.allowed_tags = ["math", "style"] |
| 69 | + # or |
| 70 | + Rails::HTML5::SafeListSanitizer.allowed_tags = ["svg", "style"] |
| 71 | + ``` |
| 72 | +
|
| 73 | + (note that this class may also be referenced as |
| 74 | + `Rails::Html::SafeListSanitizer`) |
| 75 | +
|
| 76 | + 4. using a `:tags` options to the Rails::HTML5::SafeListSanitizer |
| 77 | + instance method `sanitize`: |
| 78 | +
|
| 79 | + ```ruby |
| 80 | + # instance-level option |
| 81 | + Rails::HTML5::SafeListSanitizer.new.sanitize(@article.body, tags: ["math", "style"]) |
| 82 | + # or |
| 83 | + Rails::HTML5::SafeListSanitizer.new.sanitize(@article.body, tags: ["svg", "style"]) |
| 84 | + ``` |
| 85 | + (note that this class may also be referenced as `Rails::Html::SafeListSanitizer`) |
| 86 | +
|
| 87 | + 5. setting ActionText::ContentHelper module attribute `allowed_tags`: |
| 88 | +
|
| 89 | + ```ruby |
| 90 | + ActionText::ContentHelper.allowed_tags = ["math", "style"] |
| 91 | + # or |
| 92 | + ActionText::ContentHelper.allowed_tags = ["svg", "style"] |
| 93 | + ``` |
| 94 | +
|
| 95 | + All users overriding the allowed tags by any of the above mechanisms |
| 96 | + to include (("math" or "svg") and "style") should either upgrade or |
| 97 | + use one of the workarounds. |
| 98 | +
|
| 99 | + ## Workarounds |
| 100 | +
|
| 101 | + Any one of the following actions will work around this issue: |
| 102 | +
|
| 103 | + - Remove "style" from the overridden allowed tags, |
| 104 | + - Or, remove "math" and "svg" from the overridden allowed tags, |
| 105 | + - Or, downgrade sanitization to HTML4 (see documentation for |
| 106 | + [`config.action_view.sanitizer_vendor`](https://guides.rubyonrails.org/configuring.html#config-action-view-sanitizer-vendor) |
| 107 | + and [`config.action_text.sanitizer_vendor`](https://guides.rubyonrails.org/configuring.html#config-action-text-sanitizer-vendor) |
| 108 | + for more information) |
| 109 | + - Or, independently upgrade Nokogiri to v1.15.7 or >= 1.16.8. |
| 110 | +
|
| 111 | + ## References |
| 112 | +
|
| 113 | + - [CWE - CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (4.9)](https://cwe.mitre.org/data/definitions/79.html) |
| 114 | + - Original report: https://hackerone.com/reports/2503220 |
| 115 | +
|
| 116 | + ## Credit |
| 117 | +
|
| 118 | + This vulnerability was responsibly reported by HackerOne user |
| 119 | + [@taise](https://hackerone.com/taise?type=user). |
| 120 | +cvss_v4: 2.3 |
| 121 | +unaffected_versions: |
| 122 | + - "< 1.6.0" |
| 123 | +patched_versions: |
| 124 | + - ">= 1.6.1" |
| 125 | +related: |
| 126 | + url: |
| 127 | + - https://nvd.nist.gov/vuln/detail/CVE-2024-53985 |
| 128 | + - https://github.com/rails/rails-html-sanitizer/blob/v1.6.1/CHANGELOG.md |
| 129 | + - https://github.com/rails/rails-html-sanitizer/security/advisories/GHSA-w8gc-x259-rc7x |
| 130 | + - https://github.com/rails/rails-html-sanitizer/commit/b0220b8850d52199a15f83c472d175a4122dd7b1 |
| 131 | + - https://github.com/rails/rails-html-sanitizer/commit/cd18b0ef00aad1d4a9e1c5d860cd23f80f63c505 |
| 132 | + - https://github.com/advisories/GHSA-w8gc-x259-rc7x |
0 commit comments