|
| 1 | +--- |
| 2 | +gem: actionview |
| 3 | +framework: rails |
| 4 | +cve: 2019-5418 |
| 5 | +date: 2019-03-13 |
| 6 | +url: https://groups.google.com/forum/#!topic/rubyonrails-security/pFRKI96Sm8Q |
| 7 | + |
| 8 | +title: File Content Disclosure in Action View |
| 9 | + |
| 10 | +description: | |
| 11 | + There is a possible file content disclosure vulnerability in Action View. This |
| 12 | + vulnerability has been assigned the CVE identifier CVE-2019-5418. |
| 13 | +
|
| 14 | + Versions Affected: All. |
| 15 | + Not affected: None. |
| 16 | + Fixed Versions: 6.0.0.beta3, 5.2.2.1, 5.1.6.2, 5.0.7.2, 4.2.11.1 |
| 17 | +
|
| 18 | + Impact |
| 19 | + ------ |
| 20 | + There is a possible file content disclosure vulnerability in Action View. |
| 21 | + Specially crafted accept headers in combination with calls to `render file:` |
| 22 | + can cause arbitrary files on the target server to be rendered, disclosing the |
| 23 | + file contents. |
| 24 | +
|
| 25 | + The impact is limited to calls to `render` which render file contents without |
| 26 | + a specified accept format. Impacted code in a controller looks something like |
| 27 | + this: |
| 28 | +
|
| 29 | + ``` |
| 30 | + class UserController < ApplicationController |
| 31 | + def index |
| 32 | + render file: "#{Rails.root}/some/file" |
| 33 | + end |
| 34 | + end |
| 35 | + ``` |
| 36 | +
|
| 37 | + Rendering templates as opposed to files is not impacted by this vulnerability. |
| 38 | +
|
| 39 | + All users running an affected release should either upgrade or use one of the |
| 40 | + workarounds immediately. |
| 41 | +
|
| 42 | + Releases |
| 43 | + -------- |
| 44 | + The 6.0.0.beta3, 5.2.2.1, 5.1.6.2, 5.0.7.2, and 4.2.11.1 releases are |
| 45 | + available at the normal locations. |
| 46 | +
|
| 47 | + Workarounds |
| 48 | + ----------- |
| 49 | + This vulnerability can be mitigated by specifying a format for file rendering, |
| 50 | + like this: |
| 51 | +
|
| 52 | + ``` |
| 53 | + class UserController < ApplicationController |
| 54 | + def index |
| 55 | + render file: "#{Rails.root}/some/file", formats: [:html] |
| 56 | + end |
| 57 | + end |
| 58 | + ``` |
| 59 | +
|
| 60 | + In summary, impacted calls to `render` look like this: |
| 61 | +
|
| 62 | + ``` |
| 63 | + render file: "#{Rails.root}/some/file" |
| 64 | + ``` |
| 65 | +
|
| 66 | + The vulnerability can be mitigated by changing to this: |
| 67 | +
|
| 68 | + ``` |
| 69 | + render file: "#{Rails.root}/some/file", formats: [:html] |
| 70 | + ``` |
| 71 | +
|
| 72 | + Other calls to `render` are not impacted. |
| 73 | +
|
| 74 | + Alternatively, the following monkey patch can be applied in an initializer: |
| 75 | +
|
| 76 | + ``` |
| 77 | + $ cat config/initializers/formats_filter.rb |
| 78 | + # frozen_string_literal: true |
| 79 | +
|
| 80 | + ActionDispatch::Request.prepend(Module.new do |
| 81 | + def formats |
| 82 | + super().select do |format| |
| 83 | + format.symbol || format.ref == "*/*" |
| 84 | + end |
| 85 | + end |
| 86 | + end) |
| 87 | + ``` |
| 88 | +
|
| 89 | + Credits |
| 90 | + ------- |
| 91 | + Thanks to John Hawthorn <john@hawthorn.email> of GitHub |
| 92 | +
|
| 93 | +patched_versions: |
| 94 | + - "~> 4.2.11.1" |
| 95 | + - "~> 5.0.7.2" |
| 96 | + - "~> 5.1.6.1" |
| 97 | + - "~> 5.2.2.1" |
| 98 | + - "~> 6.0.0.beta3" |
0 commit comments