-
-
Notifications
You must be signed in to change notification settings - Fork 198
Avoid potential XSS vulnerability in flash messages #2442
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
Avoid potential XSS vulnerability in flash messages #2442
Conversation
flash messages were being assumed to be HTML-safe which feels too fragile as it relies on every developer remembering to escape any user input that's included in flash messages. fix by removing the `.html_safe` from the messages partial. the only place that seems to be relying on this behaviour is in `MeetingsController` where validation errors are joined into a single flash message using <br> tags. Updated this to just join the messages with commas instead.
venue gets validation as part of its belongs_to association which is required by default. this resulted in 2 validation error messages being shown: "Venue must be set" and "Venue can't be blank". remove the presence validator so we now get just "Venue must be set"
update meeting specs to reflect removal of duplicate validation in cbd78da
fa2ba7e to
81c7982
Compare
| - if msg.is_a?(String) | ||
| .alert.alert-dismissible.fade.show.mb-0{ 'data-alert': '', class: "alert-#{name}", role: 'alert' } | ||
| = content_tag :div, msg.html_safe | ||
| = content_tag :div, msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, here we can simplify the markup, something like
| = content_tag :div, msg | |
| %div= msg |
| - msg.each do |message| | ||
| .alert.alert-dismissible.fade.show.mb-0{ 'data-alert': '', class: "alert-#{name}", role: 'alert' } | ||
| = content_tag :span, message.html_safe | ||
| = content_tag :span, message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| = content_tag :span, message | |
| %span= message |
olleolleolle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done!
small improvement to the partial used for flash messages that was suggested in the review comments for codebar#2442
Flash messages were being assumed to be HTML-safe which feels too fragile as it relies on every developer remembering to escape any user input that's included in flash messages.
Fix by removing the
.html_safefrom the messages partial.The only place that seems to be relying on this behaviour is in
MeetingsControllerwhere validation errors are joined into a single flash message using<br>tags. Updated this to just join the messages with commas instead.