Best-effort brute-force cap on the shared password, keyed by client IP.
(env: Env, request: Request)
| 142 | |
| 143 | /** Best-effort brute-force cap on the shared password, keyed by client IP. */ |
| 144 | async function loginRateLimitOk(env: Env, request: Request): Promise<boolean> { |
| 145 | // Note for auditors: unlike the ingest worker — which never reads the client |
| 146 | // IP — this admin login does, purely as a rate-limit key. It is not stored, |
| 147 | // logged or forwarded anywhere. |
| 148 | const key = request.headers.get('cf-connecting-ip') ?? 'unknown'; |
| 149 | try { |
| 150 | const { success } = await env.LOGIN_RATE_LIMITER.limit({ key }); |
| 151 | return success; |
| 152 | } catch (err) { |
| 153 | // Fail open: a rate-limiter outage must not lock the maintainer out, and |
| 154 | // the password is still required either way. |
| 155 | console.error(JSON.stringify({ msg: 'login rate limiter unavailable', err: String(err) })); |
| 156 | return true; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | async function handleLoginPage(env: Env, request: Request, url: URL): Promise<Response> { |
| 161 | const next = safeNextPath(url.searchParams.get('next')); |
no test coverage detected