diff --git a/app/helpers/in_product_marketing_helper.rb b/app/helpers/in_product_marketing_helper.rb index 09546f251f98f6dab113c91f0829bfccd9f159f9..62612cb2a2229629bfe1641f54791a9eb7371748 100644 --- a/app/helpers/in_product_marketing_helper.rb +++ b/app/helpers/in_product_marketing_helper.rb @@ -2,7 +2,10 @@ module InProductMarketingHelper def inline_image_link(image, options) - attachments.inline[image] = File.read(Rails.root.join("app/assets/images", image)) + asset_path = Rails.root.join("app/assets/images").to_s + image_path = File.join(asset_path, image) + Gitlab::PathTraversal.check_allowed_absolute_path_and_path_traversal!(image_path, [asset_path]) + attachments.inline[image] = File.read(image_path) image_tag attachments[image].url, **options end diff --git a/spec/helpers/in_product_marketing_helper_spec.rb b/spec/helpers/in_product_marketing_helper_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..ab11135191978f15bcef5da4f1d803e6dfda463a --- /dev/null +++ b/spec/helpers/in_product_marketing_helper_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe InProductMarketingHelper, feature_category: :activation do + describe '#inline_image_link' do + let(:image) { 'gitlab_logo.png' } + + before do + attachments = instance_double(Mail::AttachmentsList).as_null_object + + allow(helper).to receive(:attachments).and_return(attachments) + allow(attachments).to receive(:[]).with(image).and_return(Mail::Part.new) + end + + it 'checks for path traversal' do + asset_path = Rails.root.join("app/assets/images").to_s + image_path = File.join(asset_path, image) + + expect(Gitlab::PathTraversal).to receive(:check_allowed_absolute_path_and_path_traversal!) + .with(image_path, [asset_path]) + + helper.inline_image_link(image, {}) + end + end +end