Skip to content

Commit

Permalink
Refactor preview_card partial to avoid brakeman XSS warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Oct 17, 2023
1 parent 0036de4 commit d67fb5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
6 changes: 6 additions & 0 deletions app/helpers/formatting_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module FormattingHelper
include ERB::Util

def html_aware_format(text, local, options = {})
HtmlAwareFormatter.new(text, local, options).to_s
end
Expand All @@ -9,6 +11,10 @@ def linkify(text, options = {})
TextFormatter.new(text, options).to_s
end

def encode_url(url)
url_encode(url)
end

def extract_status_plain_text(status)
PlainTextFormatter.new(status.text, status.local?).to_s
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/trends/links/_preview_card.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.batch-table__row__content.pending-account
.pending-account__header
= link_to preview_card.title, preview_card.url
= link_to preview_card.title, encode_url(preview_card.url)

%br/

Expand Down
33 changes: 0 additions & 33 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,6 @@
79
],
"note": ""
},
{
"warning_type": "Cross-Site Scripting",
"warning_code": 4,
"fingerprint": "cd5cfd7f40037fbfa753e494d7129df16e358bfc43ef0da3febafbf4ee1ed3ac",
"check_name": "LinkToHref",
"message": "Potentially unsafe model attribute in `link_to` href",
"file": "app/views/admin/trends/links/_preview_card.html.haml",
"line": 7,
"link": "https://brakemanscanner.org/docs/warning_types/link_to_href",
"code": "link_to((Unresolved Model).new.title, (Unresolved Model).new.url)",
"render_path": [
{
"type": "template",
"name": "admin/trends/links/index",
"line": 49,
"file": "app/views/admin/trends/links/index.html.haml",
"rendered": {
"name": "admin/trends/links/_preview_card",
"file": "app/views/admin/trends/links/_preview_card.html.haml"
}
}
],
"location": {
"type": "template",
"template": "admin/trends/links/_preview_card"
},
"user_input": "(Unresolved Model).new.url",
"confidence": "Weak",
"cwe_id": [
79
],
"note": ""
}
],
"updated": "2023-07-12 11:20:51 -0400",
Expand Down

0 comments on commit d67fb5c

Please sign in to comment.