Skip to content

feat: upload panel logo and banner in the dashboard - #48

Merged
Musiker15 merged 3 commits into
mainfrom
feat/asset-upload
Nov 5, 2026
Merged

Musiker15 merged 3 commits into
mainfrom
feat/asset-upload

Conversation

@Musiker15

Copy link
Copy Markdown
Member

Description

Hosted customers have no server access, so they could not use their own panel logo or banner. The dashboard can now upload both, show a preview and reset to the default.

Pipeline per upload (POST /api/panel-assets/:slot, slot is logo or banner):

  1. config.edit, one upload at a time (else 429), the existing write limiter, origin and CSRF checks.
  2. express.raw on this route only, application/octet-stream, limit ASSET_UPLOAD_MAX_MB (default 5, 1 to 10; the msk-shop proxy buffers at most 10 MiB). 413 when too large, 415 for another content type. The global 64 KB body limit is unchanged.
  3. Type from the content only: PNG, JPEG, GIF, WebP by magic bytes; SVG only as strict UTF-8 with an <svg> root and none of script, foreignObject, event handlers, javascript:, entities/DTD, XInclude, @import, url() or any href/src that is not a local #id.
  4. ClamAV when configured (CLAMAV_SOCKET or CLAMAV_HOST/CLAMAV_PORT): the raw bytes go to clamd via zINSTREAM (own client on net, no dependency). FOUND gives 422 and an audit entry; unreachable, timeout or ERROR gives 503 (fail closed). Without ClamAV the startup log says once that uploads are not virus scanned.
  5. sharp re-encodes everything: limitInputPixels 30 MP, failOn: 'error', auto orient, resize down only (logo 1024, banner 2048). PNG stays PNG, JPEG stays JPEG, WebP stays WebP, animated GIF stays animated, static GIF and SVG become PNG. SVG is never stored. All metadata (EXIF, GPS, XMP, ICC) is gone after the re-encode.
  6. The file is written atomically as assets/custom-<slot>-<hash>.<ext>, panel.<slot>.file in config.jsonc is set (comments kept, .bak first), older uploads of the same slot are removed, audit panel.asset.upload.

The preview route only serves raster images with the Content-Type from the bytes, nosniff and no-store. DELETE resets the slot to the default (audit panel.asset.reset). The bot picks up a new image after its next restart, like any config change.

New production dependency: sharp 0.35.5 (approved by the owner). It is loaded lazily; if it is missing the upload answers 503 instead of crashing the dashboard. Prebuilt binaries for linux-x64 and linux-arm64 come from the lockfile, the Dockerfile needs no change.

The msk-shop proxy passes a 5 MB application/octet-stream upload through unchanged (no method or content-type allowlist; Next's proxy body limit is 10 MiB), so msk-shop needs no change.

Related Issue

None.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 🌍 Translation / locale update
  • 📖 Documentation only
  • 🔧 Refactor / chore (no functional change)

How Was This Tested?

npm test: 453 passed, 1 skipped (the UNIX socket test is skipped on Windows; it passed in a node:24-bookworm-slim container). New tests/panel-asset-upload.test.js with 28 tests: every allowed type, renamed non-images, 13 hostile SVGs, a GIF polyglot with an appended script (comes out as a clean PNG), metadata stripped after re-encode, decompression bomb, animation kept, the clamd client against a fake server (OK incl. chunk framing, FOUND, ERROR, unreachable, timeout, UNIX socket), size limit, JSONC patch, path traversal, and the routes (permissions, audit, config patch, replacing old uploads, reset, FOUND, scanner down, preview never SVG, fatal config gives 409 without leftovers). Counter-checks: type detection forced to png, metadata kept, FOUND ignored in the route and in the client each turned tests red, then restored.

Not tried in a browser yet (needs a Discord login).

Checklist

  • My code follows the project's conventions
  • No new production dependencies were added (sharp, approved)
  • User-facing strings go through the dashboard locale files (all seven)
  • Any DB schema change uses an inline migration (no schema change)
  • The bot still works without MSK_API_KEY
  • The bot starts cleanly (npm start) and I verified my change on a test server
  • I updated the relevant docs (docs/ in both languages, .env.example)
  • I added a CHANGELOG.md entry under [Unreleased]
  • My commit messages are in English and follow Conventional Commits

Comment thread src/dashboard/clamav.js Fixed
Comment thread src/dashboard/imageSanitizer.js Fixed
Comment thread src/dashboard/panelAssets.js Fixed
Comment thread src/dashboard/panelAssets.js Fixed
Comment thread src/dashboard/panelAssets.js Fixed
Comment thread src/dashboard/panelAssets.js Fixed
Comment thread src/dashboard/panelAssets.js Fixed
…ogged values, read previews through one handle
}
if (!verdict.clean) {
audit(req, 'panel.asset.infected', spec.slot, { signature: verdict.signature, type, bytes: input.length });
logger.warn(`[Dashboard] Upload refused, ClamAV found ${logSafe(verdict.signature)} (slot ${spec.slot}, user ${logSafe(req.auth?.userId)}).`);
…anner error in the log, LF for shell scripts
@Musiker15
Musiker15 merged commit 978485a into main Nov 5, 2026
6 checks passed
@Musiker15
Musiker15 deleted the feat/asset-upload branch November 5, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants