Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting cookie max age #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ All settings are configured through environment variables.
* `SESSION_COOKIE_SECURE`: Set SECURE flag of the session cookie (see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie))
* `SESSION_COOKIE_HTTP_ONLY`: Set HTTP_ONLY flag of the session cookie (see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)), on by default.
* `SESSION_COOKIE_SAME_SITE`: Set SAME_SITE flag of the session cookie (see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)), "Lax" by default unless `DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_HEADER` is "*" then "None" by default. This means the cookie is available only on your site unless you've also set the CORS header.
* `SESSION_COOKIE_MAX_AGE`: Set the number of seconds until the cookie expires. By default this is not set and the cookie is a [session cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#expiresdate).
* `IDLE_TIMEOUT`: the amount of time (in ms) that idle requests will be kept open (see [`idle_timeout` in the Cowboy docs](https://ninenines.eu/docs/en/cowboy/2.5/manual/cowboy_http/))
* `OVERRIDE_VARY_HEADER`: EXPERIMENTAL When set, the [`Vary` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) is overriden with the specified variable, regardless of what the backend provides.

Expand Down
1 change: 1 addition & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config :mu_identifier,
default_access_control_allow_origin_header:
System.get_env("DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_HEADER"),
default_mu_auth_allowed_groups_header: System.get_env("DEFAULT_MU_AUTH_ALLOWED_GROUPS_HEADER"),
session_cookie_max_age: System.get_env("SESSION_COOKIE_MAX_AGE"),
session_cookie_secure: CH.system_boolean("SESSION_COOKIE_SECURE", false),
session_cookie_http_only: CH.system_boolean("SESSION_COOKIE_HTTP_ONLY", true),
session_cookie_same_site: CH.calculate_same_site(),
Expand Down
9 changes: 8 additions & 1 deletion lib/proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ defmodule Proxy do
end

def opts_from_environment do
[
base_opts = [
secure: Application.get_env(:mu_identifier, :session_cookie_secure),
http_only: Application.get_env(:mu_identifier, :session_cookie_http_only),
same_site: Application.get_env(:mu_identifier, :session_cookie_same_site)
]

max_age = Application.get_env(:mu_identifier, :session_cookie_max_age)

case max_age do
nil -> base_opts
age -> base_opts ++ [max_age: String.to_integer(age)]
end
end

end