Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
allow :file to be outside rails root, but anything else must be insid…
…e the rails view directory Conflicts: actionpack/test/controller/render_test.rb actionview/lib/action_view/template/resolver.rb CVE-2016-0752
- Loading branch information
1 parent
cdabc95
commit 18269d2
Showing
4 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,9 @@ def initialize(pattern=nil) | |
| super() | ||
| end | ||
|
|
||
| cattr_accessor :allow_external_files, instance_reader: false, instance_writer: false | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cntrytwist
|
||
| self.allow_external_files = false | ||
|
|
||
| private | ||
|
|
||
| def find_templates(name, prefix, partial, details) | ||
|
|
@@ -122,6 +125,10 @@ def query(path, details, formats) | |
|
|
||
| template_paths = find_template_paths query | ||
|
|
||
| unless self.class.allow_external_files | ||
| template_paths = reject_files_external_to_app(template_paths) | ||
| end | ||
|
|
||
| template_paths.map { |template| | ||
| handler, format = extract_handler_and_format(template, formats) | ||
| contents = File.binread template | ||
|
|
@@ -133,6 +140,10 @@ def query(path, details, formats) | |
| } | ||
| end | ||
|
|
||
| def reject_files_external_to_app(files) | ||
| files.reject { |filename| !inside_path?(@path, filename) } | ||
| end | ||
|
|
||
| if RUBY_VERSION >= '2.2.0' | ||
| def find_template_paths(query) | ||
| Dir[query].reject { |filename| | ||
|
|
@@ -153,6 +164,12 @@ def find_template_paths(query) | |
| end | ||
| end | ||
|
|
||
| def inside_path?(path, filename) | ||
| filename = File.expand_path(filename) | ||
| path = File.join(path, '') | ||
| filename.start_with?(path) | ||
| end | ||
|
|
||
| # Helper for building query glob string based on resolver's pattern. | ||
| def build_query(path, details) | ||
| query = @pattern.dup | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This kills Ruby 1.8.7 compatibility. :( Is PR welcomed?