Fix bugs found in the audit

- People tiles resolve a bare photo filename to /uploads, via personPhoto
- api.ts keeps the Accept header when a request sets its own headers
- Feedback hashes IPs with auth.js's salt and client IP helper
- Drop the better-sqlite3 fallback (not installed); require Node 22.13+

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 21:53:46 -05:00
parent 9d8de0176e
commit 693dd84b6e
6 changed files with 15 additions and 56 deletions

View file

@ -10,13 +10,12 @@
length caps rejected before anything touches the database
no HTML stored verbatim, escaped at render time
The write is a single INSERT with positional parameters, so it
works on node:sqlite and better-sqlite3 alike. No transaction:
one statement is already atomic.
The write is a single INSERT. No transaction: one statement is
already atomic.
═══════════════════════════════════════════════════════════════ */
import { Hono } from "hono";
import { createHash, randomBytes } from "node:crypto";
import { clientIp, hashIp } from "../auth.js";
const feedback = new Hono();
@ -35,25 +34,6 @@ const MIN_MESSAGE = 10;
// a renamed option shouldn't lose someone's submission.
const TYPES = ["broken", "confusing", "outdated", "request", "praise", "other"];
/* ── IP hashing ────────────────────────────────────────────────
Stored so repeat abuse from one source is visible during
triage, hashed so the table never holds an address. Without
IP_SALT the salt is regenerated each boot, which makes hashes
incomparable across restarts — fine for dev, set it in
/etc/ngu/api.env for production.
───────────────────────────────────────────────────────────── */
const IP_SALT = process.env.IP_SALT ?? randomBytes(16).toString("hex");
if (!process.env.IP_SALT) {
console.warn("IP_SALT unset — feedback ip_hash values reset on restart");
}
function hashIp(ip) {
if (!ip) return null;
return createHash("sha256").update(`${IP_SALT}:${ip}`).digest("hex").slice(0, 32);
}
/* ── Input cleaning ──────────────────────────────────────────── */
function clean(value, max) {
@ -118,7 +98,7 @@ feedback.post("/", async (c) => {
pagePath || null,
sectionId || null,
clean(c.req.header("user-agent"), 500) || null,
hashIp(c.req.header("x-forwarded-for")?.split(",")[0].trim()),
hashIp(clientIp(c)),
);
// created_at and status come from column defaults.