Skip to content

Commit bcbe063

Browse files
Potential fix for code scanning alert no. 22: DOM text reinterpreted as HTML
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent c915d46 commit bcbe063

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

static/dashboard.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ let emailAccounts = [];
44
let availableDomains = [];
55
let selectedDomain = null;
66

7+
// Escape a string for HTML insertion (prevents XSS)
8+
function escapeHTML(str) {
9+
return String(str)
10+
.replace(/&/g, "&amp;")
11+
.replace(/</g, "&lt;")
12+
.replace(/>/g, "&gt;")
13+
.replace(/"/g, "&quot;")
14+
.replace(/'/g, "&#39;");
15+
}
16+
717
// Helper function to validate destinations (including special ones)
818
function isValidDestination(destination) {
919
// Allow special destinations
@@ -228,9 +238,9 @@ async function loadForwarders() {
228238
console.error('Error loading forwarders:', error);
229239

230240
if (error.response && error.response.status === 403) {
231-
tbody.innerHTML = '<tr><td colspan="3" class="error-message">Domain access denied: ' + selectedDomain + ' may not be configured in your DirectAdmin account.</td></tr>';
241+
tbody.innerHTML = '<tr><td colspan="3" class="error-message">Domain access denied: ' + escapeHTML(selectedDomain) + ' may not be configured in your DirectAdmin account.</td></tr>';
232242
} else {
233-
tbody.innerHTML = '<tr><td colspan="3" class="error-message">Failed to load forwarders for ' + selectedDomain + '. Please check your DirectAdmin settings.</td></tr>';
243+
tbody.innerHTML = '<tr><td colspan="3" class="error-message">Failed to load forwarders for ' + escapeHTML(selectedDomain) + '. Please check your DirectAdmin settings.</td></tr>';
234244
}
235245
}
236246
}

0 commit comments

Comments
 (0)