Harden sign-in: __Host- session cookie and a per-email login lock
- The session cookie is __Host-ngu_session when Secure (production), so a sibling subdomain can't set or overwrite it; plain ngu_session over local http. Every admin signs in again once after deploying. - Five wrong passwords for one email lock that email for 15 minutes, from any address; a correct password clears it. On top of the per-IP limit. - CLAUDE.md: noImplicitAny stays off on purpose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d1a6332a45
commit
b165e612c2
5 changed files with 83 additions and 5 deletions
|
|
@ -23,8 +23,6 @@ import {
|
|||
} from "node:crypto";
|
||||
import { getCookie, setCookie, deleteCookie } from "hono/cookie";
|
||||
|
||||
export const COOKIE_NAME = "ngu_session";
|
||||
|
||||
const SESSION_DAYS = 30;
|
||||
// Re-issue the expiry when a session is used with less than this
|
||||
// left, so an active person is never signed out mid-task.
|
||||
|
|
@ -35,6 +33,12 @@ const MAX_SESSION_DAYS = 90;
|
|||
// Off only for plain-http local work. Production is behind TLS.
|
||||
export const SECURE_COOKIE = (process.env.COOKIE_SECURE ?? "true") !== "false";
|
||||
|
||||
// __Host- makes the browser refuse the cookie unless it's Secure, on
|
||||
// path /, with no Domain, so a sibling subdomain can't plant or
|
||||
// overwrite it. Plain http (local work, COOKIE_SECURE=false) can't
|
||||
// use the prefix, so it keeps the plain name.
|
||||
export const COOKIE_NAME = SECURE_COOKIE ? "__Host-ngu_session" : "ngu_session";
|
||||
|
||||
const IP_SALT = process.env.IP_SALT ?? randomBytes(16).toString("hex");
|
||||
|
||||
/* ── Passwords ─────────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue