diff --git a/.erb-lint.yml b/.erb-lint.yml index 5f48c3355..e87a778f8 100644 --- a/.erb-lint.yml +++ b/.erb-lint.yml @@ -1,5 +1,7 @@ --- linters: + ErbSafety: + enabled: true ExtraNewline: enabled: true FinalNewline: diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml index a348f705b..ba3b32daa 100644 --- a/.rubocop_basic.yml +++ b/.rubocop_basic.yml @@ -160,6 +160,12 @@ Rails/Date: Rails/HttpPositionalArguments: Enabled: true +Rails/OutputSafety: + Enabled: true + Severity: warning + Exclude: + - app/helpers/text_with_links_helper.rb + Rails/PluralizationGrammar: Enabled: true diff --git a/Gemfile.lock b/Gemfile.lock index f86ab3ced..788ea82b6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -313,7 +313,7 @@ GEM actionmailer (>= 3.2) letter_opener (~> 1.0) railties (>= 3.2) - loofah (2.3.0) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 21a4564ff..26f266f90 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -10,7 +10,7 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def create if @draft_version.save - link = legislation_process_draft_version_path(@process, @draft_version).html_safe + link = legislation_process_draft_version_path(@process, @draft_version) notice = t("admin.legislation.draft_versions.create.notice", link: link) redirect_to admin_legislation_process_draft_versions_path, notice: notice else @@ -21,7 +21,7 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def update if @draft_version.update(draft_version_params) - link = legislation_process_draft_version_path(@process, @draft_version).html_safe + link = legislation_process_draft_version_path(@process, @draft_version) notice = t("admin.legislation.draft_versions.update.notice", link: link) edit_path = edit_admin_legislation_process_draft_version_path(@process, @draft_version) redirect_to edit_path, notice: notice diff --git a/app/controllers/admin/legislation/homepages_controller.rb b/app/controllers/admin/legislation/homepages_controller.rb index 6cc2062a8..0a7f04452 100644 --- a/app/controllers/admin/legislation/homepages_controller.rb +++ b/app/controllers/admin/legislation/homepages_controller.rb @@ -8,7 +8,7 @@ class Admin::Legislation::HomepagesController < Admin::Legislation::BaseControll def update if @process.update(process_params) - link = legislation_process_path(@process).html_safe + link = legislation_process_path(@process) redirect_back(fallback_location: (request.referer || root_path), notice: t("admin.legislation.processes.update.notice", link: link)) else diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index d9833e713..679fb3897 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -23,7 +23,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def create if @process.save - link = legislation_process_path(@process).html_safe + link = legislation_process_path(@process) notice = t("admin.legislation.processes.create.notice", link: link) redirect_to edit_admin_legislation_process_path(@process), notice: notice else @@ -36,7 +36,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll if @process.update(process_params) set_tag_list - link = legislation_process_path(@process).html_safe + link = legislation_process_path(@process) redirect_back(fallback_location: (request.referer || root_path), notice: t("admin.legislation.processes.update.notice", link: link)) else diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index e5bcb57ae..43a17f967 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -41,7 +41,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll private def question_path - legislation_process_question_path(@process, @question).html_safe + legislation_process_question_path(@process, @question) end def question_params diff --git a/app/controllers/direct_uploads_controller.rb b/app/controllers/direct_uploads_controller.rb index d1d52eb4c..425c43200 100644 --- a/app/controllers/direct_uploads_controller.rb +++ b/app/controllers/direct_uploads_controller.rb @@ -17,7 +17,7 @@ class DirectUploadsController < ApplicationController render json: { cached_attachment: @direct_upload.relation.cached_attachment, filename: @direct_upload.relation.attachment.original_filename, - destroy_link: render_destroy_upload_link(@direct_upload).html_safe, + destroy_link: render_destroy_upload_link(@direct_upload), attachment_url: @direct_upload.relation.attachment.url } else @direct_upload.destroy_attachment diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 40dd1073b..1033d0420 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,7 +32,8 @@ module ApplicationHelper strikethrough: true, superscript: true } - Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe + + sanitize(Redcarpet::Markdown.new(renderer, extensions).render(text)) end def author_of?(authorable, user) diff --git a/app/helpers/budget_investments_helper.rb b/app/helpers/budget_investments_helper.rb index bcfdf0f49..1e6d8405e 100644 --- a/app/helpers/budget_investments_helper.rb +++ b/app/helpers/budget_investments_helper.rb @@ -10,7 +10,7 @@ module BudgetInvestmentsHelper translation = t("admin.budget_investments.index.list.#{column}") link_to( - "#{translation} ".html_safe, + safe_join([translation, content_tag(:span, "", class: "icon-sortable #{icon}")]), admin_budget_budget_investments_path(sort_by: column, direction: direction) ) end diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index da1588398..1386796bb 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -50,10 +50,11 @@ module DocumentsHelper end def document_item_link(document) - link_to "#{document.title} (#{document.humanized_content_type} | \ - #{number_to_human_size(document.attachment_file_size)})".html_safe, - document.attachment.url, - target: "_blank", - title: t("shared.target_blank_html") + info_text = "#{document.humanized_content_type} | #{number_to_human_size(document.attachment_file_size)}" + + link_to safe_join([document.title, content_tag(:small, "(#{info_text})")], " "), + document.attachment.url, + target: "_blank", + title: t("shared.target_blank") end end diff --git a/app/helpers/proposals_dashboard_helper.rb b/app/helpers/proposals_dashboard_helper.rb index 16efad83a..4416c9fd8 100644 --- a/app/helpers/proposals_dashboard_helper.rb +++ b/app/helpers/proposals_dashboard_helper.rb @@ -65,7 +65,7 @@ module ProposalsDashboardHelper supports: number_with_delimiter(resource.required_supports, delimiter: ".")) if resource.required_supports > 0 - label.join(" #{t("dashboard.resource.and")}
") + safe_join label, h(" #{t("dashboard.resource.and")})") + tag(:br) end def daily_selected_class @@ -97,7 +97,7 @@ module ProposalsDashboardHelper end def proposed_action_description(proposed_action) - raw proposed_action.description.truncate(200) + sanitize proposed_action.description.truncate(200) end def proposed_action_long_description?(proposed_action) diff --git a/app/helpers/signature_sheets_helper.rb b/app/helpers/signature_sheets_helper.rb index d40689837..20ef2e709 100644 --- a/app/helpers/signature_sheets_helper.rb +++ b/app/helpers/signature_sheets_helper.rb @@ -24,10 +24,10 @@ module SignatureSheetsHelper text_help += t("admin.signature_sheets.new.text_help.postal_code_note") end - text_help += "
" + text_help += tag(:br) text_help += t("admin.signature_sheets.new.text_help.required_fields_structure_note") - return text_help.html_safe + return text_help end def example_text_help diff --git a/app/helpers/text_with_links_helper.rb b/app/helpers/text_with_links_helper.rb index b59c6ae7f..f01376847 100644 --- a/app/helpers/text_with_links_helper.rb +++ b/app/helpers/text_with_links_helper.rb @@ -1,16 +1,16 @@ module TextWithLinksHelper - def text_with_links(text) + def sanitize_and_auto_link(text) return unless text sanitized = sanitize(text, tags: [], attributes: []) - Rinku.auto_link(sanitized, :all, 'target="_blank" rel="nofollow"').html_safe + auto_link_already_sanitized_html(sanitized) end - def safe_html_with_links(html) + def auto_link_already_sanitized_html(html) return if html.nil? - html = ActiveSupport::SafeBuffer.new(html) if html.is_a?(String) - return html.html_safe unless html.html_safe? - Rinku.auto_link(html, :all, 'target="_blank" rel="nofollow"').html_safe + raise "Could not add links because the content is not safe" unless html.html_safe? + + raw Rinku.auto_link(html, :all, 'target="_blank" rel="nofollow"') end def simple_format_no_tags_no_sanitize(html) diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 92eff3d33..78ce9566d 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -26,9 +26,9 @@ module TranslatableFormHelper visible_locales.map do |locale| @translations[locale] = translation_for(locale) end - visible_locales.map do |locale| + safe_join(visible_locales.map do |locale| Globalize.with_locale(locale) { fields_for_locale(locale, &block) } - end.join.html_safe + end) end private diff --git a/app/helpers/valuation_helper.rb b/app/helpers/valuation_helper.rb index 8767ebb96..428d7fb14 100644 --- a/app/helpers/valuation_helper.rb +++ b/app/helpers/valuation_helper.rb @@ -14,7 +14,7 @@ module ValuationHelper end def explanation_field(field) - simple_format_no_tags_no_sanitize(safe_html_with_links(field.html_safe)) if field.present? + simple_format_no_tags_no_sanitize(sanitize_and_auto_link(field)) if field.present? end end diff --git a/app/views/admin/budget_investments/_select_investment.html.erb b/app/views/admin/budget_investments/_select_investment.html.erb index 793e05c7c..b293894b2 100644 --- a/app/views/admin/budget_investments/_select_investment.html.erb +++ b/app/views/admin/budget_investments/_select_investment.html.erb @@ -31,7 +31,7 @@ <% valuators = [investment.assigned_valuation_groups, investment.assigned_valuators].compact %> <% no_valuators_assigned = t("admin.budget_investments.index.no_valuators_assigned") %> - <%= raw valuators.present? ? valuators.join(", ") : no_valuators_assigned %> + <%= valuators.present? ? valuators.join(", ") : no_valuators_assigned %> diff --git a/app/views/admin/budget_investments/_written_by_author.html.erb b/app/views/admin/budget_investments/_written_by_author.html.erb index b2bc5b5b5..f030aac91 100644 --- a/app/views/admin/budget_investments/_written_by_author.html.erb +++ b/app/views/admin/budget_investments/_written_by_author.html.erb @@ -55,6 +55,6 @@ <% if @investment.external_url.present? %>

- <%= text_with_links @investment.external_url %>  + <%= sanitize_and_auto_link @investment.external_url %> 

<% end %> diff --git a/app/views/admin/debates/show.html.erb b/app/views/admin/debates/show.html.erb index 2494efa3d..2d70c4596 100644 --- a/app/views/admin/debates/show.html.erb +++ b/app/views/admin/debates/show.html.erb @@ -25,7 +25,7 @@ - <%= safe_html_with_links @debate.description %> + <%= auto_link_already_sanitized_html @debate.description %>

<%= t("votes.supports") %>

diff --git a/app/views/admin/hidden_comments/index.html.erb b/app/views/admin/hidden_comments/index.html.erb index ca26aef31..693efda67 100644 --- a/app/views/admin/hidden_comments/index.html.erb +++ b/app/views/admin/hidden_comments/index.html.erb @@ -15,7 +15,7 @@ <% @comments.each do |comment| %> - <%= text_with_links comment.body %>
+ <%= sanitize_and_auto_link comment.body %>
<% if comment.commentable.hidden? %> (<%= t("admin.hidden_comments.index.hidden_#{comment.commentable_type.downcase}") %>: <%= comment.commentable.title %>) <% else %> diff --git a/app/views/admin/hidden_proposals/index.html.erb b/app/views/admin/hidden_proposals/index.html.erb index 4e23b8c5b..5cbadf84d 100644 --- a/app/views/admin/hidden_proposals/index.html.erb +++ b/app/views/admin/hidden_proposals/index.html.erb @@ -23,7 +23,7 @@

<%= proposal.summary %>

<%= proposal.description %> <% if proposal.video_url.present? %> -

<%= text_with_links proposal.video_url %>

+

<%= sanitize_and_auto_link proposal.video_url %>

<% end %> diff --git a/app/views/admin/hidden_users/show.html.erb b/app/views/admin/hidden_users/show.html.erb index 0a95eab12..1d82fb301 100644 --- a/app/views/admin/hidden_users/show.html.erb +++ b/app/views/admin/hidden_users/show.html.erb @@ -30,7 +30,7 @@ <% @comments.each do |comment| %> - <%= text_with_links comment.body %> + <%= sanitize_and_auto_link comment.body %> <% end %> diff --git a/app/views/admin/site_customization/content_blocks/index.html.erb b/app/views/admin/site_customization/content_blocks/index.html.erb index ddedef7b7..17328f8a2 100644 --- a/app/views/admin/site_customization/content_blocks/index.html.erb +++ b/app/views/admin/site_customization/content_blocks/index.html.erb @@ -32,7 +32,7 @@ <% @content_blocks.each do |content_block| %> <%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_content_block_path(content_block) %> - <%= content_block.body.html_safe %> + <%= raw content_block.body %> <%= link_to t("admin.site_customization.content_blocks.index.delete"), admin_site_customization_content_block_path(content_block), @@ -43,7 +43,7 @@ <% @headings_content_blocks.each do |content_block| %> <%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %> - <%= content_block.body.html_safe %> + <%= raw content_block.body %> <%= link_to t("admin.site_customization.content_blocks.index.delete"), admin_site_customization_delete_heading_content_block_path(content_block.id), diff --git a/app/views/budgets/_phases.html.erb b/app/views/budgets/_phases.html.erb index 61dd1904c..f9791a43e 100644 --- a/app/views/budgets/_phases.html.erb +++ b/app/views/budgets/_phases.html.erb @@ -7,7 +7,7 @@ - <%= l(phase.ends_at.to_date - 1.day, format: :long) if phase.ends_at.present? %> -

<%= safe_html_with_links(phase.summary) %>

+

<%= auto_link_already_sanitized_html(WYSIWYGSanitizer.new.sanitize(phase.summary)) %>

<% end %> diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb index e99de7510..c29a2b4f0 100644 --- a/app/views/budgets/ballot/_ballot.html.erb +++ b/app/views/budgets/ballot/_ballot.html.erb @@ -10,7 +10,7 @@ count: @ballot.investments.count) %>

