Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/advertisement_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def community_icon(icon_path)
icon = Magick::ImageList.new("./app/assets/images/#{File.basename(expanded_path)}")
else
icon = Magick::ImageList.new
icon_path_content = URI.open(icon_path).read # rubocop:disable Security/Open
icon_path_content = URI.parse(icon_path).open.read
icon.from_blob(icon_path_content)
end

Expand Down
14 changes: 14 additions & 0 deletions test/helpers/advertisement_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class AdvertisementHelperTest < ActionView::TestCase
setup do
@external_png = File.open(Rails.root.join('app/assets/images/logo.png'))
stub_request(:get, 'https://example.com/external.png').to_return(body: @external_png)

FileUtils.rm_f(command_execution_test_filepath)
end

teardown do
Expand All @@ -24,4 +26,16 @@ class AdvertisementHelperTest < ActionView::TestCase
icon = community_icon('https://example.com/external.png')
assert icon.is_a?(Magick::ImageList)
end

test ':community_icon should not allow system command execution' do
community_icon('| touch "tmp/oops.txt"')

assert_not File.exist?(command_execution_test_filepath)
end

private

def command_execution_test_filepath
Rails.root.join('tmp/oops.txt')
end
end
Loading