From 879b40fe93d5cbe3f49962ae5ef23aac0d86a1ae Mon Sep 17 00:00:00 2001 From: dtzp555-max Date: Sun, 31 May 2026 23:03:50 +1000 Subject: [PATCH] fix: escape dashboard DB-sourced values + validate key names (#114) (#121) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dashboard built table rows via template-literal innerHTML, interpolating DB-sourced strings (key names, usage rows) with no HTML escaping, and an onclick="revokeKeyUI('${k.name}')" sink a single quote could break out of. Key names were unvalidated at creation. Admin-gated (self-XSS today), but a real unescaped-sink gap that becomes cross-user if key creation is ever delegated. - dashboard.html: added escapeHtml() and applied it to every DB/string-sourced interpolation in refreshUsage and refreshKeys (key_name, name, keyPreview, created_at, last_request, model). Replaced the inline-onclick revoke button with a data-revoke attribute + addEventListener, so a name can never break out into an event-handler string. (model is attacker-pickable via the request body, so its escaping is the load-bearing one.) - server.mjs: POST /api/keys now rejects names not matching /^[A-Za-z0-9 ._-]{1,64}$/ before createKey() — defense-in-depth so a