Skip to content

Commit caddaeb

Browse files
parkrjekyllbot
authored andcommitted
3.6.x: security: fix include bypass of EntryFilter#filter symlink check (#7229)
Merge pull request 7229
1 parent 0b83d76 commit caddaeb

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

lib/jekyll/entry_filter.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ def relative_to_source(entry)
3131

3232
def filter(entries)
3333
entries.reject do |e|
34-
unless included?(e)
35-
special?(e) || backup?(e) || excluded?(e) || symlink?(e)
36-
end
34+
# Reject this entry if it is a symlink.
35+
next true if symlink?(e)
36+
# Do not reject this entry if it is included.
37+
next false if included?(e)
38+
# Reject this entry if it is special, a backup file, or excluded.
39+
special?(e) || backup?(e) || excluded?(e)
3740
end
3841
end
3942

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/passwd

test/test_entry_filter.rb

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class TestEntryFilter < JekyllUnitTest
66
context "Filtering entries" do
77
setup do
8-
@site = Site.new(site_configuration)
8+
@site = fixture_site
99
end
1010

1111
should "filter entries" do
@@ -87,7 +87,7 @@ class TestEntryFilter < JekyllUnitTest
8787
# no support for symlinks on Windows
8888
skip_if_windows "Jekyll does not currently support symlinks on Windows."
8989

90-
site = Site.new(site_configuration("safe" => true))
90+
site = fixture_site("safe" => true)
9191
site.reader.read_directories("symlink-test")
9292

9393
assert_equal %w(main.scss symlinked-file).length, site.pages.length
@@ -99,11 +99,22 @@ class TestEntryFilter < JekyllUnitTest
9999
# no support for symlinks on Windows
100100
skip_if_windows "Jekyll does not currently support symlinks on Windows."
101101

102-
site = Site.new(site_configuration)
102+
@site.reader.read_directories("symlink-test")
103+
refute_equal [], @site.pages
104+
refute_equal [], @site.static_files
105+
end
106+
107+
should "include only safe symlinks in safe mode even when included" do
108+
# no support for symlinks on Windows
109+
skip_if_windows "Jekyll does not currently support symlinks on Windows."
103110

111+
site = fixture_site("safe" => true, "include" => ["symlinked-file-outside-source"])
104112
site.reader.read_directories("symlink-test")
105-
refute_equal [], site.pages
106-
refute_equal [], site.static_files
113+
114+
# rubocop:disable Performance/FixedSize
115+
assert_equal %w(main.scss symlinked-file).length, site.pages.length
116+
refute_includes site.static_files.map(&:name), "symlinked-file-outside-source"
117+
# rubocop:enable Performance/FixedSize
107118
end
108119
end
109120

test/test_layout_reader.rb

+46
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,51 @@ class TestLayoutReader < JekyllUnitTest
3131
assert_equal LayoutReader.new(@site).layout_directory, source_dir("blah/_layouts")
3232
end
3333
end
34+
35+
context "when a layout is a symlink" do
36+
setup do
37+
FileUtils.ln_sf("/etc/passwd", source_dir("_layouts", "symlink.html"))
38+
@site = fixture_site(
39+
"safe" => true,
40+
"include" => ["symlink.html"]
41+
)
42+
end
43+
44+
teardown do
45+
FileUtils.rm(source_dir("_layouts", "symlink.html"))
46+
end
47+
48+
should "only read the layouts which are in the site" do
49+
skip_if_windows "Jekyll does not currently support symlinks on Windows."
50+
51+
layouts = LayoutReader.new(@site).read
52+
53+
refute layouts.key?("symlink"), "Should not read the symlinked layout"
54+
end
55+
end
56+
57+
context "with a theme" do
58+
setup do
59+
FileUtils.ln_sf("/etc/passwd", theme_dir("_layouts", "theme-symlink.html"))
60+
@site = fixture_site(
61+
"include" => ["theme-symlink.html"],
62+
"theme" => "test-theme",
63+
"safe" => true
64+
)
65+
end
66+
67+
teardown do
68+
FileUtils.rm(theme_dir("_layouts", "theme-symlink.html"))
69+
end
70+
71+
should "not read a symlink'd theme" do
72+
skip_if_windows "Jekyll does not currently support symlinks on Windows."
73+
74+
layouts = LayoutReader.new(@site).read
75+
76+
refute layouts.key?("theme-symlink"), \
77+
"Should not read symlinked layout from theme"
78+
end
79+
end
3480
end
3581
end

0 commit comments

Comments
 (0)