diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-06-19 13:26:20 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-06-19 13:26:20 +0300 |
| commit | ef7d52f85dfe611d536fcb96c3a61db1b8b67481 (patch) | |
| tree | de050bf0171f4a211c4e8e91196b706c4db10fbf /src | |
| parent | 8eb610074f829cdcbbac035340318601fa41af5c (diff) | |
| download | the-epube-ef7d52f85dfe611d536fcb96c3a61db1b8b67481.tar.gz the-epube-ef7d52f85dfe611d536fcb96c3a61db1b8b67481.tar.xz | |
deal with some potential minor xss issues
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.js | 16 | ||||
| -rw-r--r-- | src/reader.js | 10 |
2 files changed, 13 insertions, 13 deletions
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')); |
