Skip to content

Commit 8330a7b

Browse files
authored
Merge commit from fork
Alternative advisory fix, including the fix for the Lua function
2 parents 2e445c9 + 973900b commit 8330a7b

6 files changed

Lines changed: 36 additions & 31 deletions

File tree

scripts/js/charts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This file is copyright under the latest version of the EUPL.
66
* Please see LICENSE file for your rights under this license. */
77

8-
/* global upstreamIPs:false */
8+
/* global upstreamIPs:false, utils:false */
99

1010
"use strict";
1111

@@ -211,7 +211,7 @@ function setTooltipContent(tooltipEl, tooltip) {
211211
let tooltipHtml = "<thead>";
212212

213213
for (const title of titleLines) {
214-
tooltipHtml += `<tr><th>${title}</th></tr>`;
214+
tooltipHtml += `<tr><th>${utils.escapeHtml(title)}</th></tr>`;
215215
}
216216

217217
tooltipHtml += "</thead><tbody>";
@@ -231,7 +231,7 @@ function setTooltipContent(tooltipEl, tooltip) {
231231
// Do not display entries with value of 0 in bar chart,
232232
// but pass through entries with "0.0%" (in pie charts)
233233
if (num[1] !== "0") {
234-
tooltipHtml += `<tr><td>${span}${body}</td></tr>`;
234+
tooltipHtml += `<tr><td>${span}${utils.escapeHtml(body.toString())}</td></tr>`;
235235
printed++;
236236
}
237237
}

scripts/js/network.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ $(() => {
163163

164164
// Only add IPs to the table if we have not reached the maximum
165165
if (ips.length < MAXIPDISPLAY) {
166-
ips.push(`<a href="queries?client_ip=${ip}">${iptext}</a>`);
166+
ips.push(
167+
`<a href="queries?client_ip=${encodeURIComponent(ip)}">${utils.escapeHtml(iptext)}</a>`
168+
);
167169
}
168170
}
169171

scripts/js/queries.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function parseQueryStatus(data) {
159159
icon = "fa-solid fa-cloud-download-alt";
160160
fieldtext =
161161
(data.reply.type !== "UNKNOWN" ? "Forwarded, reply from " : "Forwarded to ") +
162-
data.upstream;
162+
utils.escapeHtml(data.upstream);
163163
buttontext =
164164
'<button type="button" class="btn btn-default btn-sm text-red btn-blacklist"><i class="fa fa-ban"></i> Deny</button>';
165165
break;
@@ -270,14 +270,14 @@ function parseQueryStatus(data) {
270270
case "SPECIAL_DOMAIN":
271271
colorClass = "text-red";
272272
icon = "fa-solid fa-ban";
273-
fieldtext = data.status;
273+
fieldtext = utils.escapeHtml(data.status);
274274
buttontext = "";
275275
blocked = true;
276276
break;
277277
default:
278278
colorClass = "text-orange";
279279
icon = "fa-solid fa-question";
280-
fieldtext = data.status;
280+
fieldtext = utils.escapeHtml(data.status);
281281
buttontext = "";
282282
}
283283

@@ -374,7 +374,10 @@ function formatInfo(data) {
374374
let cnameInfo = "";
375375
if (queryStatus.isCNAME) {
376376
cnameInfo =
377-
divStart + "Query was blocked during CNAME inspection of&nbsp;&nbsp;" + data.cname + "</div>";
377+
divStart +
378+
"Query was blocked during CNAME inspection of&nbsp;&nbsp;" +
379+
utils.escapeHtml(data.cname) +
380+
"</div>";
378381
}
379382

380383
// Show TTL if applicable
@@ -392,8 +395,8 @@ function formatInfo(data) {
392395
// Show client information, show hostname only if available
393396
const ipInfo =
394397
data.client.name !== null && data.client.name.length > 0
395-
? utils.escapeHtml(data.client.name) + " (" + data.client.ip + ")"
396-
: data.client.ip;
398+
? utils.escapeHtml(data.client.name) + " (" + utils.escapeHtml(data.client.ip) + ")"
399+
: utils.escapeHtml(data.client.ip);
397400
const clientInfo = divStart + "Client:&nbsp;&nbsp;<strong>" + ipInfo + "</strong></div>";
398401

399402
// Show DNSSEC status if applicable
@@ -418,7 +421,7 @@ function formatInfo(data) {
418421
let replyInfo = "";
419422
replyInfo =
420423
data.reply.type !== "UNKNOWN"
421-
? divStart + "Reply:&nbsp;&nbsp;" + data.reply.type + "</div>"
424+
? divStart + `Reply:&nbsp;&nbsp;${utils.escapeHtml(data.reply.type)}</div>`
422425
: divStart + "Reply:&nbsp;&nbsp;No reply received</div>";
423426

424427
// Show extended DNS error if applicable
@@ -429,7 +432,7 @@ function formatInfo(data) {
429432
edeInfo += ' class="' + dnssec.color + '"';
430433
}
431434

432-
edeInfo += ">" + data.ede.text + "</strong></div>";
435+
edeInfo += ">" + utils.escapeHtml(data.ede.text) + "</strong></div>";
433436
}
434437

435438
// Compile extra info for displaying
@@ -640,7 +643,7 @@ $(() => {
640643
" " +
641644
querystatus.colorClass +
642645
"' title='" +
643-
utils.escapeHtml(querystatus.fieldtext) +
646+
querystatus.fieldtext +
644647
"'></i>"
645648
);
646649
} else if (querystatus.colorClass !== false) {

scripts/js/settings-advanced.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ function valueDetails(key, value) {
9090
'<label class="col-sm-2 control-label">Value <small>(string)</small></label>' +
9191
'<div class="col-sm-10">' +
9292
'<input type="text" class="form-control" value="' +
93-
value.value +
93+
utils.escapeHtml(value.value) +
9494
'" data-key="' +
95-
key +
95+
utils.escapeHtml(key) +
9696
'"' +
9797
extraAttributes +
9898
"> " +
@@ -129,9 +129,9 @@ function valueDetails(key, value) {
129129
'<label class="col-sm-2 control-label">Value</label>' +
130130
'<div class="col-sm-10">' +
131131
'<input type="number" class="form-control" value="' +
132-
value.value +
132+
utils.escapeHtml(String(value.value)) +
133133
'" data-key="' +
134-
key +
134+
utils.escapeHtml(key) +
135135
'" data-type="float"' +
136136
extraAttributes +
137137
"> " +
@@ -146,9 +146,9 @@ function valueDetails(key, value) {
146146
'<label class="col-sm-2 control-label">Value <small>(integer)</small></label>' +
147147
'<div class="col-sm-10">' +
148148
'<input type="number" step="1" class="form-control" value="' +
149-
value.value +
149+
utils.escapeHtml(String(value.value)) +
150150
'" data-key="' +
151-
key +
151+
utils.escapeHtml(key) +
152152
'" data-type="integer"' +
153153
extraAttributes +
154154
"> " +
@@ -163,9 +163,9 @@ function valueDetails(key, value) {
163163
'<label class="col-sm-4 control-label">Value <small>(unsigned integer)</small></label>' +
164164
'<div class="col-sm-8">' +
165165
'<input type="number" step="1" min="0" class="form-control" value="' +
166-
value.value +
166+
utils.escapeHtml(String(value.value)) +
167167
'" data-key="' +
168-
key +
168+
utils.escapeHtml(key) +
169169
'" data-type="integer"' +
170170
extraAttributes +
171171
"> " +
@@ -180,9 +180,9 @@ function valueDetails(key, value) {
180180
'<label class="col-sm-4 control-label">Value <small>(unsigned 16bit integer)</small></label>' +
181181
'<div class="col-sm-8">' +
182182
'<input type="number" step="1" min="0" max="65535" class="form-control" value="' +
183-
value.value +
183+
utils.escapeHtml(String(value.value)) +
184184
'" data-key="' +
185-
key +
185+
utils.escapeHtml(key) +
186186
'" data-type="integer"' +
187187
extraAttributes +
188188
"> " +

scripts/js/taillog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function getData() {
9898
// Validate that file parameter is one of the allowed values
9999
if (!allowedFileParams.includes(queryParams.file)) {
100100
const errorMessage = `Invalid file parameter: ${queryParams.file}. Allowed values are: ${allowedFileParams.join(", ")}`;
101-
outputElement.innerHTML = `<div><em class="text-danger">*** Error: ${errorMessage} ***</em></div>`;
101+
outputElement.innerHTML = `<div><em class="text-danger">*** Error: ${utils.escapeHtml(errorMessage)} ***</em></div>`;
102102
return;
103103
}
104104

scripts/lua/header.lp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ end
4747

4848
-- Function to sanitize hostname containing invalid HTML characters
4949
function sanitize_hostname(str)
50-
-- Check if string contains any of the HTML special characters
51-
if str:find("&<>\"'") then
52-
return "invalid hostname"
53-
end
54-
55-
-- Return the original string if no special characters are found
56-
return str
50+
return str:gsub("[&<>\"']", {
51+
["&"] = "&amp;",
52+
["<"] = "&lt;",
53+
[">"] = "&gt;",
54+
['"'] = "&quot;",
55+
["'"] = "&#039;"
56+
})
5757
end
5858

5959
-- Sanitize hostname

0 commit comments

Comments
 (0)