mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Allow embedding to ignore HTTP REFERER
New site setting: `embed_any_origin` that will send postMessages to wildcard origins `*` instead of the referer. Most of the time you won't want to do this, so the setting is default to `false`. However, there are certain situations where you want to allow embedding to send post messages when there is no HTTP REFERER. For example, if you created a native mobile app and you wanted to embed a list of Discourse topics as HTML. In the code your HTML would be a static file/string, which would not be able to send a referer. In this case, the site setting will allow the embed to work. From a security standpoint we currently only use `postMessage` to send data about the size of the HTML document and scroll position, so it should be enable if required with minimal security ramifications.
This commit is contained in:
@@ -88,12 +88,29 @@ describe EmbedController do
|
||||
|
||||
it "returns a list of topics" do
|
||||
topic = Fabricate(:topic)
|
||||
get '/embed/topics?discourse_embed_id=de-1234', headers: headers
|
||||
get '/embed/topics?discourse_embed_id=de-1234', headers: {
|
||||
'REFERER' => 'https://example.com/evil-trout'
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.headers['X-Frame-Options']).to eq("ALLOWALL")
|
||||
expect(response.body).to match("data-embed-id=\"de-1234\"")
|
||||
expect(response.body).to match("data-topic-id=\"#{topic.id}\"")
|
||||
expect(response.body).to match("data-referer=\"https://example.com/evil-trout\"")
|
||||
end
|
||||
|
||||
it "returns no referer if not supplied" do
|
||||
get '/embed/topics?discourse_embed_id=de-1234'
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to match("data-referer=\"\"")
|
||||
end
|
||||
|
||||
it "returns * for the referer if `embed_any_origin` is set" do
|
||||
SiteSetting.embed_any_origin = true
|
||||
get '/embed/topics?discourse_embed_id=de-1234'
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to match("data-referer=\"\\*\"")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user