Sanitize markdown output

We were using the markdown renderer with the `filter_html` option set to
false, so we weren't removing hypothetical `<script>` tags.
This commit is contained in:
Javi Martín
2019-10-06 15:10:26 +02:00
parent 61bf9a5c73
commit 9eee79f218
3 changed files with 12 additions and 3 deletions

View File

@@ -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)

View File

@@ -49,7 +49,7 @@
<div data-sticky-container>
<div data-sticky data-anchor="sticky-panel" class="draft-index sticky" data-tree-navigator>
<%= @draft_version.toc_html.html_safe %>
<%= sanitize(@draft_version.toc_html) %>
</div>
</div>
</div>
@@ -66,7 +66,7 @@
data-legislation-annotatable-base-url="<%= legislation_process_draft_version_path(@process, @draft_version) %>"
data-legislation-open-phase="<%= @process.allegations_phase.open? %>">
<% end %>
<%= @draft_version.body_html.html_safe %>
<%= sanitize(@draft_version.body_html) %>
</section>
</div>
</div>

View File

@@ -78,4 +78,12 @@ describe "Cross-Site Scripting protection", :js do
expect(page.text).not_to be_empty
end
scenario "markdown conversion" do
process = create(:legislation_process, description: attack_code)
visit legislation_process_path(process)
expect(page.text).not_to be_empty
end
end