A platform for community discussion. Free, open, simple.
SECURITY: Oneboxer should escape the URL before processing
Vinoth Kannan58bb3967e5b4
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rbindex 935233ead73..b8394f16901 100644--- a/lib/oneboxer.rb+++ b/lib/oneboxer.rb@@ -1,3 +1,4 @@+require 'uri'require_dependency "onebox/discourse_onebox_sanitize_config"require_dependency 'final_destination'@@ -131,6 +132,7 @@ module Oneboxerenddef self.onebox_raw(url, opts = {})+ url = URI(url).to_slocal_onebox(url, opts) || external_onebox(url)rescue => e# no point warning here, just cause we have an issue oneboxing a urldiff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rbindex 6ba23c3a950..601af265fc9 100644--- a/spec/components/oneboxer_spec.rb+++ b/spec/components/oneboxer_spec.rb@@ -98,4 +98,13 @@ describe Oneboxer doend+ context ".onebox_raw" do+ it "should escape the onebox URL before processing" do+ post = Fabricate(:post, raw: Discourse.base_url + "/new?'class=black")+ cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)+ cpp.post_process_oneboxes+ expect(cpp.html).to eq("<a href=\"#{Discourse.base_url}/new?%27class=black\">http://test.localhost/new?%27class=black</a>")+ end+ end+end