diff --git a/public/visualsubnetcalc/js/main.js b/public/visualsubnetcalc/js/main.js
index d2b366db..82fd63cb 100644
--- a/public/visualsubnetcalc/js/main.js
+++ b/public/visualsubnetcalc/js/main.js
@@ -33,7 +33,7 @@ function escapeHtml(text) {
'"': '"',
"'": '''
};
- return text.replace(/[&<>"']/g, char => map[char]);
+ return String(text).replace(/[&<>"']/g, char => map[char]);
}
// Helper function to generate HTML table from table data array
@@ -1139,7 +1139,7 @@ function reset() {
let rootNetwork = get_network($('#network').val(), $('#netsize').val())
let rootCidr = rootNetwork + '/' + $('#netsize').val()
if (cidrInput !== rootCidr) {
- show_warning_modal('
Your network input is not on a network boundary for this network size. It has been automatically changed:
' + $('#network').val() + ' -> ' + rootNetwork + '
')
+ show_warning_modal('Your network input is not on a network boundary for this network size. It has been automatically changed:
' + escapeHtml($('#network').val()) + ' -> ' + escapeHtml(rootNetwork) + '
')
$('#network').val(rootNetwork)
cidrInput = $('#network').val() + '/' + $('#netsize').val()
}
@@ -1264,6 +1264,13 @@ function addRowTree(subnetTree, depth, maxDepth, operatingMode) {
}
function addRow(network, netSize, colspan, note, notesWidth, color, operatingMode) {
+ // The subnet map can come from a shareable URL or an imported config, so escape everything that lands in HTML
+ const rawNetwork = network
+ network = escapeHtml(network)
+ note = escapeHtml(note)
+ if (!/^#[0-9a-f]{3,8}$/i.test(color)) {
+ color = ''
+ }
let addressFirst = ip2int(network)
let addressLast = subnet_last_address(addressFirst, netSize)
let usableFirst = subnet_usable_first(addressFirst, netSize, operatingMode)
@@ -1317,10 +1324,10 @@ function addRow(network, netSize, colspan, note, notesWidth, color, operatingMod
// DONE: If the subnet address (without the mask) matches a larger subnet address
// in the heirarchy that is a signal to add more join buttons to that row, since they start at the top row and
// via rowspan extend downward.
- let matchingNetworkList = get_matching_network_list(network, subnetMap).slice(1)
+ let matchingNetworkList = get_matching_network_list(rawNetwork, subnetMap).slice(1)
for (const i in matchingNetworkList) {
- let matchingNetwork = matchingNetworkList[i]
- let networkChildrenCount = count_network_children(matchingNetwork, subnetMap, [])
+ let networkChildrenCount = count_network_children(matchingNetworkList[i], subnetMap, [])
+ let matchingNetwork = escapeHtml(matchingNetworkList[i])
newRow += ' /' + matchingNetwork.split('/')[1] + ' | \n'
}
}
@@ -2281,7 +2288,7 @@ $('#btn_auto_allocate').on('click', function() {
if (subnetRequests.errors) {
let errorHtml = 'Subnet Requirements Errors:';
for (const error of subnetRequests.errors) {
- errorHtml += `- ${error}
`;
+ errorHtml += `- ${escapeHtml(error)}
`;
}
errorHtml += '
';
$('#allocation_results').html(errorHtml);
@@ -2464,7 +2471,7 @@ $('#btn_auto_allocate').on('click', function() {
if (allocations.length > 0) {
resultsHtml += 'Allocated Subnets:
';
for (const alloc of allocations) {
- resultsHtml += `- ${alloc.name}: ${alloc.cidr}
`;
+ resultsHtml += `- ${escapeHtml(alloc.name)}: ${escapeHtml(alloc.cidr)}
`;
}
resultsHtml += '
';
@@ -2557,7 +2564,7 @@ $('#btn_auto_allocate').on('click', function() {
if (allocationErrors.length > 0) {
resultsHtml += 'Errors:
';
for (const error of allocationErrors) {
- resultsHtml += `- ${error}
`;
+ resultsHtml += `- ${escapeHtml(error)}
`;
}
resultsHtml += '
';
}
@@ -2565,7 +2572,7 @@ $('#btn_auto_allocate').on('click', function() {
$('#allocation_results').html(resultsHtml);
} catch (error) {
console.error('Auto-allocation error:', error);
- $('#allocation_results').html('An error occurred during allocation: ' + error.message + '
');
+ $('#allocation_results').html('An error occurred during allocation: ' + escapeHtml(error.message) + '
');
}
}, 100);
});
@@ -2665,14 +2672,14 @@ $('#btn_validate_alignment').on('click', function() {
if (issues.length > 0) {
resultsHtml += 'Issues Found:
';
for (const issue of issues) {
- resultsHtml += `- ${issue}
`;
+ resultsHtml += `- ${escapeHtml(issue)}
`;
}
resultsHtml += '
';
}
if (warnings.length > 0) {
resultsHtml += 'Gaps Detected:
';
for (const warning of warnings) {
- resultsHtml += `- ${warning}
`;
+ resultsHtml += `- ${escapeHtml(warning)}
`;
}
resultsHtml += '
';
}
diff --git a/public/zpool-calc/capacity.js b/public/zpool-calc/capacity.js
index 1465fa21..2f5af1ed 100644
--- a/public/zpool-calc/capacity.js
+++ b/public/zpool-calc/capacity.js
@@ -1255,9 +1255,9 @@ $(document).ready(function() {
$("input#add_vdev").val("");
if (new_vdev_type == "mirror") {
- $("td#status").html(new_vdev_width + "-way mirror added");
+ $("td#status").text(new_vdev_width + "-way mirror added");
} else {
- $("td#status").html(new_vdev_width + "-wide " + new_vdev_type.toUpperCase() + " added");
+ $("td#status").text(new_vdev_width + "-wide " + new_vdev_type.toUpperCase() + " added");
}
}