Repository navigation
feat: upload panel logo and banner in the dashboard - #48
Merged
Merged
Conversation
…harp and scanned by ClamAV
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,slotislogoorbanner):config.edit, one upload at a time (else 429), the existing write limiter, origin and CSRF checks.express.rawon this route only,application/octet-stream, limitASSET_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.<svg>root and none of script, foreignObject, event handlers,javascript:, entities/DTD, XInclude,@import,url()or anyhref/srcthat is not a local#id.CLAMAV_SOCKETorCLAMAV_HOST/CLAMAV_PORT): the raw bytes go to clamd viazINSTREAM(own client onnet, 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.limitInputPixels30 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.assets/custom-<slot>-<hash>.<ext>,panel.<slot>.fileinconfig.jsoncis set (comments kept,.bakfirst), older uploads of the same slot are removed, auditpanel.asset.upload.The preview route only serves raster images with the Content-Type from the bytes,
nosniffandno-store.DELETEresets the slot to the default (auditpanel.asset.reset). The bot picks up a new image after its next restart, like any config change.New production dependency:
sharp0.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-streamupload 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
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). Newtests/panel-asset-upload.test.jswith 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
MSK_API_KEYnpm start) and I verified my change on a test serverdocs/in both languages,.env.example)CHANGELOG.mdentry under[Unreleased]