I've gone off and overridden devise's devise_error_messages!
in the DeviseHelper
module to return a differently formatted response as suggested here: rails - Devise - Handling - devise_error_messages
However part of what I did was to include the results of alert
like so:
def devise_error_messages!
# if there aren't any errors, just return a blank string
return '' if (resource.errors.empty? && !alert)
# go through each of the messages and add a <br> onto the back of it
messages = resource.errors.full_messages.map { |msg| msg << "<br>" }.join
# if there are also alerts, add that to the end of messages
if alert
messages << alert
end
# add div around messages
messages = "<div class='errorbox'>" << messages << "</div>"
# return messages in an html safe format
messages.html_safe
end
This way I can have the devise_error_messages!
in any page that needs them, and it'll just return the right answer. (E.g. devise's Sign Up form returns it's errors through devise_error_message!
while the login form returns in through alert
).
What I want to know is if I can be guaranteed that the output of alert
won't lead to any Cross Site Scripting. I am assuming that the output of resource.errors.full_messages
is safe since the original devise_error_messages!
method returns messages.html_safe
and I'd trust that they wouldn't let it be at risk of any XSS.
However since alert
is suggested to be used in an erg output (e.g. <%= alert %>
) where any injected code would be escaped by default, is there any occasion, where code could be injected in, thus making use of .html_safe
potentially quite hazardous?
tl;dr - is it safe to use alert.html_safe
?
<%= notice %>
<%= alert %>
`" Not entirely sure where it comes from besides that, but it works. – SCB Feb 27 '14 at 08:41