mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
Escape the completed localized notification before creating HTML line breaks and remove subject newlines so stored card, list, board, actor, comment, and translation values remain text. Thanks to binary-lover and xet7 !
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const { escapeEmailHtml, safeEmailSubject } = require(
|
|
path.join(root, 'models/lib/emailNotificationSafety'),
|
|
);
|
|
const email = fs.readFileSync(
|
|
path.join(root, 'server/notifications/email.js'),
|
|
'utf8',
|
|
);
|
|
|
|
assert.equal(
|
|
escapeEmailHtml(`<img src=x onerror="alert('x')"> & card`),
|
|
'<img src=x onerror="alert('x')"> & card',
|
|
'HTML-active card, list and board titles must render only as text',
|
|
);
|
|
assert.equal(
|
|
escapeEmailHtml('ordinary Roadmap title'),
|
|
'ordinary Roadmap title',
|
|
'ordinary notification text must remain readable',
|
|
);
|
|
assert.equal(
|
|
safeEmailSubject('Roadmap\r\nBcc: attacker@example.test'),
|
|
'Roadmap Bcc: attacker@example.test',
|
|
'titles must not inject additional mail headers',
|
|
);
|
|
assert.match(
|
|
email,
|
|
/htmlEnabled \? escapeEmailHtml\(text\)\.replace\(\/\\n\/g, '<br\/>'\) : text/,
|
|
'the completed localized message must be escaped before line breaks become HTML',
|
|
);
|
|
assert.match(
|
|
email,
|
|
/const subject = safeEmailSubject\(formatActivityNotificationTitle\(/,
|
|
'notification subjects must use the shared header-safe formatter',
|
|
);
|
|
|
|
console.log('notificationEmailHtmlSafety: 5 assertions passed');
|