diff --git a/History.txt b/History.txt index 37bc9aae..947f56c8 100644 --- a/History.txt +++ b/History.txt @@ -6,6 +6,7 @@ * Added new date filter that shows the full month name [github.com/mreid] * Make post's YAML front matter available as post.data [github.com/remi] * Merge Post's YAML front matter into its to_liquid payload [github.com/remi] + * Restrict includes to regular files underneath _includes * Bug Fixes * Change YAML delimiter matcher so as to not chew up 2nd level markdown headers [github.com/mreid] * Fix bug that meant page data (such as the date) was not available in templates [github.com/mreid] diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index f03ed177..f2494243 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -7,7 +7,18 @@ module Jekyll end def render(context) - File.read(File.join(Jekyll.source, '_includes', @file)) + if @file !~ /^[a-zA-Z0-9_\/\.-]+$/ || @file =~ /\.\// || @file =~ /\/\./ + return "Include file '#{@file}' contains invalid characters or sequences" + end + + Dir.chdir(File.join(Jekyll.source, '_includes')) do + choices = Dir['**/*'].reject { |x| File.symlink?(x) } + if choices.include?(@file) + File.read(@file) + else + "Included file '#{@file}' not found in _includes directory" + end + end end end