Merge pull request #183 from Sijisu/main

Fix numerous XSS vulnerabilities when rendering text coming from the Immich instance
This commit is contained in:
Alan Grainger
2026-02-09 11:28:40 +13:00
committed by GitHub
2 changed files with 14 additions and 5 deletions
+10 -1
View File
@@ -6,6 +6,15 @@ import archiver from 'archiver'
import { respondToInvalidRequest } from './invalidRequestHandler' import { respondToInvalidRequest } from './invalidRequestHandler'
import { sanitize } from './includes/sanitize' import { sanitize } from './includes/sanitize'
function escapeHtml (str: string): string {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
class Render { class Render {
lgConfig lgConfig
@@ -134,7 +143,7 @@ class Render {
const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail)
const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) 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, '&apos;') : '' 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 // Create the full HTML element source to pass to the gallery view
const itemHtml = [ const itemHtml = [
+4 -4
View File
@@ -1,15 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title><%- title %></title> <title><%= title %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<% <%
// Add an og-image using the first image's thumbnail // Add an og-image using the first image's thumbnail
if (items?.[0]?.previewUrl) { if (items?.[0]?.previewUrl) {
%> %>
<meta property="og:title" content="<%- title %>"> <meta property="og:title" content="<%= title %>">
<meta property="og:image" content="<%- publicBaseUrl %><%- items[0].previewUrl %>"> <meta property="og:image" content="<%- publicBaseUrl %><%- items[0].previewUrl %>">
<meta name="twitter:title" content="<%- title %>"> <meta name="twitter:title" content="<%= title %>">
<meta name="twitter:image" content="<%- publicBaseUrl %><%- items[0].previewUrl %>"> <meta name="twitter:image" content="<%- publicBaseUrl %><%- items[0].previewUrl %>">
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:card" content="summary_large_image">
<% } %> <% } %>
@@ -20,7 +20,7 @@
<body> <body>
<div id="header"> <div id="header">
<% if (showTitle) { %> <% if (showTitle) { %>
<h1><%- title || 'Gallery' %></h1> <h1><%= title || 'Gallery' %></h1>
<% } %> <% } %>
<% <%
if (showDownload) { if (showDownload) {