Fix stored XSS vulnerabilities in HTML helper methods and views#2567
Draft
Copilot wants to merge 7 commits into
Draft
Fix stored XSS vulnerabilities in HTML helper methods and views#2567Copilot wants to merge 7 commits into
Copilot wants to merge 7 commits into
Conversation
… and views Agent-Logs-Url: https://github.com/seek4science/seek/sessions/a0db5e17-9a4c-4ea4-b006-fc781a2ff034 Co-authored-by: whomingbird <42063448+whomingbird@users.noreply.github.com>
…e html_safe? bypass in folding_panel Agent-Logs-Url: https://github.com/seek4science/seek/sessions/a0db5e17-9a4c-4ea4-b006-fc781a2ff034 Co-authored-by: whomingbird <42063448+whomingbird@users.noreply.github.com>
…ape error messages Agent-Logs-Url: https://github.com/seek4science/seek/sessions/a0db5e17-9a4c-4ea4-b006-fc781a2ff034 Co-authored-by: whomingbird <42063448+whomingbird@users.noreply.github.com>
Agent-Logs-Url: https://github.com/seek4science/seek/sessions/a0db5e17-9a4c-4ea4-b006-fc781a2ff034 Co-authored-by: whomingbird <42063448+whomingbird@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
whomingbird
May 6, 2026 13:47
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens several Rails helpers and ERB views against stored XSS by ensuring user-/project-member-controlled strings (attribute labels/titles/descriptions and validation messages) are escaped before being inserted into HTML.
Changes:
- Updated
folding_panel/panel_titleto avoid unsafe string concatenation patterns and ensure non-safe input is escaped. - Escaped extended metadata labels/descriptions via
h(...)andcontent_tag(...)instead of raw concatenation. - Removed unsafe
.html_safeusage from validation error rendering and escaped popover content in the samples table.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/helpers/bootstrap_helper.rb | Escapes panel titles and uses SafeBuffer concatenation to prevent title-based XSS. |
| app/helpers/extended_metadata_helper.rb | Uses escaping/content_tag for linked metadata labels and descriptions. |
| app/helpers/samples_helper.rb | Escapes attribute titles/labels and avoids unsafe HTML building in sample attribute display. |
| app/views/spreadsheets/_spreadsheet_errors.html.erb | Stops rendering error.full_message as raw HTML. |
| app/views/samples/_sample_error_messages.html.erb | Stops rendering error.full_message as raw HTML. |
| app/views/samples/_table_view.html.erb | Escapes attribute titles and per-field error text used in popovers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+32
to
33
| title = h(title) unless title.nil? | ||
| title += " <span class=\"#{collapsed ? 'caret' : 'caret-up'}\"></span>".html_safe |
Comment on lines
106
to
+114
| def sample_attribute_display_title(attribute) | ||
| title = attribute.title | ||
| title = h(attribute.title) | ||
| if (unit = attribute.unit) && !unit.dimensionless? | ||
| title += " ( #{unit} )" | ||
| title << ' ( ' << h(unit) << ' )' | ||
| end | ||
| unless attribute.pid.blank? | ||
| title += content_tag(:small, 'data-tooltip'=>attribute.pid) do | ||
| " [ "+attribute.short_pid+ " ]" | ||
| end.html_safe | ||
| title << content_tag(:small, " [ #{attribute.short_pid} ]", 'data-tooltip' => attribute.pid) | ||
| end | ||
| title.html_safe | ||
| title |
…ute_display_title to verify script tags and image tags with event handlers are escaped
…itles for folding_panel in sample panels so counter <span> elements render correctly while the helper escapes any malicious HTML
-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several helpers and views were constructing HTML via unsafe string concatenation — marking admin/project-member-controlled content (attribute labels, titles, descriptions, error messages) as
html_safewithout escaping, enabling stored XSS.Changes
app/helpers/bootstrap_helper.rbfolding_panel: callh(title)before appending the caret<span>—h()is a no-op for already-safe strings, escapes plain stringspanel_title: inittitle_htmlas''.html_safe(SafeBuffer) so<<auto-escapes any non-safe input; remove terminal.html_safecall on plain Stringapp/helpers/extended_metadata_helper.rbextended_metadata_attribute_description: replace raw string concat withcontent_tagsodescriptionis escapedextended_metadata_form_field_for_attribute/render_extended_metadata_value: wrapattribute.labelinh()before passing tofolding_panelapp/helpers/samples_helper.rbsample_attribute_display_title: escapeattribute.titlewithh(), use SafeBuffer<<for unit appending, usecontent_tagfor the pid<small>spanlinked_extended_metadata_form_field: escapeattr.labelwithh()in HTML stringlinked_extended_metadata_attribute_display: escapeattr.titlewithh(); passh(attr.label)tofolding_panelViews
_sample_error_messages.html.erb/_spreadsheet_errors.html.erb: remove.html_safefromerror.full_message— attribute names derived from sample type definitions (project-member-controlled) were rendered unescaped_table_view.html.erb: escape bothattribute.titleand error messageewithh()in popover content stringExample
Before:
After: