Skip to content

Commit

Permalink
Prevent malformed DNS queries executing JS on querylog/long term quer…
Browse files Browse the repository at this point in the history
…y log

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
  • Loading branch information
PromoFaux committed Dec 23, 2020
1 parent c32bcd3 commit c568d05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions scripts/pi-hole/js/db_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ $(function () {

tableApi = $("#all-queries").DataTable({
rowCallback: function (row, data) {
for (i = 0; i < data.length; i++) {
//Santise data coming back from API to ensure no malicious HTML
data[i] = utils.escapeHtml(data[i]);
}
var fieldtext, buttontext, color;
switch (data[4]) {
case 1:
Expand Down Expand Up @@ -324,8 +328,8 @@ $(function () {
}
},
{ width: "10%" },
{ width: "40%" },
{ width: "20%", type: "ip-address" },
{ width: "40%", render: $.fn.dataTable.render.text() },
{ width: "20%", type: "ip-address", render: $.fn.dataTable.render.text() },
{ width: "10%" },
{ width: "5%" }
],
Expand Down
4 changes: 4 additions & 0 deletions scripts/pi-hole/js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ $(function () {

tableApi = $("#all-queries").DataTable({
rowCallback: function (row, data) {
for (i = 0; i < data.length; i++) {
//Santise data coming back from API to ensure no malicious HTML
data[i] = utils.escapeHtml(data[i]);
}
// DNSSEC status
var dnssecStatus;
switch (data[6]) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/pi-hole/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function escapeHtml(text) {
'"': "&quot;",
"'": "&#039;"
};

if (typeof text !== "string") return text;
if (text === null) return null;

return text.replace(/[&<>"']/g, function (m) {
Expand All @@ -32,7 +32,7 @@ function unescapeHtml(text) {
"&quot;": '"',
"&#039;": "'"
};

if (typeof text !== "string") return text;
if (text === null) return null;

return text.replace(/&(?:amp|lt|gt|quot|#039);/g, function (m) {
Expand Down

0 comments on commit c568d05

Please sign in to comment.