From eaaeacb4c66d3dce434410bcaba8bac442877a1a Mon Sep 17 00:00:00 2001 From: Sijisu Date: Sun, 8 Feb 2026 22:59:58 +0100 Subject: [PATCH] Properly escape text coming from the Immich instance --- app/src/render.ts | 11 ++++++++++- app/views/gallery.ejs | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/render.ts b/app/src/render.ts index bf735b6..b2d9a88 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -6,6 +6,15 @@ import archiver from 'archiver' import { respondToInvalidRequest } from './invalidRequestHandler' import { sanitize } from './includes/sanitize' +function escapeHtml (str: string): string { + return str + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') +} + class Render { lgConfig @@ -134,7 +143,7 @@ class Render { const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) - const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : '' + const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? escapeHtml(asset.exifInfo.description) : '' // Create the full HTML element source to pass to the gallery view const itemHtml = [ diff --git a/app/views/gallery.ejs b/app/views/gallery.ejs index 01bfee0..958bfe7 100644 --- a/app/views/gallery.ejs +++ b/app/views/gallery.ejs @@ -1,15 +1,15 @@ - <%- title %> + <%= title %> <% // Add an og-image using the first image's thumbnail if (items?.[0]?.previewUrl) { %> - + - + <% } %> @@ -20,7 +20,7 @@