# No \`Referer:\`, no embedding

**URL:** <https://meta.discourse.org/t/no-referer-no-embedding/163524>\
**Category:** Product Support\
**Created:** [September 9, 2020, 3:38pm UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524 "2020-09-09T15:38:34Z")\
**Posts on this page:** 6\
**Page:** 1

## AI-generated summary

Discourse embedding fails when the browser suppresses the `Referer:` header, resulting in a `400 Bad Request` error. This issue is observed in private Firefox and Safari windows. [AxelN](/t/-/163524/1) notes that enabling "embed any origin" and having comments for only one embedding site does not resolve the issue.

[AxelN](/t/-/163524/3) suspects the problem may be related to the difference in domain names between the blog and the forum. However, he later finds a simpler solution by adding a `<meta>` tag to the embedding page, allowing cross-site embedding to work [AxelN](/t/-/163524/4).

[Gja](/t/-/163524/5) suggests an alternative approach, proposing to accept requests that match specific conditions, including the presence of `discourseEmbedUrl` and `Referer` headers. However, [AxelN](/t/-/163524/6) cautions that this approach may not be robust enough, as Safari and Firefox/private browsers suppress the `Referer` header completely, and recommends adding the `<meta>` tag instead.

<div class="post-metadata">

**Author:** ![AxelN](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axeln/32/120662_2.png) [@AxelN](https://meta.discourse.org/u/AxelN)\
**Post date:** [September 9, 2020, 3:38pm UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524/1 "2020-09-09T15:38:34Z")

</div>

Hi,

We use Discourse embedding for Jekyll at [New ROOT Web Site! - ROOT](https://root.cern/blog/new-web-site/) - works like a charm! Unless - the browser is suppressing the `Referer:` header, in which case we get a `400 Bad Request`. Try yourself - if you switch to a private Firefox window (which suppresses referrers) then embedding is broken. Same for Safari which seems to be a bit stricter on handing out referrers.

I cross checked by looking at [New ROOT Web Site! - Blog - ROOT Forum](https://root-forum.cern.ch/embed/comments?embed_url=https%3A%2F%2Froot.cern%2Fblog%2Fnew-web-site%2F) in a Firefox private window which gives me a HTTP 400; then editing the request to add `Referer: https://root.cern/blog/new-web-site/` - and the 400 turns into a 200 happiness.

We do have “embed any origin” enabled. We have comments for exactly one embedding site. Is there a way we can make that work?

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [September 10, 2020, 4:19pm UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524/2 "2020-09-10T16:19:20Z")

</div>

> [@AxelN](#):
>
> Try yourself - if you switch to a private Firefox window (which suppresses referrers) then embedding is broken.

Yes, I can reproduce that.

It’s interesting that embedded comments at [https://blog.codinghorror.com/the-cloud-is-just-someone-elses-computer/](https://blog.codinghorror.com/the-cloud-is-just-someone-elses-computer/) work without issue in a Firefox private window. Could the issue be related to the domain? Your blog is on `root.cern` and your form is on `root-forum.cern.ch`.

---

<div class="post-metadata">

**Author:** ![AxelN](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axeln/32/120662_2.png) [@AxelN](https://meta.discourse.org/u/AxelN)\
**Post date:** [September 10, 2020, 4:35pm UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524/3 "2020-09-10T16:35:43Z")

</div>

Hi Simon,

Thanks for looking at this! It could very well be related to the difference in domain names: I could imagine that browsers are providing referrers for a request to the same domain, but not to a different domain. But while that’s interesting I don’t yet see what we can do to fix this - we won’t be able to use `root.cern` as the forum domain, and that cross-domain embedding seemed a key and super useful feature… Is this simply at risk these days, given improved privacy, or can you think of a way out?

Something I might want to try is reverse proxying from root.cern/forum to root-forum.cern.ch. That way, the embedding can be done as if it’s on the same host, and we keep a referrer…? I’ll be back 🙂

Cheers, Axel

---

<div class="post-metadata">

**Author:** ![AxelN](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axeln/32/120662_2.png) [@AxelN](https://meta.discourse.org/u/AxelN)\
**Post date:** [September 14, 2020, 9:58am UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524/4 "2020-09-14T09:58:59Z")

</div>

Hi,

I now have a way simpler solution. It’s something that should probably be called out in [Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963) :

For cross-site embedding, in the embedding pages, add either

- `<meta name="referrer" content="strict-origin">` with `Path Allowlist` set to `/.*` (because no path will be provided), or
- `<meta name="referrer" content="no-referrer-when-downgrade">` with the actual `Path Allowlist`.

As mentioned in [Referrer-Policy header - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy), “There is effort from browsers in moving to a stricter default value,” and Discourse embedding relies on the old default for cross-host embedding.

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![gja](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gja/32/165241_2.png) [@gja](https://meta.discourse.org/u/gja)\
**Post date:** [September 16, 2020, 4:32pm UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524/5 "2020-09-16T16:32:34Z")

</div>

Given that this is going to be the default browser standard from Chrome 85 onwards ([A new default Referrer-Policy for Chrome - strict-origin-when-cross-origin &nbsp;|&nbsp; Blog &nbsp;|&nbsp; Chrome for Developers](https://developers.google.com/web/updates/2020/07/referrer-policy-new-chrome-default)), should we look at an alternative here?

Can we accept requests which match **all** of the following three conditions

- Request contains both `discourseEmbedUrl` and `Referer`
- The referer is set to the origin of the `discourseEmbedUrl`
- The `discourseEmbedUrl` matches one of the of the embedding rules

I think passing the discourseEmbedUrl would be easy to do for a majority of users.

---

<div class="post-metadata">

**Author:** ![AxelN](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/axeln/32/120662_2.png) [@AxelN](https://meta.discourse.org/u/AxelN)\
**Post date:** [September 16, 2020, 7:17pm UTC](https://meta.discourse.org/t/no-referer-no-embedding/163524/6 "2020-09-16T19:17:28Z")

</div>

Just a warning, Tejas - AFAIK without the `meta` tag, Safari and Firefox / Private suppress the `Referer` header completely. What you suggest might work for Chrome \>= 85, but adding the `meta` tag seems more robust / general and I suspect is sufficiently trivial for most embeddings?
