Fix the Panel account bug and harden what the second audit found

- Panel: changing a role or disabling an account always failed
  (db.transaction doesn't exist on node:sqlite); it uses tx() now
- Feeds and link previews are scanned with indexOf, not whole-document
  regexes, so a hostile feed or page can't freeze the server; entity
  decoding can't throw; escaped-HTML descriptions make clean excerpts
- Feed reads share one fetch per feed and serve the stale copy while
  a refresh runs
- Deliberate HTTP errors (the CSRF 403) keep their status instead of
  becoming logged 500s; a JSON null body is handled
- url columns read the scheme the way the URL parser does, so
  control characters can't hide javascript:
- Google sign-in state cookie is __Host- and its return page is
  checked again; more reserved ranges blocked for previews and feeds,
  and a 15 s cap on each whole fetch
- Log lines from visitor text are made single-line and short; list
  limits can't go negative; entity names can't hit object prototypes
- A clip title can't point the clip tool at another file
- Uploads over 60 MP are refused before decoding; the Keep original
  help says a photo's location stays in it
- admin-cli add defaults to the editor role

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 02:34:26 -05:00
parent fd40907ed6
commit be7e92417e
18 changed files with 226 additions and 59 deletions

View file

@ -13,6 +13,7 @@ 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 { HTTPException } from "hono/http-exception";
import { csrf } from "hono/csrf";
import { logger } from "hono/logger";
import { secureHeaders } from "hono/secure-headers";
@ -35,7 +36,7 @@ import media from "./routes/media.js";
import clips from "./routes/clips.js";
import { CLIPS_DIR, startClipWorker } from "./clips.js";
import { UPLOADS_DIR } from "./media.js";
import { startSessionSweeper } from "./auth.js";
import { logSafe, startSessionSweeper } from "./auth.js";
import { syncDescriptorsWithSchema } from "./admin-schema-sync.js";
import { ENTITIES } from "./admin-schema.js";
@ -111,8 +112,9 @@ app.post("/api/csp-report", async (c) => {
const text = (await c.req.text()).slice(0, 4000);
try {
const report = JSON.parse(text)["csp-report"] ?? {};
const field = (name) => logSafe(report[name] ?? "?", 150);
console.warn(
`csp ${report["violated-directive"] ?? "?"} blocked ${report["blocked-uri"] ?? "?"} on ${report["document-uri"] ?? "?"}`,
`csp ${field("violated-directive")} blocked ${field("blocked-uri")} on ${field("document-uri")}`,
);
} catch {
// Not a report; nothing to log.
@ -203,6 +205,9 @@ console.log(`clips ${CLIPS_DIR}`);
app.notFound((c) => c.json({ error: "Not found" }, 404));
app.onError((err, c) => {
// A deliberate refusal (the CSRF check's 403, say) is an answer,
// not a crash: send it as it is and keep it out of the error log.
if (err instanceof HTTPException) return err.getResponse();
console.error(err);
// Never leak internals to the browser.
return c.json({ error: "Something went wrong." }, 500);