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

A gem-based plugin whitelist for safe mode #1657

Merged
merged 12 commits into from Dec 8, 2013
1 change: 1 addition & 0 deletions bin/jekyll
Expand Up @@ -41,6 +41,7 @@ def add_build_options(c)
c.option '--lsi', 'Use LSI for improved related posts'
c.option '-D', '--drafts', 'Render posts in the _drafts folder'
c.option '-V', '--verbose', 'Print verbose output.'
c.option '-W', '--whitelist', 'Gem plugin whitelist'
end

command :default do |c|
Expand Down
21 changes: 18 additions & 3 deletions lib/jekyll/site.rb
Expand Up @@ -77,11 +77,10 @@ def setup
require f
end
end
self.gems.each do |gem|
require gem
end
end

require_gems

self.converters = instantiate_subclasses(Jekyll::Converter)
self.generators = instantiate_subclasses(Jekyll::Generator)
end
Expand All @@ -97,6 +96,22 @@ def ensure_not_in_dest
end
end

def require_gems
self.gems.each do |gem|
if whitelist.include?(gem) || !self.safe
Copy link
Member Author

Choose a reason for hiding this comment

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

if the site is safe, then just iterate over whitelist & gems (the intersection of the two arrays), otherwise just iterate over gems. Might be wise to make a Site#allowed_gems array that handles the aforementioned condition.

require gem
end
end
end

def whitelist
@whitelist ||= begin
YAML.safe_load_file(self.config['whitelist']) || []
rescue
[]
end
end

# Internal: Setup the plugin search path
#
# Returns an Array of plugin search paths
Expand Down