diff --git a/custom/js/helper.js b/custom/js/helper.js
index 5b43272..0555922 100644
--- a/custom/js/helper.js
+++ b/custom/js/helper.js
@@ -1,3 +1,13 @@
+function escapeHtml(unsafe)
+{
+ return unsafe
+ .replace(/&/g, "&")
+ .replace(//g, ">")
+ .replace(/"/g, """)
+ .replace(/'/g, "'");
+ }
+
function renderClientList(data) {
$.each(data, function(index, obj) {
// render telegram button
@@ -6,13 +16,13 @@ function renderClientList(data) {
telegramButton = `
+ data-clientname="${escapeHtml(obj.Client.name)}">Telegram
`
}
let telegramHtml = "";
if (obj.Client.telegram_userid && obj.Client.telegram_userid.length > 0) {
- telegramHtml = `${obj.Client.telegram_userid}`
+ telegramHtml = `${escapeHtml(obj.Client.telegram_userid)}`
}
// render client status css tag style
@@ -24,13 +34,13 @@ function renderClientList(data) {
// render client allocated ip addresses
let allocatedIpsHtml = "";
$.each(obj.Client.allocated_ips, function(index, obj) {
- allocatedIpsHtml += `${obj} `;
+ allocatedIpsHtml += `${escapeHtml(obj)} `;
})
// render client allowed ip addresses
let allowedIpsHtml = "";
$.each(obj.Client.allowed_ips, function(index, obj) {
- allowedIpsHtml += `${obj} `;
+ allowedIpsHtml += `${escapeHtml(obj)} `;
})
let subnetRangesString = "";
@@ -40,7 +50,7 @@ function renderClientList(data) {
let additionalNotesHtml = "";
if (obj.Client.additional_notes && obj.Client.additional_notes.length > 0) {
- additionalNotesHtml = `${obj.Client.additional_notes.toUpperCase()}`
+ additionalNotesHtml = `${escapeHtml(obj.Client.additional_notes.toUpperCase())}`
}
// render client html content
@@ -56,12 +66,12 @@ function renderClientList(data) {
+ data-clientname="${escapeHtml(obj.Client.name)}" ${obj.QRCode != "" ? '' : ' disabled'}>QR code
+ data-clientname="${escapeHtml(obj.Client.name)}">Email
${telegramButton}
@@ -72,22 +82,22 @@ function renderClientList(data) {
- ${obj.Client.name}
- ${obj.Client.public_key}
- ${subnetRangesString}
+ ${escapeHtml(obj.Client.name)}
+ ${escapeHtml(obj.Client.public_key)}
+ ${escapeHtml(subnetRangesString)}
${telegramHtml}
${additionalNotesHtml}
- ${obj.Client.email}
+ ${escapeHtml(obj.Client.email)}
${prettyDateTime(obj.Client.created_at)}
@@ -95,7 +105,7 @@ function renderClientList(data) {
${obj.Client.use_server_dns ? 'DNS enabled' : 'DNS disabled'}
- ${obj.Client.additional_notes}
+ ${escapeHtml(obj.Client.additional_notes)}
IP Allocation`
+ allocatedIpsHtml
+ `Allowed IPs`
diff --git a/router/router.go b/router/router.go
index 59d352e..25dafd8 100644
--- a/router/router.go
+++ b/router/router.go
@@ -2,11 +2,11 @@ package router
import (
"errors"
+ "html/template"
"io"
"io/fs"
"reflect"
"strings"
- "text/template"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"