Skip to content

Commit

Permalink
Swap sanitize for raw when used in Govspeak
Browse files Browse the repository at this point in the history
The `sanitize` method is stripping out too much and breaking things - swapping
it for `raw` (which stringifies and uses the `html_safe` method) fixes this.
This will need a more secure fix in the future.
  • Loading branch information
injms committed Nov 2, 2020
1 parent f663362 commit 227bdea
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/views/content_items/_document_collection_body.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(group["body"]) %>
<%= raw(group["body"]) %>
<% end %>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/case_study.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
</div>

Expand Down
8 changes: 4 additions & 4 deletions app/views/content_items/consultation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.final_outcome_detail) %>
<%= raw(@content_item.final_outcome_detail) %>
<% end %>
</div>
<% end %>
Expand All @@ -72,7 +72,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.public_feedback_detail) %>
<%= raw(@content_item.public_feedback_detail) %>
<% end %>
</div>
<% end %>
Expand Down Expand Up @@ -132,7 +132,7 @@
} %>

<%= render 'govuk_publishing_components/components/govspeak', {} do %>
<%= sanitize(@content_item.govspeak_body[:content]) %>
<%= raw(@content_item.govspeak_body[:content]) %>
<% end %>

<%= render "attachments",
Expand Down Expand Up @@ -180,7 +180,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@ways_to_respond_body) %>
<%= raw(@ways_to_respond_body) %>
<% end %>
</div>
<% end %>
Expand Down
5 changes: 2 additions & 3 deletions app/views/content_items/corporate_information_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@
<%= render "components/contents-list-with-body", contents: @content_item.contents do %>
<div class="responsive-bottom-margin">
<%= render 'govuk_publishing_components/components/govspeak', {} do %>
<%= sanitize("#{@content_item.body}#{@additional_body}", {
attributes: %w(id href),
}) %>
<%= raw(@content_item.body) %>
<%= raw(@additional_body) %>
<% end %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/detailed_guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
} %>

<%= render 'govuk_publishing_components/components/govspeak', {} do %>
<%= sanitize(@content_item.govspeak_body[:content]) %>
<%= raw(@content_item.govspeak_body[:content]) %>
<% end %>

<div class="responsive-bottom-margin">
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/fatality_notice.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/gone.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>

<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= sanitize(@content_item.explanation) %>
<%= raw(@content_item.explanation) %>
<% end %>

<% if @content_item.alternative_path.present? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
direction: page_text_direction,
disable_youtube_expansions: true
} do %>
<%= sanitize(@content_item.current_part_body) %>
<%= raw(@content_item.current_part_body) %>
<% end %>

<% if @content_item.show_guide_navigation? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/html_publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

<div class="main-content-container<% unless @content_item.contents.any? %> offset-empty-contents-list<% end %>">
<%= render "govuk_publishing_components/components/govspeak_html_publication", {} do %>
<%= sanitize(@content_item.govspeak_body[:content]) %>
<%= raw(@content_item.govspeak_body[:content]) %>
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/news_article.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<%= render "govuk_publishing_components/components/govspeak", {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<%= render "govuk_publishing_components/components/govspeak", {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.details) %>
<%= raw(@content_item.details) %>
<% end %>
</section>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/govspeak', {} do %>
<%= sanitize(@content_item.description) %>
<%= raw(@content_item.description) %>
<% end %>
<% if @error %>
<%= render "components/error-message", text: t('service_sign_in.error.option') %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/specialist_document.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<div class="responsive-bottom-margin">
<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= sanitize(@content_item.govspeak_body[:content]) %>
<%= raw(@content_item.govspeak_body[:content]) %>
<% end %>

<% if @content_item.continuation_link %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/speech.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%= render "govuk_publishing_components/components/govspeak", {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/take_part.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= render "govuk_publishing_components/components/govspeak", {
direction: page_text_direction
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
</div>
<%= render 'shared/sidebar_navigation' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/topical_event_about_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<%= render "govuk_publishing_components/components/govspeak", {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/travel_advice.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.current_part_body) %>
<%= raw(@content_item.current_part_body) %>
<% end %>

<%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/unpublishing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</p>

<%= render "govuk_publishing_components/components/govspeak", {} do %>
<%= sanitize(@content_item.explanation) %>
<%= raw(@content_item.explanation) %>
<% end %>

<% if @content_item.alternative_url.present? %>
Expand Down
8 changes: 2 additions & 6 deletions app/views/content_items/working_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body, {
attributes: %w(id class href),
}) %>
<%= sanitize(@additional_body, {
attributes: %w(id class href),
}) %>
<%= raw(@content_item.body) %>
<%= raw(@additional_body) %>
<% end %>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<%= sanitize(@content_item.body) %>
<%= raw(@content_item.body) %>
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_travel_advice_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
direction: page_text_direction,
} do %>
<div class="help-notice">
<%= sanitize(content_item.alert_status) %>
<%= raw(content_item.alert_status) %>
</div>
<% end %>
<% end %>
Expand Down

0 comments on commit 227bdea

Please sign in to comment.