Harden security found in the audit
- Rate limits and IP hashes use the X-Forwarded-For entry nginx adds, not the client-supplied first one - Link preview and feed fetches block IPv4-mapped and other embedded IPv6 forms of private addresses (net.BlockList) - CSRF check on /api writes; security headers and HSTS on every response - Viewers no longer receive a person's private details (readRole) - Sessions end 90 days after sign-in however active - yt-dlp ignores config files and takes the link after -- - Meta tag insert no longer expands $ patterns from record text - Links with an unsafe scheme draw as text - Migration 037: leadership lists name published home orgs only - Ignore *.db-wal, *.db-shm and *.txt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
693dd84b6e
commit
4066e9ec61
11 changed files with 143 additions and 42 deletions
|
|
@ -29,6 +29,8 @@ 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.
|
||||
const REFRESH_WITHIN_DAYS = 7;
|
||||
// However active, a session ends this long after sign-in.
|
||||
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";
|
||||
|
|
@ -95,9 +97,11 @@ export function hashIp(ip) {
|
|||
}
|
||||
|
||||
export function clientIp(c) {
|
||||
// Trustworthy only because this service binds to 127.0.0.1 and
|
||||
// nginx is the only thing that can reach it.
|
||||
return c.req.header("x-forwarded-for")?.split(",")[0].trim() ?? null;
|
||||
// The last X-Forwarded-For entry is the one nginx (or Vite in dev)
|
||||
// added from the connection itself; anything before it is whatever
|
||||
// the client sent. Trustworthy only because this service binds to
|
||||
// 127.0.0.1 and nginx is the only thing that can reach it.
|
||||
return c.req.header("x-forwarded-for")?.split(",").at(-1).trim() || null;
|
||||
}
|
||||
|
||||
/* ── Sessions ────────────────────────────────────────────────── */
|
||||
|
|
@ -160,9 +164,10 @@ export function currentUser(db, c) {
|
|||
JOIN admin_users u ON u.id = s.user_id
|
||||
WHERE s.token_hash = ?
|
||||
AND s.expires_at > datetime('now')
|
||||
AND s.created_at > datetime('now', ?)
|
||||
AND u.is_active = 1`,
|
||||
)
|
||||
.get(tokenHash);
|
||||
.get(tokenHash, `-${MAX_SESSION_DAYS} days`);
|
||||
|
||||
if (!row) return null;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue