feat(webui): custom CSS + config export/import/reset (phase 6)

A "高级" Settings tab adds:
- Custom CSS (appearance.customCss, <=50KB) applied post-auth only, as the
  last <style> so it overrides everything. It never reaches the login page:
  the server strips it from /api/ui/public, applyAppearance gates injection on
  a bearer token (so the localStorage cache can't leak it pre-auth), and the
  login page clears any lingering <style> on mount. `?safe-mode=1` (sticky for
  the tab session) disables custom CSS so a broken rule can't lock the
  operator out.
- Export / import the whole UI config as JSON (import is normalized
  server-side, then reload); reset-all behind a confirm dialog.

POST /api/ui and the import file are size-capped (256KB) on top of the
per-field caps. Verified across 2 adversarial review rounds — the pre-auth
cached-CSS leak/lockout vector found in round 1 is closed across the boot /
logout / 401-expiry / re-login paths.
This commit is contained in:
DrSmoothl committed 2026-06-13 21:17:23 +08:00
1 parent 3258300539
commit 7c2923dd04
7 files changed
+237 -8

No files matched your search

+6
View File
@@ -551,6 +551,12 @@ export async function initWebUI(
app.get('/api/ui/public', (c) => c.json({ appearance: publicAppearance() }));
app.post('/api/ui', async (c) => {
// Reject oversized bodies before buffering — the normalizer caps individual
// fields (customCss 50KB, per-widget config 4KB) but not the whole payload.
const declaredLen = Number(c.req.header('content-length'));
if (Number.isFinite(declaredLen) && declaredLen > 256 * 1024) {
return c.json({ success: false, message: '配置过大' }, 413);
}
let body: unknown;
try {
body = await c.req.json();