Skip to content

Conversation

@mikej
Copy link
Contributor

@mikej mikej commented Jan 21, 2026

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.

mikej added 3 commits January 21, 2026 14:43
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
@mikej mikej force-pushed the prevent-potential-xss-in-flash-messages branch from fa2ba7e to 81c7982 Compare January 21, 2026 15:15
- 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
Copy link
Collaborator

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

Suggested change
= 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
= content_tag :span, message
%span= message

Copy link
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

@olleolleolle olleolleolle merged commit 46ed308 into codebar:master Jan 22, 2026
2 checks passed
mikej added a commit to mikej/codebar-planner that referenced this pull request Jan 22, 2026
small improvement to the partial used for flash messages that was
suggested in the review comments for codebar#2442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants