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

@ -40,35 +40,24 @@ const USER_AGENT = "NGU-LinkPreview/1.0 (+https://nextgenerationofunity.org)";
/* ── Address checks ────────────────────────────────────────── */
function ipv4Blocked(ip) {
const [a, b] = ip.split(".").map(Number);
return (
a === 0 ||
a === 10 ||
a === 127 ||
(a === 100 && b >= 64 && b <= 127) ||
(a === 169 && b === 254) ||
(a === 172 && b >= 16 && b <= 31) ||
(a === 192 && b === 168) ||
(a === 192 && b === 0) ||
(a === 198 && (b === 18 || b === 19)) ||
a >= 224
);
}
/* Private, loopback, link-local, shared, benchmark, multicast and
reserved ranges. BlockList also judges an IPv4-mapped IPv6 address
(::ffff:7f00:1, however it's written) by the IPv4 inside it. The
IPv6 ranges that embed an IPv4 some other way (NAT64, 6to4, the
old compatible form) are refused outright. */
const BLOCKED = new net.BlockList();
for (const [ip, bits] of [
["0.0.0.0", 8], ["10.0.0.0", 8], ["100.64.0.0", 10], ["127.0.0.0", 8],
["169.254.0.0", 16], ["172.16.0.0", 12], ["192.0.0.0", 24], ["192.168.0.0", 16],
["198.18.0.0", 15], ["224.0.0.0", 3],
]) BLOCKED.addSubnet(ip, bits, "ipv4");
for (const [ip, bits] of [
["::", 96], ["::1", 128], ["64:ff9b::", 96], ["64:ff9b:1::", 48], ["2002::", 16],
["fc00::", 7], ["fe80::", 10], ["ff00::", 8],
]) BLOCKED.addSubnet(ip, bits, "ipv6");
function ipBlocked(ip) {
if (net.isIPv4(ip)) return ipv4Blocked(ip);
const lower = ip.toLowerCase();
// An IPv4 address written as IPv6 is judged as the IPv4 it is.
const mapped = lower.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
if (mapped) return ipv4Blocked(mapped[1]);
return (
lower === "::" ||
lower === "::1" ||
/^f[cd]/.test(lower) || // fc00::/7 unique local
/^fe[89ab]/.test(lower) || // fe80::/10 link-local
/^ff/.test(lower) // multicast
);
return BLOCKED.check(ip, net.isIPv4(ip) ? "ipv4" : "ipv6");
}
async function vet(raw) {