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

strengthen checks on plugin directories. #4020

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions apps/dashboard/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,27 @@ class Application < Rails::Application
if plugins_dir.directory?
plugins_dir.children.select(&:directory?).each do |installed_plugin|
next unless installed_plugin.readable?
# Ignore plugins not installed by admins - plugin directory should be owned by root
next if ::Configuration.rails_env_production? && !File.stat(installed_plugin.to_s).uid.zero?

config.paths["config/initializers"] << installed_plugin.join("initializers").to_s
config.autoload_paths << installed_plugin.join("lib").to_s
config.paths["app/views"].unshift installed_plugin.join("views").to_s
initers = installed_plugin.join('initializers')
lib = installed_plugin.join('lib')
views = installed_plugin.join('views')

production = ::Configuration.rails_env_production?

# only load paths in production if every single file in the directory is root owned.
safe_load_initers = production ? safe_load_path?(initers) : true
safe_load_lib = production ? safe_load_path?(lib) : true
safe_load_views = production ? safe_load_path?(views) : true

config.paths['config/initializers'] << initers.to_s if safe_load_initers
config.autoload_paths << lib.to_s if safe_load_lib
config.paths["app/views"].unshift(views.to_s) if safe_load_views
end
end

# Determine if this path is safe to load. I.e., are all the files root owned.
def safe_load_path?(path)
path.children.all? { |f| File.stat(f).uid.zero? }
end
end
end
Loading