Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ All notable changes to this project will be documented in this file.
- Change auth session cookies to token-based ones with server-side expiration management.
- Improve Google error messages in CE plausible/analytics#4485
- Better compress static assets in CE plausible/analytics#4476
- Return domain-less cookies in CE plausible/analytics#4482

### Fixed

Expand Down
21 changes: 14 additions & 7 deletions lib/plausible_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule PlausibleWeb.Endpoint do
# 5 years, this is super long but the SlidingSessionTimeout will log people out if they don't return for 2 weeks
max_age: 60 * 60 * 24 * 365 * 5,
extra: "SameSite=Lax"
# domain added dynamically via RuntimeSessionAdapter, see below
# in EE domain is added dynamically via RuntimeSessionAdapter, see below
]

socket("/live", Phoenix.LiveView.Socket,
Expand Down Expand Up @@ -103,12 +103,19 @@ defmodule PlausibleWeb.Endpoint do
end

def runtime_session_opts() do
# `host()` provided by Phoenix.Endpoint's compilation hooks
# is used to inject the domain - this way we can authenticate
# websocket requests within single root domain, in case websocket_url()
# returns a ws{s}:// scheme (in which case SameSite=Lax is not applicable).
@session_options
|> Keyword.put(:domain, host())
session_options =
on_ee do
# `host()` provided by Phoenix.Endpoint's compilation hooks
# is used to inject the domain - this way we can authenticate
# websocket requests within single root domain, in case websocket_url()
# returns a ws{s}:// scheme (in which case SameSite=Lax is not applicable).
Keyword.put(@session_options, :domain, host())
else
# CE setup is simpler and we don't need to worry about WS domain being different
@session_options
end

session_options
|> Keyword.put(:key, "_plausible_#{Application.fetch_env!(:plausible, :environment)}")
|> Keyword.put(:secure, secure_cookie?())
end
Expand Down