mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: during concurrent emails generation renderer should not be reused
Our instance used for template rendering needs a lock to ensure there is no race condition where rendering happens on 2 threads at the same time. This can lead to local poisoning which can cause unexpected results in emails
This commit is contained in:
@@ -589,7 +589,7 @@ class UserNotifications < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless translation_override_exists
|
unless translation_override_exists
|
||||||
html = UserNotificationRenderer.instance.render(
|
html = UserNotificationRenderer.render(
|
||||||
template: 'email/notification',
|
template: 'email/notification',
|
||||||
format: :html,
|
format: :html,
|
||||||
locals: { context_posts: context_posts,
|
locals: { context_posts: context_posts,
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ class UserNotificationRenderer < ActionView::Base
|
|||||||
include UserNotificationsHelper
|
include UserNotificationsHelper
|
||||||
include EmailHelper
|
include EmailHelper
|
||||||
|
|
||||||
def self.instance
|
LOCK = Mutex.new
|
||||||
|
|
||||||
|
def self.render(*args)
|
||||||
|
LOCK.synchronize do
|
||||||
@instance ||= UserNotificationRenderer.with_view_paths(
|
@instance ||= UserNotificationRenderer.with_view_paths(
|
||||||
Rails.configuration.paths["app/views"]
|
Rails.configuration.paths["app/views"]
|
||||||
)
|
)
|
||||||
|
@instance.render(*args)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ module Email
|
|||||||
html_override.gsub!("%{respond_instructions}", "")
|
html_override.gsub!("%{respond_instructions}", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
html = UserNotificationRenderer.instance.render(
|
html = UserNotificationRenderer.render(
|
||||||
template: 'layouts/email_template',
|
template: 'layouts/email_template',
|
||||||
format: :html,
|
format: :html,
|
||||||
locals: { html_body: html_override.html_safe }
|
locals: { html_body: html_override.html_safe }
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module Email
|
|||||||
style = if @message.html_part
|
style = if @message.html_part
|
||||||
Email::Styles.new(@message.html_part.body.to_s, @opts)
|
Email::Styles.new(@message.html_part.body.to_s, @opts)
|
||||||
else
|
else
|
||||||
unstyled = UserNotificationRenderer.instance.render(
|
unstyled = UserNotificationRenderer.render(
|
||||||
template: 'layouts/email_template',
|
template: 'layouts/email_template',
|
||||||
format: :html,
|
format: :html,
|
||||||
locals: { html_body: PrettyText.cook(text).html_safe }
|
locals: { html_body: PrettyText.cook(text).html_safe }
|
||||||
|
|||||||
Reference in New Issue
Block a user