- <%= t("budgets.ballots.show.voted_info_html") %> + <%= t("budgets.ballots.show.voted_info") %>

<%= t("budgets.ballots.show.voted_info_2") %>

@@ -26,8 +26,8 @@

<%= group.name %> - <%= @ballot.heading_for_group(group).name %>

- <%= link_to t("budgets.ballots.show.remaining", - amount: @ballot.formatted_amount_available(@ballot.heading_for_group(group))).html_safe, + <%= link_to sanitize(t("budgets.ballots.show.remaining", + amount: @ballot.formatted_amount_available(@ballot.heading_for_group(group)))), budget_group_path(@budget, group) %> <% if @ballot.has_lines_in_group?(group) %> diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index e194af049..3ad23eec3 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -15,7 +15,7 @@

<%= current_budget.name %>

- <%= safe_html_with_links(current_budget.description) %> + <%= auto_link_already_sanitized_html(current_budget.description) %>

<%= link_to t("budgets.index.section_header.help"), "#section_help" %> @@ -37,14 +37,14 @@ class: "button margin-top expanded" %> <% else %>

- <%= t("budgets.investments.index.sidebar.verified_only", - verify: link_to_verify_account).html_safe %> + <%= sanitize(t("budgets.investments.index.sidebar.verified_only", + verify: link_to_verify_account)) %>
<% end %> <% else %>
- <%= t("budgets.investments.index.sidebar.not_logged_in", - sign_in: link_to_signin, sign_up: link_to_signup).html_safe %> + <%= sanitize(t("budgets.investments.index.sidebar.not_logged_in", + sign_in: link_to_signin, sign_up: link_to_signup)) %>
<% end %> <% end %> diff --git a/app/views/budgets/investments/_ballot.html.erb b/app/views/budgets/investments/_ballot.html.erb index ae027b2fc..73fe2fe8b 100644 --- a/app/views/budgets/investments/_ballot.html.erb +++ b/app/views/budgets/investments/_ballot.html.erb @@ -51,11 +51,11 @@

