Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
+269
-116
@@ -6,6 +6,7 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const crypto = require("crypto");
|
||||
const { validateSvgBuffer, sanitizeSvg } = require("./svg-sanitizer");
|
||||
|
||||
const BRANDING_CONFIG_PATH = path.join(__dirname, "..", "data", "branding.json");
|
||||
|
||||
@@ -19,8 +20,6 @@ const DEFAULT_BRANDING = {
|
||||
appName: "ADPanel",
|
||||
logoUrl: null,
|
||||
localLogoPath: null,
|
||||
loginWatermarkUrl: "https://stalwart-pegasus-2c2ca4.netlify.app/watermark.webp",
|
||||
localLoginWatermarkPath: null,
|
||||
loginBackgroundType: "video",
|
||||
loginBackgroundExternalUrl: null,
|
||||
localLoginBackgroundPath: null,
|
||||
@@ -28,10 +27,46 @@ const DEFAULT_BRANDING = {
|
||||
};
|
||||
|
||||
|
||||
const ALLOWED_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "ico", "svg"];
|
||||
// Allowed extensions for login background (raster/video only; SVG rejected for backgrounds).
|
||||
const ALLOWED_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "ico", "avif", "gif"];
|
||||
// Allowed extensions for brand logo (SVG is supported with strict security sanitization & CSP sandboxing).
|
||||
const ALLOWED_LOGO_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "ico", "avif", "gif", "svg"];
|
||||
const ALLOWED_VIDEO_EXTENSIONS = ["webm", "mp4", "ogg", "ogv"];
|
||||
const GENERATED_LOGO_FILENAME_RE = /^logo-[0-9a-f]{16}\.[a-z0-9]+$/;
|
||||
const GENERATED_LOGIN_BG_FILENAME_RE = /^login-background-(remote-)?[0-9a-f]{16}\.[a-z0-9]+$/;
|
||||
const DEFAULT_LOGIN_BACKGROUND_URL = "/images/bgvid.webm";
|
||||
// Default brand logo shown everywhere until an admin uploads/sets a custom
|
||||
// one. Served from the panel's own public/ assets: the historical value was a
|
||||
// pinned cdn.jsdelivr.net URL, which made every login page an availability
|
||||
// dependent on — and a trust decision in — a third-party CDN repo. The local
|
||||
// file is the same asset that URL mirrored.
|
||||
const DEFAULT_LOGO_URL = "/images/adpanel-dark.svg";
|
||||
const PUBLIC_IMAGES_DIR = path.join(__dirname, "..", "public", "images");
|
||||
const BUNDLED_MEDIA_ALIASES = new Map([
|
||||
["https://logos-world.net/wp-content/uploads/2021/03/FiveM-Symbol.png", "fivem.avif"],
|
||||
["https://cdn.cloudflare.steamstatic.com/steam/apps/730/header.jpg", "cs2.avif"],
|
||||
]);
|
||||
|
||||
function resolveBundledMediaFilename(value) {
|
||||
if (typeof value !== "string") return null;
|
||||
const url = value.trim();
|
||||
const filename = BUNDLED_MEDIA_ALIASES.get(url)
|
||||
|| /^(?:\/images\/|https?:\/\/cdn\.jsdelivr\.net\/gh\/antonndev\/adcdn(?:@[\w.-]+)?\/)([\w.-]{1,255})(?:[?#][^\r\n]*)?$/i.exec(url)?.[1];
|
||||
if (!filename || filename.startsWith(".") || !(getValidatedLogoExtension(filename) || getValidatedVideoExtension(filename))) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return fs.lstatSync(path.join(PUBLIC_IMAGES_DIR, filename), { throwIfNoEntry: false })?.isFile() ? filename : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function preferBundledMediaUrl(value) {
|
||||
if (typeof value !== "string" || value.trimStart().startsWith("/")) return value;
|
||||
const filename = resolveBundledMediaFilename(value);
|
||||
return filename ? `/images/${filename}` : value;
|
||||
}
|
||||
|
||||
|
||||
const IMAGE_MAGIC_BYTES = {
|
||||
@@ -40,7 +75,8 @@ const IMAGE_MAGIC_BYTES = {
|
||||
jpeg: [0xFF, 0xD8, 0xFF],
|
||||
webp: [0x52, 0x49, 0x46, 0x46],
|
||||
ico: [0x00, 0x00, 0x01, 0x00],
|
||||
svg: null
|
||||
gif: [0x47, 0x49, 0x46, 0x38], // "GIF8"
|
||||
avif: null // detected separately (ISO-BMFF "ftyp" box, brand "avif"/"avis")
|
||||
};
|
||||
|
||||
const VIDEO_MIME_TYPES = {
|
||||
@@ -72,16 +108,6 @@ function resolveLocalBrandingAssetUrl(filename, branding) {
|
||||
return `/images/${safe}${getBrandingAssetVersionSuffix(branding)}`;
|
||||
}
|
||||
|
||||
function resolveLoginWatermarkAssetUrl(branding) {
|
||||
const config = branding && typeof branding === "object" ? branding : loadBrandingConfig();
|
||||
const localUrl = resolveLocalBrandingAssetUrl(config.localLoginWatermarkPath, config);
|
||||
if (localUrl) return localUrl;
|
||||
if (config.loginWatermarkUrl) {
|
||||
return `/branding-media/login-watermark${getBrandingAssetVersionSuffix(config)}`;
|
||||
}
|
||||
return DEFAULT_BRANDING.loginWatermarkUrl;
|
||||
}
|
||||
|
||||
function resolveLoginBackgroundAssetUrl(branding) {
|
||||
const config = branding && typeof branding === "object" ? branding : loadBrandingConfig();
|
||||
const localUrl = resolveLocalBrandingAssetUrl(config.localLoginBackgroundPath, config);
|
||||
@@ -94,7 +120,39 @@ function resolveLoginBackgroundAssetUrl(branding) {
|
||||
|
||||
function resolveFaviconAssetUrl(branding) {
|
||||
const config = branding && typeof branding === "object" ? branding : loadBrandingConfig();
|
||||
return `/auth-assets/favicon${getBrandingAssetVersionSuffix(config)}`;
|
||||
const safeLogo = safeBasename(config.localLogoPath);
|
||||
if (safeLogo && fs.existsSync(path.join(PUBLIC_IMAGES_DIR, safeLogo))) {
|
||||
return `/images/${safeLogo}${getBrandingAssetVersionSuffix(config)}`;
|
||||
}
|
||||
const remoteLogoUrl = String(config.logoUrl || "").trim();
|
||||
if (remoteLogoUrl) {
|
||||
return remoteLogoUrl;
|
||||
}
|
||||
return DEFAULT_LOGO_URL;
|
||||
}
|
||||
|
||||
// Resolve the favicon MIME type so the <link rel="icon" type="..."> attribute
|
||||
// matches the actual asset extension. This mirrors the resolution order used by
|
||||
// the /auth-assets/favicon route (local logo -> remote logo URL -> built-in default).
|
||||
function resolveFaviconMimeType(branding) {
|
||||
const config = branding && typeof branding === "object" ? branding : loadBrandingConfig();
|
||||
|
||||
// 1. Custom uploaded logo (stored locally) — derive type from its extension.
|
||||
const localLogo = safeBasename(config.localLogoPath);
|
||||
if (localLogo) {
|
||||
const ext = getValidatedLogoExtension(localLogo);
|
||||
if (ext) return getMimeTypeForExtension(ext) || "image/webp";
|
||||
}
|
||||
|
||||
// 2. Custom remote logo URL — derive type from its extension.
|
||||
const remoteLogoUrl = String(config.logoUrl || "").trim();
|
||||
if (remoteLogoUrl) {
|
||||
const ext = getLogoExtensionFromUrl(remoteLogoUrl);
|
||||
if (ext) return getMimeTypeForExtension(ext) || "image/webp";
|
||||
}
|
||||
|
||||
// 3. Built-in favicon referenced by the page (adpanel-dark.svg).
|
||||
return "image/svg+xml";
|
||||
}
|
||||
|
||||
|
||||
@@ -113,12 +171,27 @@ function loadBrandingConfig() {
|
||||
if (fs.existsSync(BRANDING_CONFIG_PATH)) {
|
||||
const data = fs.readFileSync(BRANDING_CONFIG_PATH, "utf8");
|
||||
const config = JSON.parse(data);
|
||||
|
||||
|
||||
brandingCache = {
|
||||
|
||||
// The login watermark feature was removed; never resurrect legacy keys
|
||||
// from an old config (they would otherwise be re-persisted on save).
|
||||
delete config.loginWatermarkUrl;
|
||||
delete config.localLoginWatermarkPath;
|
||||
|
||||
|
||||
// adpanel:branding-load-sanitization — the save route sanitizes, but
|
||||
// data/branding.json is operator-editable at rest (hand-edited or
|
||||
// co-opted): load must not trust what save validated once. Re-run the
|
||||
// module's OWN sanitizers (the exact ones the save route applies — no
|
||||
// fork, no second copy of the rules) so a hand-edited javascript:,
|
||||
// protocol-relative or private-host URL cannot reach the auth pages —
|
||||
// whose CSP derives img-src from the branding logo origin — and an
|
||||
// oversized/control-char appName is cut down to the save path's
|
||||
// alphabet. Anything a sanitizer rejects falls back exactly as a
|
||||
// rejected save would (middleware defaults, not a crash).
|
||||
brandingCache = sanitizeLoadedBrandingConfig({
|
||||
...DEFAULT_BRANDING,
|
||||
...config
|
||||
};
|
||||
});
|
||||
brandingCacheTime = now;
|
||||
return brandingCache;
|
||||
}
|
||||
@@ -184,63 +257,83 @@ function generateSafeLogoFilename(extension) {
|
||||
|
||||
|
||||
|
||||
function validateBase64Image(base64Data) {
|
||||
function validateImageBuffer(buffer, options = {}) {
|
||||
const allowSvg = Boolean(options && options.allowSvg);
|
||||
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
return { valid: false, error: "Invalid image data" };
|
||||
}
|
||||
|
||||
if (buffer.length < 8) {
|
||||
return { valid: false, error: "Image data too small" };
|
||||
}
|
||||
|
||||
if (buffer.length > 5 * 1024 * 1024) {
|
||||
return { valid: false, error: "Image too large (max 5MB)" };
|
||||
}
|
||||
|
||||
// SVG support for logo source with enterprise-grade sanitization
|
||||
if (allowSvg) {
|
||||
const head = buffer.slice(0, Math.min(512, buffer.length)).toString("utf8").trim().toLowerCase();
|
||||
if (head.startsWith("<svg") || head.startsWith("<?xml") || head.includes("<svg")) {
|
||||
const svgResult = validateSvgBuffer(buffer);
|
||||
if (svgResult.valid) {
|
||||
return { valid: true, data: svgResult.data, ext: "svg" };
|
||||
} else {
|
||||
return { valid: false, error: svgResult.error || "Invalid or malicious SVG file" };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let validType = false;
|
||||
for (const magic of Object.values(IMAGE_MAGIC_BYTES)) {
|
||||
if (magic === null) continue;
|
||||
|
||||
let matches = true;
|
||||
for (let i = 0; i < magic.length; i++) {
|
||||
if (buffer[i] !== magic[i]) {
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (matches) {
|
||||
validType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validType && buffer.length >= 12) {
|
||||
// AVIF (and other ISO-BMFF based images) start with a "ftyp" box at
|
||||
// offset 4 followed by a brand. Accept AVIF still images.
|
||||
const isFtyp = buffer[4] === 0x66 && buffer[5] === 0x74 && buffer[6] === 0x79 && buffer[7] === 0x70;
|
||||
if (isFtyp) {
|
||||
const brand = buffer.toString("ascii", 8, 12).toLowerCase();
|
||||
const compat = buffer.toString("ascii", 8, Math.min(64, buffer.length)).toLowerCase();
|
||||
if (brand === "avif" || brand === "avis" || compat.includes("avif") || compat.includes("avis")) {
|
||||
validType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!validType) {
|
||||
return { valid: false, error: "Unrecognized image format. SVG is only allowed for logo source." };
|
||||
}
|
||||
|
||||
return { valid: true, data: buffer };
|
||||
}
|
||||
|
||||
function validateBase64Image(base64Data, options = {}) {
|
||||
try {
|
||||
|
||||
if (typeof base64Data !== "string") {
|
||||
return { valid: false, error: "Failed to decode image data" };
|
||||
}
|
||||
|
||||
let cleanBase64 = base64Data;
|
||||
if (base64Data.includes(",")) {
|
||||
cleanBase64 = base64Data.split(",")[1];
|
||||
}
|
||||
|
||||
|
||||
const buffer = Buffer.from(cleanBase64, "base64");
|
||||
|
||||
|
||||
if (buffer.length < 8) {
|
||||
return { valid: false, error: "Image data too small" };
|
||||
}
|
||||
|
||||
|
||||
if (buffer.length > 5 * 1024 * 1024) {
|
||||
return { valid: false, error: "Image too large (max 5MB)" };
|
||||
}
|
||||
|
||||
|
||||
let validType = false;
|
||||
for (const [type, magic] of Object.entries(IMAGE_MAGIC_BYTES)) {
|
||||
if (magic === null) continue;
|
||||
|
||||
let matches = true;
|
||||
for (let i = 0; i < magic.length; i++) {
|
||||
if (buffer[i] !== magic[i]) {
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (matches) {
|
||||
validType = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!validType) {
|
||||
const text = buffer.toString("utf8", 0, Math.min(100, buffer.length)).toLowerCase();
|
||||
if (text.includes("<svg") || text.includes("<?xml")) {
|
||||
|
||||
const fullText = buffer.toString("utf8").toLowerCase();
|
||||
if (fullText.includes("<script") || fullText.includes("javascript:") || /\bon[a-z]+\s*=/.test(fullText)) {
|
||||
return { valid: false, error: "SVG contains potentially dangerous content" };
|
||||
}
|
||||
validType = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validType) {
|
||||
return { valid: false, error: "Unrecognized image format" };
|
||||
}
|
||||
|
||||
return { valid: true, data: buffer };
|
||||
|
||||
return validateImageBuffer(Buffer.from(cleanBase64, "base64"), options);
|
||||
} catch (err) {
|
||||
return { valid: false, error: "Failed to decode image data" };
|
||||
}
|
||||
@@ -251,26 +344,31 @@ function validateBase64Image(base64Data) {
|
||||
|
||||
|
||||
|
||||
function getValidatedExtension(filename) {
|
||||
function getValidatedExtension(filename, options = {}) {
|
||||
if (!filename || typeof filename !== "string") {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const parts = filename.toLowerCase().split(".");
|
||||
if (parts.length < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ext = parts[parts.length - 1].replace(/[^a-z0-9]/g, "");
|
||||
const allowSvg = Boolean(options && options.allowSvg);
|
||||
const allowed = allowSvg ? ALLOWED_LOGO_EXTENSIONS : ALLOWED_EXTENSIONS;
|
||||
|
||||
if (ALLOWED_EXTENSIONS.includes(ext)) {
|
||||
if (allowed.includes(ext)) {
|
||||
return ext;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getValidatedLogoExtension(filename) {
|
||||
return getValidatedExtension(filename, { allowSvg: true });
|
||||
}
|
||||
|
||||
function getValidatedVideoExtension(filename) {
|
||||
if (!filename || typeof filename !== "string") {
|
||||
return null;
|
||||
@@ -298,6 +396,8 @@ function getMimeTypeForExtension(extension) {
|
||||
if (normalized === "png") return "image/png";
|
||||
if (normalized === "jpg" || normalized === "jpeg") return "image/jpeg";
|
||||
if (normalized === "webp") return "image/webp";
|
||||
if (normalized === "avif") return "image/avif";
|
||||
if (normalized === "gif") return "image/gif";
|
||||
if (normalized === "ico") return "image/x-icon";
|
||||
if (normalized === "svg") return "image/svg+xml";
|
||||
return VIDEO_MIME_TYPES[normalized] || null;
|
||||
@@ -328,7 +428,7 @@ function getMediaTypeFromUrl(url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getExtensionFromUrl(url) {
|
||||
function getExtensionFromUrl(url, options = {}) {
|
||||
if (!url || typeof url !== "string") {
|
||||
return null;
|
||||
}
|
||||
@@ -338,7 +438,9 @@ function getExtensionFromUrl(url) {
|
||||
const pathname = (parsed.pathname || "").toLowerCase();
|
||||
if (!pathname.includes(".")) return null;
|
||||
const ext = pathname.slice(pathname.lastIndexOf(".") + 1).replace(/[^a-z0-9]/g, "");
|
||||
if (ALLOWED_EXTENSIONS.includes(ext) || ALLOWED_VIDEO_EXTENSIONS.includes(ext)) {
|
||||
const allowSvg = Boolean(options && options.allowSvg);
|
||||
const allowed = allowSvg ? ALLOWED_LOGO_EXTENSIONS : ALLOWED_EXTENSIONS;
|
||||
if (allowed.includes(ext) || ALLOWED_VIDEO_EXTENSIONS.includes(ext)) {
|
||||
return ext;
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -348,46 +450,61 @@ function getExtensionFromUrl(url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getLogoExtensionFromUrl(url) {
|
||||
return getExtensionFromUrl(url, { allowSvg: true });
|
||||
}
|
||||
|
||||
function validateVideoBuffer(buffer, expectedExt, declaredMime = "") {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
return { valid: false, error: "Invalid video data" };
|
||||
}
|
||||
|
||||
if (buffer.length < 32) {
|
||||
return { valid: false, error: "Video data too small" };
|
||||
}
|
||||
if (buffer.length > 40 * 1024 * 1024) {
|
||||
return { valid: false, error: "Video too large (max 40MB)" };
|
||||
}
|
||||
|
||||
const ext = String(expectedExt || "").toLowerCase();
|
||||
let valid = false;
|
||||
|
||||
if (ext === "webm") {
|
||||
valid = buffer[0] === 0x1a && buffer[1] === 0x45 && buffer[2] === 0xdf && buffer[3] === 0xa3;
|
||||
} else if (ext === "mp4") {
|
||||
valid = buffer.slice(4, 8).toString("ascii") === "ftyp";
|
||||
} else if (ext === "ogg" || ext === "ogv") {
|
||||
valid = buffer.slice(0, 4).toString("ascii") === "OggS";
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
return { valid: false, error: "Unrecognized video format" };
|
||||
}
|
||||
|
||||
if (declaredMime && !declaredMime.startsWith("video/")) {
|
||||
return { valid: false, error: "Invalid video MIME type" };
|
||||
}
|
||||
|
||||
return { valid: true, data: buffer };
|
||||
}
|
||||
|
||||
function validateBase64Video(base64Data, expectedExt) {
|
||||
try {
|
||||
if (typeof base64Data !== "string") {
|
||||
return { valid: false, error: "Failed to decode video data" };
|
||||
}
|
||||
|
||||
let cleanBase64 = base64Data;
|
||||
let declaredMime = "";
|
||||
if (typeof base64Data === "string" && base64Data.startsWith("data:")) {
|
||||
if (base64Data.startsWith("data:")) {
|
||||
const match = base64Data.match(/^data:([^;,]+)[;,]/i);
|
||||
declaredMime = match ? String(match[1] || "").toLowerCase() : "";
|
||||
}
|
||||
if (typeof base64Data === "string" && base64Data.includes(",")) {
|
||||
if (base64Data.includes(",")) {
|
||||
cleanBase64 = base64Data.split(",")[1];
|
||||
}
|
||||
|
||||
const buffer = Buffer.from(cleanBase64, "base64");
|
||||
if (buffer.length < 32) {
|
||||
return { valid: false, error: "Video data too small" };
|
||||
}
|
||||
if (buffer.length > 40 * 1024 * 1024) {
|
||||
return { valid: false, error: "Video too large (max 40MB)" };
|
||||
}
|
||||
|
||||
const ext = String(expectedExt || "").toLowerCase();
|
||||
let valid = false;
|
||||
|
||||
if (ext === "webm") {
|
||||
valid = buffer[0] === 0x1a && buffer[1] === 0x45 && buffer[2] === 0xdf && buffer[3] === 0xa3;
|
||||
} else if (ext === "mp4") {
|
||||
valid = buffer.slice(4, 8).toString("ascii") === "ftyp";
|
||||
} else if (ext === "ogg" || ext === "ogv") {
|
||||
valid = buffer.slice(0, 4).toString("ascii") === "OggS";
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
return { valid: false, error: "Unrecognized video format" };
|
||||
}
|
||||
|
||||
if (declaredMime && !declaredMime.startsWith("video/")) {
|
||||
return { valid: false, error: "Invalid video MIME type" };
|
||||
}
|
||||
|
||||
return { valid: true, data: buffer };
|
||||
return validateVideoBuffer(Buffer.from(cleanBase64, "base64"), expectedExt, declaredMime);
|
||||
} catch (err) {
|
||||
return { valid: false, error: "Failed to decode video data" };
|
||||
}
|
||||
@@ -496,6 +613,31 @@ function sanitizeLogoUrl(url) {
|
||||
}
|
||||
}
|
||||
|
||||
// adpanel:branding-load-sanitization — load-time twin of the save route's
|
||||
// sanitize set: appName/logoUrl/loginBackgroundExternalUrl are exactly the
|
||||
// fields the save route runs through sanitizeAppName/sanitizeLogoUrl (a
|
||||
// hand-edited config must not get wider acceptance than the admin API), and
|
||||
// existing local paths stay basename-guarded at every resolve site. Legacy
|
||||
// URLs for bundled media resolve to their local files without a network fetch.
|
||||
function sanitizeLoadedBrandingConfig(config) {
|
||||
const logoFilename = resolveBundledMediaFilename(config.logoUrl);
|
||||
const backgroundFilename = resolveBundledMediaFilename(config.loginBackgroundExternalUrl);
|
||||
const bundledLogo = getValidatedLogoExtension(logoFilename);
|
||||
const backgroundType = getMediaTypeFromFilename(backgroundFilename);
|
||||
return {
|
||||
...config,
|
||||
appName: sanitizeAppName(config.appName) || DEFAULT_BRANDING.appName,
|
||||
logoUrl: bundledLogo ? null : sanitizeLogoUrl(config.logoUrl),
|
||||
...(bundledLogo && !resolveLocalBrandingAssetUrl(config.localLogoPath, config) ? { localLogoPath: logoFilename } : {}),
|
||||
loginBackgroundExternalUrl: backgroundType ? null : sanitizeLogoUrl(config.loginBackgroundExternalUrl),
|
||||
...(backgroundType ? {
|
||||
localLoginBackgroundPath: backgroundFilename,
|
||||
loginBackgroundType: backgroundType,
|
||||
loginBackgroundMimeType: getMimeTypeForExtension(getValidatedExtension(backgroundFilename) || getValidatedVideoExtension(backgroundFilename))
|
||||
} : {})
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -505,18 +647,15 @@ function sanitizeLogoUrl(url) {
|
||||
function brandingMiddleware(req, res, next) {
|
||||
const branding = loadBrandingConfig();
|
||||
const safeLogo = safeBasename(branding.localLogoPath);
|
||||
const safeWatermark = safeBasename(branding.localLoginWatermarkPath);
|
||||
|
||||
const localLogoExists = Boolean(safeLogo && fs.existsSync(path.join(PUBLIC_IMAGES_DIR, safeLogo)));
|
||||
|
||||
res.locals.branding = {
|
||||
appName: branding.appName || DEFAULT_BRANDING.appName,
|
||||
faviconUrl: resolveFaviconAssetUrl(branding),
|
||||
logoUrl: safeLogo
|
||||
? `/images/${safeLogo}`
|
||||
: (branding.logoUrl || null),
|
||||
loginWatermarkUrl: safeWatermark
|
||||
? `/images/${safeWatermark}`
|
||||
: resolveLoginWatermarkAssetUrl(branding),
|
||||
faviconMimeType: resolveFaviconMimeType(branding),
|
||||
logoUrl: localLogoExists
|
||||
? `/images/${safeLogo}${getBrandingAssetVersionSuffix(branding)}`
|
||||
: (branding.logoUrl || DEFAULT_LOGO_URL),
|
||||
loginBackgroundType: branding.loginBackgroundType || DEFAULT_BRANDING.loginBackgroundType,
|
||||
loginBackgroundUrl: resolveLoginBackgroundAssetUrl(branding),
|
||||
loginBackgroundMimeType: branding.loginBackgroundMimeType || DEFAULT_BRANDING.loginBackgroundMimeType
|
||||
@@ -531,20 +670,34 @@ module.exports = {
|
||||
saveBrandingConfig,
|
||||
sanitizeAppName,
|
||||
sanitizeLogoUrl,
|
||||
sanitizeLoadedBrandingConfig,
|
||||
resolveBundledMediaFilename,
|
||||
preferBundledMediaUrl,
|
||||
generateSafeLogoFilename,
|
||||
GENERATED_LOGO_FILENAME_RE,
|
||||
GENERATED_LOGIN_BG_FILENAME_RE,
|
||||
validateImageBuffer,
|
||||
validateBase64Image,
|
||||
validateVideoBuffer,
|
||||
validateBase64Video,
|
||||
validateSvgBuffer,
|
||||
sanitizeSvg,
|
||||
getValidatedExtension,
|
||||
getValidatedLogoExtension,
|
||||
getValidatedVideoExtension,
|
||||
getMimeTypeForExtension,
|
||||
getMediaTypeFromFilename,
|
||||
getMediaTypeFromUrl,
|
||||
getExtensionFromUrl,
|
||||
getLogoExtensionFromUrl,
|
||||
getBrandingAssetVersionSuffix,
|
||||
resolveFaviconAssetUrl,
|
||||
resolveLoginWatermarkAssetUrl,
|
||||
resolveFaviconMimeType,
|
||||
resolveLoginBackgroundAssetUrl,
|
||||
invalidateBrandingCache,
|
||||
ALLOWED_EXTENSIONS,
|
||||
ALLOWED_LOGO_EXTENSIONS,
|
||||
DEFAULT_BRANDING,
|
||||
DEFAULT_LOGIN_BACKGROUND_URL
|
||||
DEFAULT_LOGIN_BACKGROUND_URL,
|
||||
DEFAULT_LOGO_URL
|
||||
};
|
||||
Reference in new issue
Block a user