about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-19 13:26:20 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-19 13:26:20 +0300
commitef7d52f85dfe611d536fcb96c3a61db1b8b67481 (patch)
treede050bf0171f4a211c4e8e91196b706c4db10fbf
parent8eb610074f829cdcbbac035340318601fa41af5c (diff)
downloadthe-epube-ef7d52f85dfe611d536fcb96c3a61db1b8b67481.tar.gz
the-epube-ef7d52f85dfe611d536fcb96c3a61db1b8b67481.tar.xz
deal with some potential minor xss issues
-rw-r--r--classes/Handler/DefineHandler.php4
-rw-r--r--classes/Handler/ListHandler.php2
-rw-r--r--src/app.js16
-rw-r--r--src/reader.js10
4 files changed, 16 insertions, 16 deletions
diff --git a/classes/Handler/DefineHandler.php b/classes/Handler/DefineHandler.php
index 7906adc..f15885f 100644
--- a/classes/Handler/DefineHandler.php
+++ b/classes/Handler/DefineHandler.php
@@ -46,7 +46,7 @@ class DefineHandler implements RequestHandlerInterface, AuthRequired
                 $retParsed = $this->parseDictReply($dictReply);
 
                 if (count($retParsed) > 0) {
-                    array_push($result, "<strong>$word</strong>");
+                    array_push($result, "<strong>" . htmlspecialchars($word, ENT_QUOTES, 'UTF-8') . "</strong>");
                     $result = array_merge($result, $retParsed);
                     break;
                 } else {
@@ -60,7 +60,7 @@ class DefineHandler implements RequestHandlerInterface, AuthRequired
         }
 
         if (count($result) == 0) {
-            array_push($result, "No results for: <b>$origWord</b>");
+            array_push($result, "No results for: <b>" . htmlspecialchars($origWord, ENT_QUOTES, 'UTF-8') . "</b>");
         }
 
         return (new Response())->withBody(json_encode(["result" => $result]));
diff --git a/classes/Handler/ListHandler.php b/classes/Handler/ListHandler.php
index e8a5916..6ecec7d 100644
--- a/classes/Handler/ListHandler.php
+++ b/classes/Handler/ListHandler.php
@@ -32,7 +32,7 @@ class ListHandler implements RequestHandlerInterface, AuthRequired
 
             $fav_ids = [];
             while ($line = $fav_sth->fetch()) {
-                array_push($fav_ids, $line["bookid"]);
+                array_push($fav_ids, (int) $line["bookid"]);
             }
 
             if (empty($fav_ids)) {
diff --git a/src/app.js b/src/app.js
index e72da4f..4bc10b4 100644
--- a/src/app.js
+++ b/src/app.js
@@ -140,6 +140,13 @@ class AppCommon {
         $("#theme_css").attr("href",
             "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css"));
     }
+
+    escapeHtml(str) {
+        if (!str) return "";
+        const div = document.createElement("div");
+        div.appendChild(document.createTextNode(str));
+        return div.innerHTML;
+    }
 }
 
 /* eslint-disable-next-line no-unused-vars */
@@ -475,7 +482,7 @@ class AppClass extends AppCommon {
 
             $(".dl-progress")
                 .show()
-                .html("Finished downloading <b>" + data.title + "</b>");
+                .html("Finished downloading <b>" + this.escapeHtml(data.title) + "</b>");
 
             window.clearTimeout(this._dl_progress_timeout);
 
@@ -648,13 +655,6 @@ class AppClass extends AppCommon {
         pagerInfo.find("span").text(`Page ${currentPage} of ${totalPages}`);
     }
 
-    escapeHtml(str) {
-        if (!str) return "";
-        const div = document.createElement("div");
-        div.appendChild(document.createTextNode(str));
-        return div.innerHTML;
-    }
-
     /**
      * Render a book cell DOM element.
      * @param {BookInfo} book - Book data object.
diff --git a/src/reader.js b/src/reader.js
index 8f8e784..a45ce9c 100644
--- a/src/reader.js
+++ b/src/reader.js
@@ -242,7 +242,7 @@ class ReaderClass extends AppCommon {
 
                 console.error(err);
 
-                $(".loading-message").html(`Unable to load book info.<br/><small>${err.responseText}</small>`);
+                $(".loading-message").html(`Unable to load book info.<br/><small>${this.escapeHtml(err.responseText)}</small>`);
                 return;
             }
         }
@@ -285,7 +285,7 @@ class ReaderClass extends AppCommon {
 
         fileReader.onerror = (e) => {
             console.log('filereader error', e);
-            $(".loading-message").html("Unable to open book.<br/><small>" + e + "</small>");
+            $(".loading-message").html("Unable to open book.<br/><small>" + this.escapeHtml(String(e)) + "</small>");
         };
 
         fileReader.readAsArrayBuffer(book_data);
@@ -298,7 +298,7 @@ class ReaderClass extends AppCommon {
             await this.book.open(book_data);
         } catch (e) {
             console.error(e);
-            $(".loading-message").html(`Unable to open book.<br/><small>${e instanceof Error ? e.message: e}</small>`);
+            $(".loading-message").html(`Unable to open book.<br/><small>${this.escapeHtml(e instanceof Error ? e.message : String(e))}</small>`);
             return;
         }
 
@@ -1406,7 +1406,7 @@ class ReaderClass extends AppCommon {
 
             console.error(err);
 
-            $(".dict_result").html(`Network error while looking up word: ${err.responseText}.`);
+            $(".dict_result").html(`Network error while looking up word: ${this.escapeHtml(err.responseText)}.`);
         }
     }
 
@@ -1443,7 +1443,7 @@ class ReaderClass extends AppCommon {
 
                 const a = $("<a>")
                     .attr('href', '#')
-                    .html(`<b class='pull-right'>${this.book.locations.locationFromCfi(row.cfi)}</b>${row.excerpt}`)
+                    .html(`<b class='pull-right'>${this.book.locations.locationFromCfi(row.cfi)}</b>${this.escapeHtml(row.excerpt)}`)
                     .attr('data-cfi', row.cfi)
                     .on('click', () => {
                         this.book.rendition.display($(a).attr('data-cfi'));