- <%= t("budgets.ballots.reasons_for_not_balloting.#{reason}", + <%= sanitize(t("budgets.ballots.reasons_for_not_balloting.#{reason}", verify_account: link_to_verify_account, signin: link_to_signin, signup: link_to_signup, my_heading: my_heading, change_ballot: change_ballot, - heading_link: heading_link(@assigned_heading, @budget)).html_safe %> + heading_link: heading_link(@assigned_heading, @budget))) %>

diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index e080f2ede..138743669 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -93,7 +93,8 @@ title: t("form.accept_terms_title"), label: t("form.accept_terms", policy: link_to(t("form.policy"), "/privacy", target: "blank"), - conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> + conditions: link_to(t("form.conditions"), "/conditions", target: "blank") + ) %> <% end %> diff --git a/app/views/budgets/investments/_header.html.erb b/app/views/budgets/investments/_header.html.erb index 48f78411b..e46e2d287 100644 --- a/app/views/budgets/investments/_header.html.erb +++ b/app/views/budgets/investments/_header.html.erb @@ -40,9 +40,9 @@ heading_link: heading_link(@assigned_heading, @budget)) %>
- <%= t("budgets.investments.header.change_ballot", + <%= sanitize(t("budgets.investments.header.change_ballot", check_ballot: link_to(t("budgets.investments.header.check_ballot_link"), - budget_ballot_path(@budget))).html_safe %> + budget_ballot_path(@budget)))) %> diff --git a/app/views/budgets/investments/_investment_detail.erb b/app/views/budgets/investments/_investment_detail.erb index 6c49abe38..3e9098d8f 100644 --- a/app/views/budgets/investments/_investment_detail.erb +++ b/app/views/budgets/investments/_investment_detail.erb @@ -22,7 +22,7 @@ <%= t("budgets.investments.show.code_html", code: investment.id) %>

