Initial commit on Forgejo
All checks were successful
CI and deploy / Test (push) Successful in 4m52s
CI and deploy / Deploy production (push) Successful in 23s

Fresh repository history for elektrine/tarakan hosted at
https://git.elektrine.com/elektrine/tarakan.
This commit is contained in:
Maxfield Luke 2026-07-29 04:43:40 -04:00
commit af6077b9c3
455 changed files with 78366 additions and 0 deletions

View file

@ -0,0 +1,30 @@
defmodule TarakanWeb.BrowserRateLimit do
@moduledoc "Central rate profiles for browser authentication and email workflows."
alias Tarakan.RateLimiter
@defaults %{
login_ip: {10, 60},
login_pair: {6, 300},
magic_ip: {5, 3_600},
magic_email: {3, 3_600},
registration_ip: {5, 3_600},
# Device-auth start is unauthenticated; keep it well below general API limits.
client_auth_start_ip: {10, 60},
# Exchange is polled every @poll_interval_seconds (2s) while awaiting approval,
# i.e. ~30/min for one client. Allow generous headroom for jitter and several
# clients sharing one NAT/CI egress IP so honest polling never trips a 429.
client_auth_exchange_ip: {120, 60},
# OAuth starts/callbacks force an upstream redirect or token exchange.
oauth_ip: {20, 60}
}
def allowed?(profile, key) when is_atom(profile) do
{limit, window_seconds} =
:tarakan
|> Application.get_env(__MODULE__, [])
|> Keyword.get(profile, Map.fetch!(@defaults, profile))
RateLimiter.check({profile, key}, limit, window_seconds) == :ok
end
end