Owner bearer token and browser session cookie manager backed by a :protected
ETS table and <data_dir>/auth.token (0600).
Provides constant-time token/cookie verification via Plug.Crypto.secure_compare/2
and strict Host / Origin checks against DNS rebinding and CSRF.
Summary
Functions
Validates the HTTP Host header against the listener's literal :bind_address
(defaults to loopback literals when omitted). Pass allow_localhost: true
to also accept localhost:<port>.
Validates the HTTP Origin as an HTTP URL using the same host policy as allowed_host?/3.
Returns a specification to start this module under a supervisor.
Verifies owner_token_candidate in constant time and, if valid, mints a fresh
32-byte browser session cookie stored in ETS.
Returns the current owner token from ETS.
Starts the auth manager.
Constant-time comparison of candidate against the stored owner token.
Constant-time comparison of cookie_candidate against active browser session cookies.
Functions
@spec allowed_host?(term(), pos_integer(), keyword()) :: boolean()
Validates the HTTP Host header against the listener's literal :bind_address
(defaults to loopback literals when omitted). Pass allow_localhost: true
to also accept localhost:<port>.
@spec allowed_origin?(term(), pos_integer(), keyword()) :: boolean()
Validates the HTTP Origin as an HTTP URL using the same host policy as allowed_host?/3.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec create_browser_session(term(), GenServer.server(), atom()) :: {:ok, String.t()} | {:error, :unauthorized}
Verifies owner_token_candidate in constant time and, if valid, mints a fresh
32-byte browser session cookie stored in ETS.
Returns the current owner token from ETS.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the auth manager.
Options:
:data_dir(required) - root storage directory holdingauth.token:name- GenServer registration name (defaultH.Auth, passnilfor unnamed):table- ETS table name (default:h_auth)
Constant-time comparison of candidate against the stored owner token.
Constant-time comparison of cookie_candidate against active browser session cookies.