Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions web-app/js/projects/budget-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,14 @@ function getCategoryEmoji(category, type) {
return type === "income" ? CATEGORY_EMOJIS["income_default"] : CATEGORY_EMOJIS["expense_default"];
}

// Escapes a user-controlled string so it renders as literal text when
// interpolated into an innerHTML template, preventing HTML/script injection.
function escapeHTML(str) {
const div = document.createElement("div");
div.textContent = str;
return div.innerHTML;
}

function initBudgetTracker() {
let transactions = [];
let activeBreakdownType = "expense";
Expand Down Expand Up @@ -1181,7 +1189,7 @@ function initBudgetTracker() {
item.className = "breakdown-item";
item.innerHTML = `
<div class="breakdown-info">
<span class="breakdown-name">${emoji} ${cat} (${percent.toFixed(1)}%)</span>
<span class="breakdown-name">${emoji} ${escapeHTML(cat)} (${percent.toFixed(1)}%)</span>
<span class="breakdown-amount">₹${amount.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span>
</div>
<div class="breakdown-bar-bg">
Expand Down Expand Up @@ -1230,8 +1238,8 @@ function initBudgetTracker() {
<span>${emoji}</span>
</div>
<div class="trans-text">
<span class="trans-category-tag">${t.category}</span>
${t.description ? `<span class="trans-desc">${t.description}</span>` : ''}
<span class="trans-category-tag">${escapeHTML(t.category)}</span>
${t.description ? `<span class="trans-desc">${escapeHTML(t.description)}</span>` : ''}
<span class="trans-date">${t.date}</span>
</div>
</div>
Expand Down
Loading