fix: escape HTML in receipt print template to prevent injection

This commit is contained in:
Derek Ross committed 2026-04-12 12:58:57 -04:00
1 parent c229f40da8
commit 47f9edacfd
1 file changed
+7 -4
+7 -4
View File
@@ -895,6 +895,9 @@ export function AIProviderConfigDialog({
}
};
const escapeHtml = (str: string): string =>
str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
const handlePrintReceipt = (payment: Payment) => {
const receiptDate = new Date((payment.completed_at ?? payment.created_at) * 1000);
const formattedDate = new Intl.DateTimeFormat('en-US', {
@@ -924,7 +927,7 @@ export function AIProviderConfigDialog({
<!DOCTYPE html>
<html>
<head>
<title>${t('receipt')} - ${payment.id}</title>
<title>${t('receipt')} - ${escapeHtml(payment.id)}</title>
<style>
* {
margin: 0;
@@ -1070,14 +1073,14 @@ export function AIProviderConfigDialog({
<dl class="details-grid">
<dt>${t('receiptNumber')}</dt>
<dd>${payment.id}</dd>
<dd>${escapeHtml(payment.id)}</dd>
<dt>${t('date')}</dt>
<dd>${formattedDate} ${formattedTime}</dd>
<dt>${t('status')}</dt>
<dd>${statusDisplay}</dd>
<dd>${escapeHtml(statusDisplay)}</dd>
<dt>${t('paymentMethodLabel')}</dt>
<dd>${paymentMethodDisplay}</dd>
${payment.description ? `<dt>${t('description')}</dt><dd>${payment.description}</dd>` : ''}
${payment.description ? `<dt>${t('description')}</dt><dd>${escapeHtml(payment.description)}</dd>` : ''}
</dl>
<hr class="divider" />