diff --git a/cps/redirect.py b/cps/redirect.py old mode 100644 new mode 100755 index 09b3101f..337bb77b --- a/cps/redirect.py +++ b/cps/redirect.py @@ -29,7 +29,7 @@ from urllib.parse import urlparse, urljoin -from flask import request, url_for, redirect +from flask import request, url_for, redirect, current_app def is_safe_url(target): @@ -38,16 +38,15 @@ def is_safe_url(target): return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc -def get_redirect_target(): - for target in request.values.get('next'), request.referrer: - if not target: - continue - if is_safe_url(target): - return target +def remove_prefix(text, prefix): + if text.startswith(prefix): + return text[len(prefix):] + return "" def redirect_back(endpoint, **values): - target = request.form['next'] - if not target or not is_safe_url(target): + target = request.form.get('next', None) or url_for(endpoint, **values) + adapter = current_app.url_map.bind(urlparse(request.host_url).netloc) + if not len(adapter.allowed_methods(remove_prefix(target, request.environ.get('HTTP_X_SCRIPT_NAME',"")))): target = url_for(endpoint, **values) return redirect(target) diff --git a/cps/web.py b/cps/web.py index 705627e7..4a95a21d 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1322,7 +1322,7 @@ def handle_login_user(user, remember, message, category): ub.store_user_session() flash(message, category=category) [limiter.limiter.storage.clear(k.key) for k in limiter.current_limits] - return redirect_back(url_for("web.index")) + return redirect_back("web.index") def render_login(username="", password=""): diff --git a/test/Calibre-Web TestSummary_Linux.html b/test/Calibre-Web TestSummary_Linux.html index 031ba52c..49fa93ef 100644 --- a/test/Calibre-Web TestSummary_Linux.html +++ b/test/Calibre-Web TestSummary_Linux.html @@ -37,20 +37,20 @@
Start Time: 2024-02-10 19:51:08
+Start Time: 2024-02-11 21:14:02
Stop Time: 2024-02-11 02:37:31
+Stop Time: 2024-02-12 04:05:52
Duration: 5h 36 min
+Duration: 5h 42 min
Traceback (most recent call last): + File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 501, in test_backup_change_custom_date + self.assertEqual(custom["#value#"], None) +AssertionError: {'__class__': 'datetime.datetime', '__value__': '2023-08-03T00:00:00+00:00'} != None+
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 359, in test_backup_change_custom_float - self.queue_metadata_backup() - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1630, in queue_metadata_backup - self.check_element_on_page((By.ID, "metadata_backup")).click() -AttributeError: 'bool' object has no attribute 'click'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 392, in test_backup_change_custom_int - self.queue_metadata_backup() - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1630, in queue_metadata_backup - self.check_element_on_page((By.ID, "metadata_backup")).click() -AttributeError: 'bool' object has no attribute 'click'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 425, in test_backup_change_custom_rating - self.queue_metadata_backup() - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1630, in queue_metadata_backup - self.check_element_on_page((By.ID, "metadata_backup")).click() -AttributeError: 'bool' object has no attribute 'click'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 452, in test_backup_change_custom_text - self.queue_metadata_backup() - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 1630, in queue_metadata_backup - self.check_element_on_page((By.ID, "metadata_backup")).click() -AttributeError: 'bool' object has no attribute 'click'-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 595, in test_upload_book - self.fill_basic_config({'config_uploading': 1}) - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 399, in fill_basic_config - cls._fill_basic_config(elements) - File "/home/ozzie/Development/calibre-web-test/test/helper_ui.py", line 304, in _fill_basic_config - WebDriverWait(cls.driver, 5).until(EC.presence_of_element_located((By.ID, "config_port"))) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/support/wait.py", line 95, in until - raise TimeoutException(message, screen, stacktrace) -selenium.common.exceptions.TimeoutException: Message: -Stacktrace: -RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8 -WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:191:5 -NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:509:5 -dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16-
Traceback (most recent call last): - File "/home/ozzie/Development/calibre-web-test/test/test_backup_metadata.py", line 39, in tearDownClass - cls.driver.get("http://127.0.0.1:" + PORTS[0]) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 449, in get - self.execute(Command.GET, {"url": url}) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute - self.error_handler.check_response(response) - File "/home/ozzie/Development/calibre-web-test/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response - raise exception_class(message, screen, stacktrace) -selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=connectionFailure&u=http%3A//127.0.0.1%3A8083/&c=UTF-8&d=Firefox%20can%E2%80%99t%20establish%20a%20connection%20to%20the%20server%20at%20127.0.0.1%3A8083. -Stacktrace: -RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8 -WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:191:5 -UnknownError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:800:5 -checkReadyState@chrome://remote/content/marionette/navigate.sys.mjs:58:24 -onNavigation@chrome://remote/content/marionette/navigate.sys.mjs:324:39 -emit@resource://gre/modules/EventEmitter.sys.mjs:154:20 -receiveMessage@chrome://remote/content/marionette/actors/MarionetteEventsParent.sys.mjs:33:25-