From f8adcbb69138a625d478b42808920bdbd3e4a7c6 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Thu, 25 Jul 2024 21:41:40 +0200 Subject: [PATCH] Make light theme default theme on epub reader Fix csp Header for reader and google drive (#3108) Testrun --- cps/helper.py | 4 +- cps/static/js/reading/epub.js | 2 +- cps/web.py | 18 +- test/Calibre-Web TestSummary_Linux.html | 1083 ++++++++++++++--------- 4 files changed, 667 insertions(+), 440 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 08fa1387..37302075 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -463,8 +463,8 @@ def rename_author_path(first_author, old_author_dir, renamed_author, calibre_pat except OSError as ex: log.error("Rename author from: %s to %s: %s", old_author_path, new_author_path, ex) log.debug(ex, exc_info=True) - return _("Rename author from: '%(src)s' to '%(dest)s' failed with error: %(error)s", - src=old_author_path, dest=new_author_path, error=str(ex)) + raise Exception(_("Rename author from: '%(src)s' to '%(dest)s' failed with error: %(error)s", + src=old_author_path, dest=new_author_path, error=str(ex))) return new_authordir # Moves files in file storage during author/title rename, or from temp dir to file storage diff --git a/cps/static/js/reading/epub.js b/cps/static/js/reading/epub.js index 5047b1d3..a552da05 100644 --- a/cps/static/js/reading/epub.js +++ b/cps/static/js/reading/epub.js @@ -79,6 +79,6 @@ var reader; } // Default settings load - const theme = localStorage.getItem("calibre.reader.theme") ?? Object.keys(themes)[0]; + const theme = localStorage.getItem("calibre.reader.theme") ?? "lightTheme"; selectTheme(theme); })(); diff --git a/cps/web.py b/cps/web.py index 7da22e3a..2519ebd5 100644 --- a/cps/web.py +++ b/cps/web.py @@ -89,21 +89,21 @@ except ImportError: def add_security_headers(resp): default_src = ([host.strip() for host in config.config_trustedhosts.split(',') if host] + ["'self'", "'unsafe-inline'", "'unsafe-eval'"]) - csp = "default-src " + ' '.join(default_src) + "; " - csp += "font-src 'self' data:" + csp = "default-src " + ' '.join(default_src) + if request.endpoint == "web.read_book" and config.config_use_google_drive: + csp +=" blob: " + csp += "; font-src 'self' data:" if request.endpoint == "web.read_book": - csp += " blob:" + csp += " blob: " csp += "; img-src 'self'" if request.path.startswith("/author/") and config.config_use_goodreads: csp += " images.gr-assets.com i.gr-assets.com s.gr-assets.com" csp += " data:" if request.endpoint == "edit-book.show_edit_book" or config.config_use_google_drive: - csp += " *;" - elif request.endpoint == "web.read_book": - csp += " blob:; style-src-elem 'self' blob: 'unsafe-inline';" - else: - csp += ";" - csp += " object-src 'none';" + csp += " *" + if request.endpoint == "web.read_book": + csp += " blob: ; style-src-elem 'self' blob: 'unsafe-inline'" + csp += "; object-src 'none';" resp.headers['Content-Security-Policy'] = csp resp.headers['X-Content-Type-Options'] = 'nosniff' resp.headers['X-Frame-Options'] = 'SAMEORIGIN' diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 288c7443..1bdb3396 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
-

Start Time: 2024-07-18 20:53:44

+

Start Time: 2024-07-24 19:37:58

-

Stop Time: 2024-07-19 03:48:09

+

Stop Time: 2024-07-25 02:52:34

-

Duration: 5h 43 min

+

Duration: 6h 1 min

@@ -1791,15 +1791,15 @@ - - TestEditBooksList - 19 - 19 - 0 - 0 + + TestEditAuthorsSmb + 9 + 3 + 4 + 2 0 - Detail + Detail @@ -1807,52 +1807,132 @@ -
TestEditBooksList - test_booklist_xss
+
TestEditAuthorsSmb - test_change_capital_co_author
PASS - + -
TestEditBooksList - test_bookslist_edit_author
+
TestEditAuthorsSmb - test_change_capital_one_author_one_book
+ + +
+ FAIL +
+ + + - PASS - + -
TestEditBooksList - test_bookslist_edit_categories
+
TestEditAuthorsSmb - test_change_capital_one_author_two_books
+ + +
+ FAIL +
+ + + - PASS - + -
TestEditBooksList - test_bookslist_edit_comment
+
TestEditAuthorsSmb - test_change_capital_one_author_two_books_coauthor
+ + +
+ FAIL +
+ + + - PASS - + -
TestEditBooksList - test_bookslist_edit_cust_category
+
TestEditAuthorsSmb - test_change_capital_rename_co_author
+ + +
+ FAIL +
+ + + - PASS -
TestEditBooksList - test_bookslist_edit_cust_comment
+
TestEditAuthorsSmb - test_change_capital_rename_two_co_authors
PASS @@ -1860,6 +1940,153 @@ + +
TestEditAuthorsSmb - test_rename_author_emphasis_mark_onupload
+ + PASS + + + + + + +
TestEditAuthorsSmb - test_rename_capital_on_upload
+ + +
+ ERROR +
+ + + + + + + + + + +
TestEditAuthorsSmb - test_rename_tag_emphasis_mark_onupload
+ + +
+ ERROR +
+ + + + + + + + + + + TestEditBooksList + 19 + 19 + 0 + 0 + 0 + + Detail + + + + + + + +
TestEditBooksList - test_booklist_xss
+ + PASS + + + + + + +
TestEditBooksList - test_bookslist_edit_author
+ + PASS + + + + + + +
TestEditBooksList - test_bookslist_edit_categories
+ + PASS + + + + + + +
TestEditBooksList - test_bookslist_edit_comment
+ + PASS + + + + + + +
TestEditBooksList - test_bookslist_edit_cust_category
+ + PASS + + + + + + +
TestEditBooksList - test_bookslist_edit_cust_comment
+ + PASS + + + + +
TestEditBooksList - test_bookslist_edit_cust_enum
@@ -1868,7 +2095,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_float
@@ -1877,7 +2104,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_int
@@ -1886,7 +2113,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_ratings
@@ -1895,7 +2122,7 @@ - +
TestEditBooksList - test_bookslist_edit_cust_text
@@ -1904,7 +2131,7 @@ - +
TestEditBooksList - test_bookslist_edit_languages
@@ -1913,7 +2140,7 @@ - +
TestEditBooksList - test_bookslist_edit_publisher
@@ -1922,7 +2149,7 @@ - +
TestEditBooksList - test_bookslist_edit_series
@@ -1931,7 +2158,7 @@ - +
TestEditBooksList - test_bookslist_edit_seriesindex
@@ -1940,7 +2167,7 @@ - +
TestEditBooksList - test_bookslist_edit_title
@@ -1949,7 +2176,7 @@ - +
TestEditBooksList - test_list_visibility
@@ -1958,7 +2185,7 @@ - +
TestEditBooksList - test_restricted_rights
@@ -1967,7 +2194,7 @@ - +
TestEditBooksList - test_search_books_list
@@ -1977,40 +2204,40 @@ - + TestLoadMetadata 1 0 - 0 1 0 + 0 - Detail + Detail - +
TestLoadMetadata - test_load_metadata
- ERROR + FAIL
-