-<%= safe_html_with_links investment.description.html_safe %> +<%= auto_link_already_sanitized_html investment.description %> <% if feature?(:map) && map_location_available?(@investment.map_location) %>
@@ -52,7 +52,7 @@ <% if investment.external_url.present? %> <% end %> diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb index 63d577241..b962db9e4 100644 --- a/app/views/budgets/investments/_sidebar.html.erb +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -6,17 +6,17 @@ new_budget_investment_path(budget_id: @budget.id), class: "button budget expanded" %> <% else %>
- <%= t("budgets.investments.index.sidebar.verified_only", - verify: link_to_verify_account).html_safe %> + <%= sanitize(t("budgets.investments.index.sidebar.verified_only", + verify: link_to_verify_account)) %>
<% end %> <% end %> <% if @heading && can?(:show, @ballot) %>

- <%= t("budgets.investments.index.sidebar.voted_info", + <%= sanitize(t("budgets.investments.index.sidebar.voted_info", link: link_to(t("budgets.investments.index.sidebar.voted_info_link"), - budget_ballot_path(@budget))).html_safe %> + budget_ballot_path(@budget)))) %>

<% end %> @@ -52,9 +52,9 @@ ) %>
- <%= t("budgets.investments.index.sidebar.change_ballot", + <%= sanitize(t("budgets.investments.index.sidebar.change_ballot", check_ballot: link_to(t("budgets.investments.index.sidebar.check_ballot_link"), - budget_ballot_path(@budget))).html_safe %> + budget_ballot_path(@budget)))) %>

<% else %> diff --git a/app/views/budgets/investments/_votes.html.erb b/app/views/budgets/investments/_votes.html.erb index 9fca61f6e..b4733a29b 100644 --- a/app/views/budgets/investments/_votes.html.erb +++ b/app/views/budgets/investments/_votes.html.erb @@ -31,13 +31,13 @@ diff --git a/app/views/budgets/show.html.erb b/app/views/budgets/show.html.erb index 0d1bf5779..826752248 100644 --- a/app/views/budgets/show.html.erb +++ b/app/views/budgets/show.html.erb @@ -9,7 +9,7 @@

<%= @budget.name %>

- <%= safe_html_with_links(@budget.description) %> + <%= auto_link_already_sanitized_html(@budget.description) %>

@@ -23,14 +23,14 @@ <%= link_to t("budgets.investments.index.sidebar.create"), new_budget_investment_path(@budget), class: "button margin-top expanded" %> <% else %>

- <%= t("budgets.investments.index.sidebar.verified_only", - verify: link_to_verify_account).html_safe %> + <%= sanitize(t("budgets.investments.index.sidebar.verified_only", + verify: link_to_verify_account)) %>
<% end %> <% else %>
- <%= t("budgets.investments.index.sidebar.not_logged_in", - sign_in: link_to_signin, sign_up: link_to_signup).html_safe %> + <%= sanitize(t("budgets.investments.index.sidebar.not_logged_in", + sign_in: link_to_signin, sign_up: link_to_signup)) %>
<% end %> <% end %> diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 6104d955f..56667f26d 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -80,7 +80,7 @@
- <%= simple_format text_with_links(comment.body), {}, sanitize: false %> + <%= simple_format sanitize_and_auto_link(comment.body), {}, sanitize: false %>
diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb index 9e95cc748..78acd65c4 100644 --- a/app/views/comments/_comment_tree.html.erb +++ b/app/views/comments/_comment_tree.html.erb @@ -24,7 +24,7 @@ <% elsif require_verified_resident_for_commentable?(commentable, current_user) %>
- <%= t("comments.verified_only", verify_account: link_to_verify_account).html_safe %> + <%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
<% elsif allow_comments %> <%= render "comments/form", { commentable: commentable, diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 87b04c317..6b3c9d85f 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,7 +1,7 @@ <% valuation = local_assigns.fetch(:valuation, false) %> <% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable), valuation] do %> <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %> -
class="comment-form"> +
class="comment-form"> <%= form_for Comment.new, remote: true do |f| %> <%= f.text_area :body, id: "comment-body-#{css_id}", diff --git a/app/views/comments/_votes.html.erb b/app/views/comments/_votes.html.erb index 95e2ab60b..925c2d19f 100644 --- a/app/views/comments/_votes.html.erb +++ b/app/views/comments/_votes.html.erb @@ -81,9 +81,7 @@
<% end %>
diff --git a/app/views/dashboard/_proposed_action.html.erb b/app/views/dashboard/_proposed_action.html.erb index ac26e0394..48e69c21a 100644 --- a/app/views/dashboard/_proposed_action.html.erb +++ b/app/views/dashboard/_proposed_action.html.erb @@ -38,10 +38,10 @@ <%= t("dashboard.recommended_actions.show_description") %>
- <%= proposed_action.description.html_safe %> + <%= WYSIWYGSanitizer.new.sanitize(proposed_action.description) %>
<% else %> - <%= proposed_action.description.html_safe %> + <%= WYSIWYGSanitizer.new.sanitize(proposed_action.description) %> <% end %> <% end %> diff --git a/app/views/dashboard/_resource.html.erb b/app/views/dashboard/_resource.html.erb index c71f236d3..bef2c194f 100644 --- a/app/views/dashboard/_resource.html.erb +++ b/app/views/dashboard/_resource.html.erb @@ -23,7 +23,7 @@ class: "button expanded" %> <% else %> - <%== resource_availability_label(resource) %> + <%= resource_availability_label(resource) %> <% end %>
diff --git a/app/views/dashboard/actions/new_request.html.erb b/app/views/dashboard/actions/new_request.html.erb index 1b6fd3710..ba6486ce5 100644 --- a/app/views/dashboard/actions/new_request.html.erb +++ b/app/views/dashboard/actions/new_request.html.erb @@ -2,7 +2,7 @@
- <%== dashboard_action.description %> + <%= WYSIWYGSanitizer.new.sanitize(dashboard_action.description) %> <%= render "dashboard/form" %>
diff --git a/app/views/dashboard/mailer/new_actions_notification_on_create.html.erb b/app/views/dashboard/mailer/new_actions_notification_on_create.html.erb index b26d8f7f9..0f1df7ddd 100644 --- a/app/views/dashboard/mailer/new_actions_notification_on_create.html.erb +++ b/app/views/dashboard/mailer/new_actions_notification_on_create.html.erb @@ -6,7 +6,7 @@

<%= t("mailers.new_actions_notification_on_create.text_1") %>
- <%= t("mailers.new_actions_notification_on_create.text_2", link: proposal_dashboard_url(@proposal)).html_safe %> + <%= sanitize(t("mailers.new_actions_notification_on_create.text_2", link: proposal_dashboard_url(@proposal))) %>

<%= t("mailers.new_actions_notification_on_create.text_3") %>

<%= t("mailers.new_actions_notification_on_create.text_4") %>

diff --git a/app/views/dashboard/mailer/new_actions_notification_on_published.html.erb b/app/views/dashboard/mailer/new_actions_notification_on_published.html.erb index bae02cd64..e566ebd03 100644 --- a/app/views/dashboard/mailer/new_actions_notification_on_published.html.erb +++ b/app/views/dashboard/mailer/new_actions_notification_on_published.html.erb @@ -36,7 +36,7 @@ <% end %> diff --git a/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb b/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb index ff6f3d817..7f4d74cb1 100644 --- a/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb +++ b/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb @@ -10,9 +10,9 @@ title: @proposal.title) %>

- <%= t("mailers.new_actions_notification_rake_created.text_1", + <%= sanitize(t("mailers.new_actions_notification_rake_created.text_1", link_to_published: link_to(proposal_dashboard_url(@proposal), - proposal_dashboard_url(@proposal))).html_safe %> + proposal_dashboard_url(@proposal)))) %>

<%= t("mailers.new_actions_notification_rake_created.text_2") %>


@@ -35,7 +35,7 @@
diff --git a/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb b/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb index f8d7b0d7d..f4b00ba40 100644 --- a/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb +++ b/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb @@ -36,7 +36,7 @@
diff --git a/app/views/dashboard/mailing/new.html.erb b/app/views/dashboard/mailing/new.html.erb index 9cd2a34b5..1c24c2d91 100644 --- a/app/views/dashboard/mailing/new.html.erb +++ b/app/views/dashboard/mailing/new.html.erb @@ -1,7 +1,7 @@ <% content_for :action_title, t("dashboard.mailing.new.title") %>
- <%== Setting["proposals.email_description"] %> + <%= Setting["proposals.email_description"] %>
<%= render "mailing_options" %> diff --git a/app/views/dashboard/polls/index.html.erb b/app/views/dashboard/polls/index.html.erb index 031c0da4f..24c9fd82d 100644 --- a/app/views/dashboard/polls/index.html.erb +++ b/app/views/dashboard/polls/index.html.erb @@ -1,7 +1,7 @@ <% content_for :action_title, t("dashboard.polls.index.title") %>
- <%== Setting["proposals.poll_description"] %> + <%= Setting["proposals.poll_description"] %> <% if @polls.any? %>
diff --git a/app/views/dashboard/poster/new.html.erb b/app/views/dashboard/poster/new.html.erb index 893f05ff9..172b34f92 100644 --- a/app/views/dashboard/poster/new.html.erb +++ b/app/views/dashboard/poster/new.html.erb @@ -1,7 +1,7 @@ <% content_for :action_title, t("dashboard.poster.new.title") %>
- <%== Setting["proposals.poster_description"] %> + <%= Setting["proposals.poster_description"] %>
<%= render "poster_options" %> diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index d74e08272..38b4e2bcc 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -39,7 +39,7 @@ label: t("form.accept_terms", policy: link_to(t("form.policy"), "/privacy", target: "blank"), conditions: link_to(t("form.conditions"), "/conditions", target: "blank") - ).html_safe %> + ) %> <% end %>
diff --git a/app/views/debates/_votes.html.erb b/app/views/debates/_votes.html.erb index cb7cdf9f5..9cd3437a4 100644 --- a/app/views/debates/_votes.html.erb +++ b/app/views/debates/_votes.html.erb @@ -52,7 +52,7 @@ <% elsif user_signed_in? && !debate.votable_by?(current_user) %> <% elsif !user_signed_in? %> diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 53788434d..d4920644b 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -86,8 +86,8 @@

<%= t("debates.index.section_footer.description") %>

<%= t("debates.index.section_footer.help_text_1") %>

-

<%= t("debates.index.section_footer.help_text_2", - org: link_to(setting["org_name"], new_user_registration_path)).html_safe %>

+

<%= sanitize(t("debates.index.section_footer.help_text_2", + org: link_to(setting["org_name"], new_user_registration_path))) %>

