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

@ -52,6 +52,16 @@ function entityForWrite(c) {
return entity;
}
/* An extension can ask for more than a sign-in to be read
(readRole): a person's private details need editor. Blanked on
every row sent back, so a write's reply can't leak it either. */
function visible(c, entity, row) {
for (const ext of entity.extensions ?? []) {
if (ext.readRole && !hasRole(c.get("user"), ext.readRole)) row[ext.key] = null;
}
return row;
}
/* Everything the select inputs need, in one request. Small enough
that paging it would cost more than it saves. */
entities.get("/options", (c) => {
@ -71,12 +81,12 @@ entities.get("/:entity", (c) => {
entities.get("/:entity/:id", (c) => {
const entity = entityOr404(c);
return c.json({ row: readRow(c.get("db"), entity, c.req.param("id")) }, 200, NO_STORE);
return c.json({ row: visible(c, entity, readRow(c.get("db"), entity, c.req.param("id"))) }, 200, NO_STORE);
});
entities.post("/:entity", requireRole("editor"), async (c) => {
const entity = entityForWrite(c);
const row = createRow(c.get("db"), entity, await json(c));
const row = visible(c, entity, createRow(c.get("db"), entity, await json(c)));
console.log(`${entity.key} ${row[entity.idColumn]} created by ${c.get("user").email}`);
return c.json({ row }, 201, NO_STORE);
});
@ -84,7 +94,7 @@ entities.post("/:entity", requireRole("editor"), async (c) => {
entities.patch("/:entity/:id", requireRole("editor"), async (c) => {
const entity = entityForWrite(c);
const id = c.req.param("id");
const row = updateRow(c.get("db"), entity, id, await json(c));
const row = visible(c, entity, updateRow(c.get("db"), entity, id, await json(c)));
console.log(`${entity.key} ${id} updated by ${c.get("user").email}`);
return c.json({ row }, 200, NO_STORE);
});