Files
wekan/models/lib/emailNotificationSafety.js
T
Lauri Ojansivu b6da4ebe96 Wrap card/board URLs in HTML notification emails in real <a href> links.
The HTML-formatted notification email built its body from the same
plain-text line used for the non-HTML email, so the card/board URL sat as
bare text instead of a clickable link. buildHtmlNotificationLine() now
builds the HTML body directly, escaping the actor name/description exactly
as before and wrapping the URL in an escaped <a href>. The plain-text email
is unchanged.

Thanks to papimla and xet7 !

Closes #3118,
2026-09-10 20:23:43 +03:00

36 lines
1.3 KiB
JavaScript

'use strict';
function escapeEmailHtml(value) {
return String(value ?? '')
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#39;');
}
function safeEmailSubject(value) {
return String(value ?? '').replace(/[\r\n]+/g, ' ').trim();
}
// #3118: an HTML-formatted notification email must render the card/board URL
// as a real clickable <a href> link, not as plain text that merely looks like
// one. Every dynamic piece is escaped BEFORE it is placed into the markup, so
// the subject/actor name/description can never inject markup of their own;
// only the wrapping <a href="..."> tag itself is real HTML. Pulled out as a
// pure function (no Meteor/TAPi18n dependency) so it can be unit tested.
function buildHtmlNotificationLine({ existing, subject, actorName, descriptionText, url }) {
const htmlHead = existing
? `<br/>\n${escapeEmailHtml(subject)}<br/>\n`
: '';
const safeUrl = url || '';
const link = safeUrl
? `<a href="${escapeEmailHtml(safeUrl)}">${escapeEmailHtml(safeUrl)}</a>`
: '';
return `${htmlHead}${escapeEmailHtml(actorName || '')} ${escapeEmailHtml(
descriptionText || '',
)}${link ? `<br/>\n${link}` : ''}`;
}
module.exports = { escapeEmailHtml, safeEmailSubject, buildHtmlNotificationLine };