From 422e3d2b662315c8bf76a685660be6d37bb2796b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 24 May 2022 12:25:17 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=96=20staging/bugfix=20is=20now=20?= =?UTF-8?q?1.8.2.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index 88c994cb2..306e259e0 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -26,8 +26,8 @@ improve/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev # staging/bugfix is the branch for preparation of the 1.8.1 bugfix release # so are any bug/... branches -staging/bugfix 1.8.1 d2a9aacedacf2b582faca462d6e915f88676a3d5 pep440-dev -bug/.* 1.8.1 d2a9aacedacf2b582faca462d6e915f88676a3d5 pep440-dev +staging/bugfix 1.8.2 260a1aef11432c421246019e25b6b744abbaed60 pep440-dev +bug/.* 1.8.2 260a1aef11432c421246019e25b6b744abbaed60 pep440-dev # staging/maintenance is currently the branch for preparation of 1.8.0rc6 # so is regressionfix/... From dabdd40806e3409f134ab8e276f078e2a02d062b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 4 Aug 2022 10:33:31 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Fix=20another=20ope?= =?UTF-8?q?n=20redirect=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The redirect parameter to the login dialog now gets restricted to local URLs (as detected by unset scheme & netloc) that match a short list of allowed endpoints routes. --- src/octoprint/server/util/__init__.py | 20 +++++++++++++++ src/octoprint/server/views.py | 11 +++++--- tests/server/util/test_util.py | 36 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 tests/server/util/test_util.py diff --git a/src/octoprint/server/util/__init__.py b/src/octoprint/server/util/__init__.py index 3137115d5..157959d53 100644 --- a/src/octoprint/server/util/__init__.py +++ b/src/octoprint/server/util/__init__.py @@ -421,3 +421,23 @@ def require_login(*permissions): ) return None + + +def validate_local_redirect(url, allowed_paths): + """Validates the given local redirect URL against the given allowed paths. + + An `url` is valid for a local redirect if it has neither scheme nor netloc defined, + and its path is one of the given allowed paths. + + Args: + url (str): URL to validate + allowed_paths (List[str]): List of allowed paths, only paths contained + will be considered valid. + + Returns: + bool: Whether the `url` passed validation or not. + """ + from urllib.parse import urlparse + + parsed = urlparse(url) + return parsed.scheme == "" and parsed.netloc == "" and parsed.path in allowed_paths diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index d1db66b26..5757ce6c4 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -8,7 +8,6 @@ import logging import os import re from collections import defaultdict -from urllib.parse import urlparse from flask import ( Response, @@ -39,7 +38,11 @@ from octoprint.server import ( # noqa: F401 preemptiveCache, userManager, ) -from octoprint.server.util import has_permissions, require_login_with +from octoprint.server.util import ( + has_permissions, + require_login_with, + validate_local_redirect, +) from octoprint.settings import settings from octoprint.util import sv, to_bytes, to_unicode from octoprint.util.version import get_python_version_string @@ -173,9 +176,9 @@ def login(): default_redirect_url = request.script_root + url_for("index") redirect_url = request.args.get("redirect", default_redirect_url) + allowed_paths = [url_for("index"), url_for("recovery")] - parsed = urlparse(redirect_url) # check if redirect url is valid - if parsed.scheme != "" or parsed.netloc != "": + if not validate_local_redirect(redirect_url, allowed_paths): _logger.warning( f"Got an invalid redirect URL with the login attempt, misconfiguration or attack attempt: {redirect_url}" ) diff --git a/tests/server/util/test_util.py b/tests/server/util/test_util.py new file mode 100644 index 000000000..f455047eb --- /dev/null +++ b/tests/server/util/test_util.py @@ -0,0 +1,36 @@ +__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" +__copyright__ = "Copyright (C) 2022 The OctoPrint Project - Released under terms of the AGPLv3 License" + +import pytest + + +@pytest.mark.parametrize( + "url,paths,expected", + [ + # various default UI URLs + ("/", ["/", "/recovery/"], True), + ("/?", ["/", "/recovery/"], True), + ("/?l10n=de", ["/", "/recovery/"], True), + ("/?l10n=de&", ["/", "/recovery/"], True), + ("/octoprint/", ["/octoprint/", "/octoprint/recovery/"], True), + # various recovery URLs + ("/recovery/", ["/", "/recovery/"], True), + ("/recovery/?", ["/", "/recovery/"], True), + ("/recovery/?l10n=de", ["/", "/recovery/"], True), + ("/octoprint/recovery/?l10n=de", ["/octoprint/", "/octoprint/recovery/"], True), + # various external URLs + ("http://example.com", ["/", "/recovery/"], False), + ("https://example.com", ["/", "/recovery/"], False), + ("//example.com", ["/", "/recovery/"], False), + ("/\\/\\example.com", ["/", "/recovery/"], False), + (" /\\/\\example.com", ["/", "/recovery/"], False), + ("\\/\\/example.com", ["/", "/recovery/"], False), + (" \\/\\/example.com", ["/", "/recovery/"], False), + # other stuff + ("javascript:alert(document.cookie)", ["/", "/recovery/"], False), + ], +) +def test_validate_local_redirect(url, paths, expected): + from octoprint.server.util import validate_local_redirect + + assert validate_local_redirect(url, paths) == expected From 91ef0c0d99207984c4f4a0ed3551ba5ea1a69d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 9 Aug 2022 13:03:42 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=8C=20Pin=20Flask=20to=202.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flask 2.2 requires werkzeug 2.2 which we can't upgrade to due to flask-login, and the current version pins might be causing issues in the field. TODO for 1.9.0: upgrade werkzeug & flask if possible with flask-login. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a5a4224e1..ece2d5147 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ core_deps = [ "Flask-Assets>=2.0,<3", "Flask-Babel>=2.0,<3", "Flask-Login>=0.5,<0.6", # flask-login doesn't use semver & breaks stuff on minor version increases - "flask>=2,<3", + "flask>=2.1,<2.2", # flask 2.2 requires werkzeug 2.2+ "frozendict>=2.0,<3", "future>=0.18.2,<1", # not really needed anymore, but leaving in for py2/3 compat plugins "markdown>=3.2.2,<4", From 87f4a4e8c967dab147beb6213cbf61cca32bec62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 9 Aug 2022 13:54:24 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=20Preparing=20release=20of=201?= =?UTF-8?q?.8.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SUPPORTERS.md | 18 +++++------------- .../plugins/errortracking/__init__.py | 4 ++-- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/SUPPORTERS.md b/SUPPORTERS.md index 07d92e921..c395fe028 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -10,37 +10,29 @@ thanks to everyone who contributed! * 3DPrinterOS * Al Mucci * Arnljot Arntsen - * Artillery 3D * Ash King * BigTreeTech * Boris Hussein * Brad Jackson - * BuildBee * Calvin Vette * Christian Petropolis * Christian Wolf * Christian Würthner * Christoph Sigrist - * Craig Parker * Creality3D - * David Bounds * DeltaMaker 3D Printers * Dennis Breining * Douglas Floyd * Dr. Frank Wester - * Eric Betts * Ernesto Martinez * Franziska Kunsmann - * George Robles * Greg Holloway * Hog Duske - * Itay Shem-tov * James Mackay * Jeff Green * Jeff Moe * jeffiel * Jeremy Cole - * Joshua Wills * Julian Melo * Justin Kaufman * Kaile Riser @@ -52,13 +44,15 @@ thanks to everyone who contributed! * Lefteris Lertas * LulzBot * Makespace Madrid + * Mark Greenwald * Mark Walker * Matt Van Itallie * Michael Aumock * Mike Kershaw - * Miles Flavel * Mosaic Manufacturing * Norman Jaffe + * Obico + * Ory Weaver * Peopoly * Pete Barnwell * Raise3D @@ -68,17 +62,15 @@ thanks to everyone who contributed! * Richard Michaud * Richard Stocks * Robert Gusek - * Ronald Griehsler * Sean Jensen-Grey * Sebastien Andrivet + * SimplyPrint * Stefan Krister * Steve Dougherty * Steve Thompson - * TH3D - * The Spaghetti Detective * TJ Horner * Trent Shumay * Ulrich Kempken * Yehuda Katz -and 2279 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)! +and 2209 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)! diff --git a/src/octoprint/plugins/errortracking/__init__.py b/src/octoprint/plugins/errortracking/__init__.py index 67ffa2a23..b83c24c27 100644 --- a/src/octoprint/plugins/errortracking/__init__.py +++ b/src/octoprint/plugins/errortracking/__init__.py @@ -18,10 +18,10 @@ from octoprint.util.version import ( ) SENTRY_URL_SERVER = ( - "https://f4265899b96044f3a31e6414c315a0d1@o118517.ingest.sentry.io/1373987" + "https://32fedab787cf4ef0abb9f4fb9060f7c5@o118517.ingest.sentry.io/1373987" ) SENTRY_URL_COREUI = ( - "https://2f33808cb0cb4027afd005c35eebfeb4@o118517.ingest.sentry.io/1374096" + "https://09c57ca82d4047b5a37bb0655ce14187@o118517.ingest.sentry.io/1374096" ) SETTINGS_DEFAULTS = {