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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check symlink outside site_source without Pathutil #9015

Merged
merged 1 commit into from
Apr 3, 2022
Merged
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
8 changes: 2 additions & 6 deletions lib/jekyll/entry_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@ def symlink?(entry)
end

# --
# NOTE: Pathutil#in_path? gets the realpath.
# @param [<Anything>] entry the entry you want to validate.
# Check if a path is outside of our given root.
# Check if given path is outside of current site's configured source directory.
# --
def symlink_outside_site_source?(entry)
!Pathutil.new(entry).in_path?(
site.in_source_dir
)
!File.realpath(entry).start_with?(site.in_source_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative here might be to check if a constructed path and the real path are not equal?

site.in_source_dir(entry) != File.realpath(entry)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downside to this is that it results in consumption of additional resources.
site.in_source_dir(entry) is more expensive (both in terms of allocations and cpu) than site.in_source_dir.

A better alternative to my original proposal here would be to check directly against site.source instead:

Suggested change
!File.realpath(entry).start_with?(site.in_source_dir)
!File.realpath(entry).start_with?(site.source)

But since EntryFilter#symlink_outside_site_source? method is mostly invoked only if site.safe && File.symlink?(entry) returns true, the difference between site.source and site.in_source_dir is negligible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. :shipit:

end

# Check if an entry matches a specific pattern.
Expand Down