<% end %> diff --git a/app/views/debates/new.html.erb b/app/views/debates/new.html.erb index cf3cbc7b9..4e75679de 100644 --- a/app/views/debates/new.html.erb +++ b/app/views/debates/new.html.erb @@ -5,11 +5,11 @@

<%= t("debates.new.start_new") %>

- <%= t("debates.new.info", - info_link: link_to(t("debates.new.info_link"), new_proposal_path)).html_safe %> + <%= sanitize(t("debates.new.info", + info_link: link_to(t("debates.new.info_link"), new_proposal_path))) %> <% if feature?(:help_page) %> - <%= link_to help_path, title: t("shared.target_blank_html"), target: "_blank" do %> + <%= link_to help_path, title: t("shared.target_blank"), target: "_blank" do %> <%= t("debates.new.more_info") %> <% end %> <% end %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index b8814d75b..113041e63 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -30,7 +30,7 @@
- <%= safe_html_with_links @debate.description %> + <%= auto_link_already_sanitized_html @debate.description %> <%= render "shared/tags", taggable: @debate %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index cba9e6ec0..d0d219c62 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -4,8 +4,8 @@ <%= render "devise/omniauth_form" %>

- <%= t("devise_views.shared.links.signup", - signup_link: link_to(t("devise_views.shared.links.signup_link"), new_user_registration_path)).html_safe %> + <%= sanitize(t("devise_views.shared.links.signup", + signup_link: link_to(t("devise_views.shared.links.signup_link"), new_user_registration_path))) %>

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> diff --git a/app/views/direct_messages/new.html.erb b/app/views/direct_messages/new.html.erb index 30078978e..8c0635a26 100644 --- a/app/views/direct_messages/new.html.erb +++ b/app/views/direct_messages/new.html.erb @@ -9,8 +9,8 @@ <% if not current_user %>

- <%= t("users.login_to_continue", - signin: link_to_signin, signup: link_to_signup).html_safe %> + <%= sanitize(t("users.login_to_continue", + signin: link_to_signin, signup: link_to_signup)) %>

<% elsif not @receiver.email_on_direct_message? %> @@ -33,8 +33,8 @@ <% else %>

- <%= t("users.direct_messages.new.verified_only", - verify_account: link_to_verify_account).html_safe %> + <%= sanitize(t("users.direct_messages.new.verified_only", + verify_account: link_to_verify_account)) %>

<% end %> diff --git a/app/views/direct_messages/show.html.erb b/app/views/direct_messages/show.html.erb index 3757524cc..7a3ce847a 100644 --- a/app/views/direct_messages/show.html.erb +++ b/app/views/direct_messages/show.html.erb @@ -10,6 +10,6 @@

<%= @direct_message.title %>

-

<%= simple_format text_with_links(@direct_message.body), {}, sanitize: false %>

+

<%= simple_format sanitize_and_auto_link(@direct_message.body), {}, sanitize: false %>

