Skip to content

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

Disable CORS on /login/oauth/authorize (#6657)

Artur Patace05236bdf1f
diff --git a/lib/plausible_web/endpoint.ex b/lib/plausible_web/endpoint.ex
index 0fce02defe..a63319e902 100644
--- a/lib/plausible_web/endpoint.ex
+++ b/lib/plausible_web/endpoint.ex
@@ -2,6 +2,7 @@ defmodule PlausibleWeb.Endpoint do
use Plausible
use Sentry.PlugCapture
use Phoenix.Endpoint, otp_app: :plausible
+ use PlausibleWeb.VerifiedRoutes
on_ce do
plug :maybe_handle_acme_challenge
@@ -85,7 +86,7 @@ defmodule PlausibleWeb.Endpoint do
plug(:runtime_session)
- plug(CORSPlug)
+ plug(:cors)
plug(PlausibleWeb.Router)
def secure_cookie?, do: config!(:secure_cookie)
@@ -94,6 +95,17 @@ defmodule PlausibleWeb.Endpoint do
config!(:websocket_url)
end
+ @cors_opts CORSPlug.init([])
+
+ # CORS must not be supported at the [authorization endpoint](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1#name-authorization-endpoint)
+ def cors(conn, _opts) do
+ if conn.request_path == ~p"/login/oauth/authorize" do
+ conn
+ else
+ CORSPlug.call(conn, @cors_opts)
+ end
+ end
+
def runtime_session(conn, _opts) do
Plug.run(conn, [{Plug.Session, runtime_session_opts()}])
end