Merge branch 'maintenance' into devel
This commit is contained in:
commit
c76fee7804
9 files changed
+31
-55
No files matched your search
+3
-3
@@ -24,10 +24,10 @@ maintenance 1.9.0 fa2c4680cca0d1d6b46e6c1ed68ceea4d9b79afb pep440-dev
|
||||
fix/.* 1.9.0 fa2c4680cca0d1d6b46e6c1ed68ceea4d9b79afb pep440-dev
|
||||
improve/.* 1.9.0 fa2c4680cca0d1d6b46e6c1ed68ceea4d9b79afb pep440-dev
|
||||
|
||||
# staging/bugfix is the branch for preparation of the 1.8.3 bugfix release
|
||||
# staging/bugfix is the branch for preparation of the 1.8.4 bugfix release
|
||||
# so are any bug/... branches
|
||||
staging/bugfix 1.8.3 87f4a4e8c967dab147beb6213cbf61cca32bec62 pep440-dev
|
||||
bug/.* 1.8.3 87f4a4e8c967dab147beb6213cbf61cca32bec62 pep440-dev
|
||||
staging/bugfix 1.8.4 d0d226f3e0ad0a6436e4f32519bf38a82aa576ca pep440-dev
|
||||
bug/.* 1.8.4 d0d226f3e0ad0a6436e4f32519bf38a82aa576ca pep440-dev
|
||||
|
||||
# staging/maintenance is currently the branch for preparation of 1.8.0rc6
|
||||
# so is regressionfix/...
|
||||
|
||||
@@ -179,8 +179,10 @@ class UserManager(GroupChangeListener):
|
||||
def cleanup_legacy_hashes(self):
|
||||
pass
|
||||
|
||||
def signature_key_for_user(self, username, salt=None):
|
||||
return self.create_password_hash(username, salt=salt)
|
||||
def signature_key_for_user(self, username, secret):
|
||||
return hashlib.sha512(
|
||||
to_bytes(username, encoding="utf-8", errors="replace") + to_bytes(secret)
|
||||
).hexdigest()
|
||||
|
||||
def add_user(self, username, password, active, permissions, groups, overwrite=False):
|
||||
pass
|
||||
@@ -811,14 +813,16 @@ class FilebasedUserManager(UserManager):
|
||||
self._settings.remove(["accessControl", "salt"])
|
||||
self._settings.save()
|
||||
|
||||
def signature_key_for_user(self, username, salt=None):
|
||||
def signature_key_for_user(self, username, secret):
|
||||
if username == "_api":
|
||||
return super().signature_key_for_user(username, secret)
|
||||
if username not in self._users:
|
||||
raise UnknownUser(username)
|
||||
user = self._users[username]
|
||||
|
||||
return hashlib.sha512(
|
||||
to_bytes(username + user._passwordHash, encoding="utf-8", errors="replace")
|
||||
+ to_bytes(salt)
|
||||
+ to_bytes(secret)
|
||||
).hexdigest()
|
||||
|
||||
def change_user_setting(self, username, key, value):
|
||||
|
||||
@@ -4,7 +4,6 @@ __copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms
|
||||
|
||||
import logging
|
||||
import os
|
||||
import tarfile
|
||||
import zipfile
|
||||
from collections import defaultdict
|
||||
|
||||
@@ -141,12 +140,10 @@ def uploadLanguagePack():
|
||||
|
||||
target_path = settings().getBaseFolder("translations")
|
||||
|
||||
if tarfile.is_tarfile(upload_path):
|
||||
_unpack_uploaded_tarball(upload_path, target_path)
|
||||
elif zipfile.is_zipfile(upload_path):
|
||||
if zipfile.is_zipfile(upload_path):
|
||||
_unpack_uploaded_zipfile(upload_path, target_path)
|
||||
else:
|
||||
abort(400, description="Neither zip file nor tarball included")
|
||||
abort(400, description="No zip file included")
|
||||
|
||||
return getInstalledLanguagePacks()
|
||||
|
||||
@@ -181,16 +178,6 @@ def _unpack_uploaded_zipfile(path, target):
|
||||
zip.extractall(target)
|
||||
|
||||
|
||||
def _unpack_uploaded_tarball(path, target):
|
||||
with tarfile.open(path, "r") as tar:
|
||||
# sanity check
|
||||
for info in tar.getmembers():
|
||||
_validate_tar_info(info, target)
|
||||
|
||||
# unpack everything
|
||||
tar.extractall(target)
|
||||
|
||||
|
||||
def _validate_archive_name(name, target):
|
||||
if not os.path.abspath(os.path.join(target, name)).startswith(target + os.path.sep):
|
||||
raise InvalidLanguagePack(f"Provided language pack contains invalid name {name}")
|
||||
@@ -200,11 +187,5 @@ def _validate_zip_info(info, target):
|
||||
_validate_archive_name(info.filename, target)
|
||||
|
||||
|
||||
def _validate_tar_info(info, target):
|
||||
_validate_archive_name(info.name, target)
|
||||
if not (info.isfile() or info.isdir()):
|
||||
raise InvalidLanguagePack("Provided language pack contains invalid file type")
|
||||
|
||||
|
||||
class InvalidLanguagePack(Exception):
|
||||
pass
|
||||
@@ -44,7 +44,7 @@ def loginFromApiKeyRequestHandler():
|
||||
if loginUserFromApiKey():
|
||||
_flask.g.login_via_apikey = True
|
||||
except InvalidApiKeyException:
|
||||
_flask.abort(403)
|
||||
_flask.abort(403, "Invalid API key")
|
||||
|
||||
|
||||
def loginFromAuthorizationHeaderRequestHandler():
|
||||
@@ -55,7 +55,7 @@ def loginFromAuthorizationHeaderRequestHandler():
|
||||
if loginUserFromAuthorizationHeader():
|
||||
_flask.g.login_via_header = True
|
||||
except InvalidApiKeyException:
|
||||
_flask.abort(403)
|
||||
_flask.abort(403, "Invalid credentials in Basic Authorization header")
|
||||
|
||||
|
||||
class InvalidApiKeyException(Exception):
|
||||
@@ -71,7 +71,7 @@ def loginUserFromApiKey():
|
||||
user = get_user_for_apikey(apikey, remote_address=remote_address)
|
||||
if user is None:
|
||||
# invalid API key = no API key
|
||||
return False
|
||||
raise InvalidApiKeyException("Invalid API key")
|
||||
|
||||
return loginUser(user, login_mechanism="apikey")
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ def validate_csrf_tokens(cookie, header):
|
||||
|
||||
def add_csrf_cookie(response):
|
||||
if not isinstance(response, OctoPrintFlaskResponse):
|
||||
return
|
||||
response = flask.make_response(response)
|
||||
|
||||
token = generate_csrf_token()
|
||||
response.set_cookie("csrf_token", token, httponly=False)
|
||||
@@ -77,8 +77,9 @@ def validate_csrf_request(request):
|
||||
# Irrelevant method for CSRF, bypass
|
||||
return
|
||||
|
||||
if getattr(flask.g, "login_via_apikey", False):
|
||||
# API key authorization, bypass
|
||||
session = getattr(flask, "session", {})
|
||||
if len(session) == 0 or session.get("login_mechanism") == "apikey":
|
||||
# empty session, not a browser context
|
||||
return
|
||||
|
||||
if is_exempt(request.endpoint):
|
||||
|
||||
@@ -468,7 +468,7 @@ def encode_remember_me_cookie(value):
|
||||
name = value.split("|")[0]
|
||||
try:
|
||||
remember_key = userManager.signature_key_for_user(
|
||||
name, salt=current_app.config["SECRET_KEY"]
|
||||
name, current_app.config["SECRET_KEY"]
|
||||
)
|
||||
timestamp = datetime.utcnow().timestamp()
|
||||
return encode_cookie(f"{name}|{timestamp}", key=remember_key)
|
||||
@@ -488,7 +488,7 @@ def decode_remember_me_cookie(value):
|
||||
try:
|
||||
# valid signature?
|
||||
signature_key = userManager.signature_key_for_user(
|
||||
name, salt=current_app.config["SECRET_KEY"]
|
||||
name, current_app.config["SECRET_KEY"]
|
||||
)
|
||||
cookie = decode_cookie(value, key=signature_key)
|
||||
if cookie:
|
||||
@@ -1947,11 +1947,12 @@ class OctoPrintJsonProvider(flask.json.provider.DefaultJSONProvider):
|
||||
def session_signature(user, session):
|
||||
from octoprint.server import userManager
|
||||
|
||||
key = userManager.signature_key_for_user(user, salt=current_app.config["SECRET_KEY"])
|
||||
key = userManager.signature_key_for_user(user, current_app.config["SECRET_KEY"])
|
||||
return hmac.new(
|
||||
key.encode("utf-8"), session.encode("utf-8"), hashlib.sha512
|
||||
).hexdigest()
|
||||
|
||||
|
||||
def validate_session_signature(sig, user, session):
|
||||
return hmac.compare_digest(sig, session_signature(user, session))
|
||||
user_sig = session_signature(user, session)
|
||||
return len(user_sig) == len(sig) and hmac.compare_digest(sig, user_sig)
|
||||
@@ -225,8 +225,7 @@ def login():
|
||||
_logger.exception("Error processing theming CSS, ignoring")
|
||||
|
||||
resp = make_response(render_template("login.jinja2", **render_kwargs))
|
||||
add_csrf_cookie(resp)
|
||||
return resp
|
||||
return add_csrf_cookie(resp)
|
||||
|
||||
|
||||
@app.route("/recovery")
|
||||
@@ -258,8 +257,7 @@ def recovery():
|
||||
_logger.exception("Error adding backup upload size info, ignoring")
|
||||
|
||||
resp = make_response(render_template("recovery.jinja2", **render_kwargs))
|
||||
add_csrf_cookie(resp)
|
||||
return resp
|
||||
return add_csrf_cookie(resp)
|
||||
|
||||
|
||||
@app.route("/cached.gif")
|
||||
@@ -700,8 +698,7 @@ def index():
|
||||
if response is None:
|
||||
return abort(404)
|
||||
|
||||
add_csrf_cookie(response)
|
||||
return response
|
||||
return add_csrf_cookie(response)
|
||||
|
||||
|
||||
def _get_render_kwargs(templates, plugin_names, plugin_vars, now):
|
||||
|
||||
@@ -41,15 +41,7 @@ $(function () {
|
||||
self.translationUploadFilename = ko.observable();
|
||||
self.invalidTranslationArchive = ko.pureComputed(function () {
|
||||
var name = self.translationUploadFilename();
|
||||
return (
|
||||
name !== undefined &&
|
||||
!(
|
||||
_.endsWith(name.toLocaleLowerCase(), ".zip") ||
|
||||
_.endsWith(name.toLocaleLowerCase(), ".tar.gz") ||
|
||||
_.endsWith(name.toLocaleLowerCase(), ".tgz") ||
|
||||
_.endsWith(name.toLocaleLowerCase(), ".tar")
|
||||
)
|
||||
);
|
||||
return name !== undefined && !_.endsWith(name.toLocaleLowerCase(), ".zip");
|
||||
});
|
||||
self.enableTranslationUpload = ko.pureComputed(function () {
|
||||
var name = self.translationUploadFilename();
|
||||
|
||||
@@ -124,13 +124,13 @@
|
||||
<div class="input-prepend span9">
|
||||
<span class="btn fileinput-button">
|
||||
<span>{{ _('Browse...') }}</span>
|
||||
<input id="settings_appearance_managelanguagesdialog_upload" type="file" name="file" accept=".zip,.tar.gz,.tgz,.tar" data-url="{{ url_for("api.uploadLanguagePack") }}">
|
||||
<input id="settings_appearance_managelanguagesdialog_upload" type="file" name="file" accept=".zip" data-url="{{ url_for("api.uploadLanguagePack") }}">
|
||||
</span>
|
||||
<span class="add-on add-on-limited text-left" data-bind="text: translationUploadFilename, attr: {title: translationUploadFilename}"></span>
|
||||
</div>
|
||||
<button id="settings_appearance_managelanguagesdialog_upload_start" class="btn btn-primary span3" data-bind="enable: enableTranslationUpload, css: {disabled: !enableTranslationUpload()}, click: function(){}">{{ _('Upload') }}</button>
|
||||
</div>
|
||||
<span class="help-block" data-bind="visible: invalidTranslationArchive">{{ _('This does not look like a valid language pack. Valid language packs should be either zip files or tarballs and have the extension ".zip", ".tar.gz", ".tgz" or ".tar"') }}</span>
|
||||
<span class="help-block" data-bind="visible: invalidTranslationArchive">{{ _('This does not look like a valid language pack. Valid language packs should be zip files and have the extension ".zip"') }}</span>
|
||||
</form>
|
||||
|
||||
<small>{{ _('Please note that you will have to reload the page in order for any newly added language packs to become available.') }}</small>
|
||||
|
||||
Reference in new issue
Block a user