Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Adjust secure headers for shared links to avoid breaking embeds (#5785)

Adrian Gruntkowskif6c6dec59e73
diff --git a/lib/plausible_web/plugs/secure_embed_headers.ex b/lib/plausible_web/plugs/secure_embed_headers.ex
new file mode 100644
index 0000000000..17f1745b4a
--- /dev/null
+++ b/lib/plausible_web/plugs/secure_embed_headers.ex
@@ -0,0 +1,22 @@
+defmodule PlausibleWeb.Plugs.SecureEmbedHeaders do
+ @moduledoc """
+ Sets secure headers tailored for embedded content.
+ """
+
+ import Plug.Conn
+
+ def init(_opts) do
+ []
+ end
+
+ def call(conn, _opts) do
+ merge_resp_headers(
+ conn,
+ [
+ {"referrer-policy", "strict-origin-when-cross-origin"},
+ {"x-content-type-options", "nosniff"},
+ {"x-permitted-cross-domain-policies", "none"}
+ ]
+ )
+ end
+end
diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex
index bc854c47cb..31f2f72e54 100644
--- a/lib/plausible_web/router.ex
+++ b/lib/plausible_web/router.ex
@@ -35,7 +35,7 @@ defmodule PlausibleWeb.Router do
pipeline :shared_link do
plug :accepts, ["html"]
- plug :put_secure_browser_headers
+ plug PlausibleWeb.Plugs.SecureEmbedHeaders
plug PlausibleWeb.Plugs.NoRobots
plug :put_root_layout, html: {PlausibleWeb.LayoutView, :app}
end