diff --git a/app/views/kaminari/_first_page.html.erb b/app/views/kaminari/_first_page.html.erb index e8afb0431..a5335a30b 100644 --- a/app/views/kaminari/_first_page.html.erb +++ b/app/views/kaminari/_first_page.html.erb @@ -1,3 +1,3 @@
  • - <%= link_to t("views.pagination.first").html_safe, kaminari_path(url), :remote => remote %> + <%= link_to t("views.pagination.first"), kaminari_path(url), :remote => remote %>
  • diff --git a/app/views/kaminari/_gap.html.erb b/app/views/kaminari/_gap.html.erb index fc2dbed0f..f5932a473 100644 --- a/app/views/kaminari/_gap.html.erb +++ b/app/views/kaminari/_gap.html.erb @@ -1,3 +1,3 @@ diff --git a/app/views/kaminari/_last_page.html.erb b/app/views/kaminari/_last_page.html.erb index 5a49bd7e2..697b3bd15 100644 --- a/app/views/kaminari/_last_page.html.erb +++ b/app/views/kaminari/_last_page.html.erb @@ -1,3 +1,3 @@
  • - <%= link_to t("views.pagination.last").html_safe, kaminari_path(url), :remote => remote %> + <%= link_to t("views.pagination.last"), kaminari_path(url), :remote => remote %>
  • diff --git a/app/views/kaminari/_next_page.html.erb b/app/views/kaminari/_next_page.html.erb index 11c700900..366367031 100644 --- a/app/views/kaminari/_next_page.html.erb +++ b/app/views/kaminari/_next_page.html.erb @@ -1,3 +1,3 @@
  • - <%= link_to t("views.pagination.next").html_safe, kaminari_path(url), :rel => "next", :remote => remote %> + <%= link_to t("views.pagination.next"), kaminari_path(url), :rel => "next", :remote => remote %>
  • diff --git a/app/views/kaminari/_prev_page.html.erb b/app/views/kaminari/_prev_page.html.erb index aba1d9369..d0147ff5c 100644 --- a/app/views/kaminari/_prev_page.html.erb +++ b/app/views/kaminari/_prev_page.html.erb @@ -1,3 +1,3 @@
  • - <%= link_to t("views.pagination.previous").html_safe, kaminari_path(url), :rel => "prev", :remote => remote %> + <%= link_to t("views.pagination.previous"), kaminari_path(url), :rel => "prev", :remote => remote %>
  • diff --git a/app/views/layouts/_flash.html.erb b/app/views/layouts/_flash.html.erb index a0f129224..6f881eeba 100644 --- a/app/views/layouts/_flash.html.erb +++ b/app/views/layouts/_flash.html.erb @@ -5,7 +5,7 @@
    - <%= flash_message.try(:html_safe) %> + <%= sanitize(flash_message) %>
    diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index 1337be64b..383469811 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -2,14 +2,13 @@

    - <%= link_to t("layouts.header.open_gov", open: "#{t("layouts.header.open")}").html_safe %> + <%= link_to t("layouts.header.open_gov", open: t("layouts.header.open")), root_path %>

    - <%= t("layouts.footer.description", + <%= sanitize(t("layouts.footer.description", open_source: link_to(t("layouts.footer.open_source"), t("layouts.footer.open_source_url"), target: "blank", rel: "nofollow"), - consul: link_to(t("layouts.footer.consul"), t("layouts.footer.consul_url"), target: "blank", rel: "nofollow")).html_safe - %> + consul: link_to(t("layouts.footer.consul"), t("layouts.footer.consul_url"), target: "blank", rel: "nofollow"))) %> <%= t("layouts.footer.contact_us") %>

    @@ -38,7 +37,7 @@ <% if setting["twitter_handle"] %>
  • <%= link_to "https://twitter.com/#{setting["twitter_handle"]}", target: "_blank", - title: t("shared.go_to_page") + t("social.twitter", org: setting["org_name"]) + t("shared.target_blank_html") do %> + title: t("shared.go_to_page") + t("social.twitter", org: setting["org_name"]) + t("shared.target_blank") do %> <%= t("social.twitter", org: setting["org_name"]) %> <% end %> @@ -47,7 +46,7 @@ <% if setting["facebook_handle"] %>
  • <%= link_to "https://www.facebook.com/#{setting["facebook_handle"]}/", target: "_blank", - title: t("shared.go_to_page") + t("social.facebook", org: setting["org_name"]) + t("shared.target_blank_html") do %> + title: t("shared.go_to_page") + t("social.facebook", org: setting["org_name"]) + t("shared.target_blank") do %> <%= t("social.facebook", org: setting["org_name"]) %> <% end %> @@ -56,7 +55,7 @@ <% if setting["youtube_handle"] %>
  • <%= link_to "https://www.youtube.com/#{setting["youtube_handle"]}", target: "_blank", - title: t("shared.go_to_page") + t("social.youtube", org: setting["org_name"]) + t("shared.target_blank_html") do %> + title: t("shared.go_to_page") + t("social.youtube", org: setting["org_name"]) + t("shared.target_blank") do %> <%= t("social.youtube", org: setting["org_name"]) %> <% end %> @@ -65,7 +64,7 @@ <% if setting["telegram_handle"] %>
  • <%= link_to "https://www.telegram.me/#{setting["telegram_handle"]}", target: "_blank", - title: t("shared.go_to_page") + t("social.telegram", org: setting["org_name"]) + t("shared.target_blank_html") do %> + title: t("shared.go_to_page") + t("social.telegram", org: setting["org_name"]) + t("shared.target_blank") do %> <%= t("social.telegram", org: setting["org_name"]) %> <% end %> @@ -74,7 +73,7 @@ <% if setting["instagram_handle"] %>
  • <%= link_to "https://www.instagram.com/#{setting["instagram_handle"]}", target: "_blank", - title: t("shared.go_to_page") + t("social.instagram", org: setting["org_name"]) + t("shared.target_blank_html") do %> + title: t("shared.go_to_page") + t("social.instagram", org: setting["org_name"]) + t("shared.target_blank") do %> <%= t("social.instagram", org: setting["org_name"]) %> <% end %> diff --git a/app/views/layouts/_notification_item.html.erb b/app/views/layouts/_notification_item.html.erb index 7a21a3c38..c766f862a 100644 --- a/app/views/layouts/_notification_item.html.erb +++ b/app/views/layouts/_notification_item.html.erb @@ -10,11 +10,11 @@ <%= t("layouts.header.notification_item.new_notifications", - count: current_user.notifications_count).html_safe %> + count: current_user.notifications_count) %> <% else %>