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:
Zaldimmar 2026-09-28 21:56:49 -05:00
parent 693dd84b6e
commit 4066e9ec61
11 changed files with 143 additions and 42 deletions

View file

@ -13,7 +13,9 @@ import { mkdir } from "node:fs/promises";
import { serve } from "@hono/node-server";
import { serveStatic } from "@hono/node-server/serve-static";
import { Hono } from "hono";
import { csrf } from "hono/csrf";
import { logger } from "hono/logger";
import { secureHeaders } from "hono/secure-headers";
import { openDatabase, migrate } from "./db.js";
import { rateLimit } from "./rateLimit.js";
@ -57,6 +59,39 @@ const app = new Hono();
app.use("*", logger());
/* Headers for every response. Referrer kept to the origin (YouTube
embeds refuse to play without one); HSTS without includeSubDomains
so a plain-http dev subdomain keeps working. No CSP yet: pages carry
an inline window.__NGU_SITE__ script and YouTube, Facebook and Maps
iframes, so one needs trying in Report-Only first. */
app.use(
"*",
secureHeaders({
referrerPolicy: "strict-origin-when-cross-origin",
strictTransportSecurity: "max-age=31536000",
}),
);
/* Refuse a form-style write (text/plain, form or multipart body)
that another site sent, including a sibling subdomain, which
SameSite=Lax cookies don't stop. Browsers mark their own requests
Sec-Fetch-Site: same-origin; older ones fall back to Origin, judged
by host because nginx speaks plain http to this service. JSON
bodies can't be sent cross-origin without a CORS preflight, which
this API never answers. */
app.use(
"/api/*",
csrf({
origin: (origin, c) => {
try {
return new URL(origin).host === c.req.header("host");
} catch {
return false;
}
},
}),
);
app.use("*", async (c, next) => {
c.set("db", db);
await next();