From bb02a0bd977bfcfc8b364d2f8dfd7e3bcdb3bb42 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 15 Jul 2025 13:01:34 +0200 Subject: [PATCH] Bind data attributes instead of inlining them for security (to prevent any possibility for code injection) Signed-off-by: DL6ER --- scripts/js/settings-dhcp.js | 82 ++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/scripts/js/settings-dhcp.js b/scripts/js/settings-dhcp.js index 5e4e0655..8f1b15ea 100644 --- a/scripts/js/settings-dhcp.js +++ b/scripts/js/settings-dhcp.js @@ -74,20 +74,23 @@ $(() => { }, rowCallback(row, data) { $(row).attr("data-id", data.ip); - const button = - '' + - ' '; - $("td:eq(6)", row).html(button); + // Create buttons without data-* attributes in HTML + const $deleteBtn = $( + '' + ) + .attr("id", "deleteLease_" + data.ip) + .attr("data-del-ip", data.ip) + .attr("title", "Delete lease") + .attr("data-toggle", "tooltip"); + const $copyBtn = $( + '' + ) + .attr("title", "Copy to static leases") + .attr("data-toggle", "tooltip") + .data("hwaddr", data.hwaddr || "") + .data("ip", data.ip || "") + .data("hostname", data.name || ""); + $("td:eq(6)", row).empty().append($deleteBtn, " ", $copyBtn); }, select: { style: "multi", @@ -367,24 +370,39 @@ function renderStaticDHCPTable() { continue; } - const tr = $( - "" + - '' + - '' + - '' + - "" + - ' ' + - ' ' + - '' + - "" + - "" - ); + const tr = $("") + .append($('')) + .append($('')) + .append($('')) + .append( + $("") + .append( + $( + '' + ) + .attr("data-row", idx) + .attr("title", "Save changes to this line") + .attr("data-toggle", "tooltip") + ) + .append(" ") + .append( + $( + '' + ) + .attr("data-row", idx) + .attr("title", "Delete this line") + .attr("data-toggle", "tooltip") + ) + .append(" ") + .append( + $( + '' + ) + .attr("data-row", idx) + .attr("title", "Add new line after this") + .attr("data-toggle", "tooltip") + ) + ); // Set cell values, with placeholder for empty hwaddr tr.find(".static-hwaddr").text(parsed.hwaddr); tr.find(".static-ipaddr").text(parsed.ipaddr);