-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure brakeman to ignore url safe preview card urls
These values are validated on the way to being saved, and html escaped by Rails in the views. The inclusion of the helper method here is a bit of a workaround to give brakeman a method name to ignore.
- Loading branch information
1 parent
9f218c9
commit 7f0dbf9
Showing
5 changed files
with
27 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
--- | ||
:skip_checks: | ||
- CheckPermitAttributes | ||
:url_safe_methods: | ||
- url_for_preview_card |
20 changes: 20 additions & 0 deletions
20
spec/views/admin/trends/links/_preview_card.html.haml_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'admin/trends/links/_preview_card.html.haml' do | ||
it 'correctly escapes user supplied url values' do | ||
form = instance_double(ActionView::Helpers::FormHelper, check_box: nil) | ||
trend = PreviewCardTrend.new(allowed: false) | ||
preview_card = Fabricate.build( | ||
:preview_card, | ||
url: 'https://host.example/path?query=<script>', | ||
trend: trend, | ||
title: 'Fun' | ||
) | ||
|
||
render partial: 'admin/trends/links/preview_card', locals: { preview_card: preview_card, f: form } | ||
|
||
expect(rendered).to include('<a href="https://host.example/path?query=<script>">Fun</a>') | ||
end | ||
end |