mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 16:48:03 +08:00
FEATURE: whitelist theme repo mode (experimental)
In some restricted setups all JS payloads need tight control. This setting bans admins from making changes to JS on the site and requires all themes be whitelisted to be used. There are edge cases we still need to work through in this mode hence this is still not supported in production and experimental. Use an example like this to enable: `DISCOURSE_WHITELISTED_THEME_REPOS="https://repo.com/repo.git,https://repo.com/repo2.git"` By default this feature is not enabled and no changes are made. One exception is that default theme id was missing a security check this was added for correctness.
This commit is contained in:
@ -471,9 +471,27 @@ class Guardian
|
||||
@user.staff? || @user.trust_level >= TrustLevel.levels[:member]
|
||||
end
|
||||
|
||||
def allowed_theme_repo_import?(repo)
|
||||
return false if !@user.admin?
|
||||
|
||||
whitelisted_repos = GlobalSetting.whitelisted_theme_repos
|
||||
if !whitelisted_repos.blank?
|
||||
urls = whitelisted_repos.split(",").map(&:strip)
|
||||
return urls.include?(repo)
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def allow_themes?(theme_ids, include_preview: false)
|
||||
return true if theme_ids.blank?
|
||||
|
||||
if whitelisted_theme_ids = GlobalSetting.whitelisted_theme_ids
|
||||
if (theme_ids - whitelisted_theme_ids).present?
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if include_preview && is_staff? && (theme_ids - Theme.theme_ids).blank?
|
||||
return true
|
||||
end
|
||||
|
Reference in New Issue
Block a user