Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inform that symlinks are not allowed in safe mode #6670

Merged
merged 2 commits into from Jan 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/jekyll/tags/include.rb
Expand Up @@ -115,9 +115,7 @@ def locate_include_file(context, file, safe)
path = File.join(dir.to_s, file.to_s)
return path if valid_include_file?(path, dir.to_s, safe)
end
raise IOError, "Could not locate the included file '#{file}' in any of "\
"#{includes_dirs}. Ensure it exists in one of those directories and, "\
"if it is a symlink, does not point outside your site source."
raise IOError, could_not_locate_message(file, includes_dirs, safe)
end

def render(context)
Expand Down Expand Up @@ -192,6 +190,18 @@ def realpath_prefixed_with?(path, dir)
def read_file(file, context)
File.read(file, file_read_opts(context))
end

private

def could_not_locate_message(file, includes_dirs, safe)
message = "Could not locate the included file '#{file}' in any of "\
"#{includes_dirs}. Ensure it exists in one of those directories and"
message + if safe
" is not a symlink as those are not allowed in safe mode."
else
", if it is a symlink, does not point outside your site source."
end
end
end

class IncludeRelativeTag < IncludeTag
Expand Down
8 changes: 5 additions & 3 deletions test/test_tags.rb
Expand Up @@ -912,7 +912,9 @@ def highlight_block_with_opts(options_string)
end
assert_match(
"Could not locate the included file 'tmp/pages-test-does-not-exist' " \
"in any of [\"#{source_dir}/_includes\"].",
"in any of [\"#{source_dir}/_includes\"]. Ensure it exists in one of " \
"those directories and is not a symlink as those are not allowed in " \
"safe mode.",
ex.message
)
end
Expand Down Expand Up @@ -1271,8 +1273,8 @@ def highlight_block_with_opts(options_string)
})
end
assert_match(
"Ensure it exists in one of those directories and, if it is a symlink, does " \
"not point outside your site source.",
"Ensure it exists in one of those directories and is not a symlink "\
"as those are not allowed in safe mode.",
ex.message
)
end
Expand Down