mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
SECURITY: Prevent XSS in local oneboxes (#20008)
Co-authored-by: OsamaSayegh <asooomaasoooma90@gmail.com>
This commit is contained in:
co-authored by
OsamaSayegh
parent
f55e0fe791
commit
c186a46910
@@ -198,6 +198,66 @@ RSpec.describe Oneboxer do
|
||||
"<p><a href=\"#{Discourse.base_url}/new?%27class=black\">http://test.localhost/new?%27class=black</a></p>",
|
||||
)
|
||||
end
|
||||
|
||||
it "escapes URLs of local audio uploads" do
|
||||
result =
|
||||
described_class.onebox_raw(
|
||||
"#{Discourse.base_url}/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'<>",
|
||||
)
|
||||
expect(result[:onebox]).to eq(<<~HTML)
|
||||
<audio controls>
|
||||
<source src='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'%3C%3E'>
|
||||
<a href='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'%3C%3E'>
|
||||
http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'%3C%3E
|
||||
</a>
|
||||
</audio>
|
||||
HTML
|
||||
expect(result[:preview]).to eq(<<~HTML)
|
||||
<audio controls>
|
||||
<source src='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'%3C%3E'>
|
||||
<a href='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'%3C%3E'>
|
||||
http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.wav#'%3C%3E
|
||||
</a>
|
||||
</audio>
|
||||
HTML
|
||||
end
|
||||
|
||||
it "escapes URLs of local video uploads" do
|
||||
result =
|
||||
described_class.onebox_raw(
|
||||
"#{Discourse.base_url}/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'<>",
|
||||
)
|
||||
expect(result[:onebox]).to eq(<<~HTML)
|
||||
<div class="onebox video-onebox">
|
||||
<video width="100%" height="100%" controls="">
|
||||
<source src='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'%3C%3E'>
|
||||
<a href='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'%3C%3E'>
|
||||
http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'%3C%3E
|
||||
</a>
|
||||
</video>
|
||||
</div>
|
||||
HTML
|
||||
expect(result[:preview]).to eq(<<~HTML)
|
||||
<div class="onebox video-onebox">
|
||||
<video width="100%" height="100%" controls="">
|
||||
<source src='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'%3C%3E'>
|
||||
<a href='http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'%3C%3E'>
|
||||
http://test.localhost/uploads/default/original/1X/a1c31803be81b85ecafc4f77b1008eee9b3b82f4.mp4#'%3C%3E
|
||||
</a>
|
||||
</video>
|
||||
</div>
|
||||
HTML
|
||||
end
|
||||
|
||||
it "escapes URLs of generic local links" do
|
||||
result = described_class.onebox_raw("#{Discourse.base_url}/g/somegroup#'onerror='")
|
||||
expect(result[:onebox]).to eq(
|
||||
"<a href='http://test.localhost/g/somegroup#'onerror=''>http://test.localhost/g/somegroup#'onerror='</a>",
|
||||
)
|
||||
expect(result[:preview]).to eq(
|
||||
"<a href='http://test.localhost/g/somegroup#'onerror=''>http://test.localhost/g/somegroup#'onerror='</a>",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".external_onebox" do
|
||||
|
||||
Reference in New Issue
Block a user