🥅 Prevent assignment of dangerous permissions to guests
If we don't, chances are high someone will happily assign the admin group as a subgroup to the guest group and then publicly expose their instance on the internet, thus completely defeating the purpose of making access control mandatory. We'll also automatically sanitize such configurations now but log a warning. I don't see a better way to protect the innocent, sorry.
This commit is contained in:
1 parent
e7e731800b
commit
f2ed1ebc74
5 files changed
+82
-11
No files matched your search
@@ -288,7 +288,7 @@ class FilebasedGroupManager(GroupManager):
|
||||
):
|
||||
permissions.append(permission)
|
||||
|
||||
subgroups = attributes.get("subgroups", [])
|
||||
subgroups = self._to_groups(*attributes.get("subgroups", []))
|
||||
|
||||
group = Group(
|
||||
key,
|
||||
@@ -301,6 +301,16 @@ class FilebasedGroupManager(GroupManager):
|
||||
changeable=changeable,
|
||||
toggleable=toggleable,
|
||||
)
|
||||
|
||||
if key == GUEST_GROUP and (
|
||||
len(group.permissions) != len(permissions)
|
||||
or len(group.subgroups) != len(subgroups)
|
||||
):
|
||||
self._logger.warning(
|
||||
"Dangerous permissions and/or subgroups stripped from guests group"
|
||||
)
|
||||
self._dirty = True
|
||||
|
||||
self._groups[key] = group
|
||||
|
||||
for group in self._groups.values():
|
||||
@@ -532,6 +542,16 @@ class Group(object):
|
||||
changeable=True,
|
||||
toggleable=True,
|
||||
):
|
||||
if permissions is None:
|
||||
permissions = []
|
||||
if subgroups is None:
|
||||
subgroups = []
|
||||
|
||||
if key == GUEST_GROUP:
|
||||
# guests may not have any dangerous permissions
|
||||
permissions = list(filter(lambda p: not p.dangerous, permissions))
|
||||
subgroups = list(filter(lambda g: not g.dangerous, subgroups))
|
||||
|
||||
self._key = key
|
||||
self._name = name
|
||||
self._description = description
|
||||
@@ -556,6 +576,7 @@ class Group(object):
|
||||
"removable": self._removable,
|
||||
"changeable": self._changeable,
|
||||
"toggleable": self._toggleable,
|
||||
"dangerous": self.dangerous,
|
||||
}
|
||||
|
||||
@property
|
||||
@@ -580,6 +601,12 @@ class Group(object):
|
||||
def is_toggleable(self):
|
||||
return self._toggleable
|
||||
|
||||
@property
|
||||
def dangerous(self):
|
||||
return any(map(lambda p: p.dangerous, self._permissions)) or any(
|
||||
map(lambda g: g.dangerous, self._subgroups)
|
||||
)
|
||||
|
||||
def add_permissions_to_group(self, permissions):
|
||||
"""Adds a list of permissions to a group"""
|
||||
if not self.is_changeable():
|
||||
@@ -591,6 +618,10 @@ class Group(object):
|
||||
|
||||
assert all(map(lambda p: isinstance(p, OctoPrintPermission), permissions))
|
||||
|
||||
if self.key == GUEST_GROUP:
|
||||
# don't allow dangerous permissions on the guests group
|
||||
permissions = list(filter(lambda p: not p.dangerous, permissions))
|
||||
|
||||
dirty = False
|
||||
for permission in permissions:
|
||||
if permissions not in self.permissions:
|
||||
@@ -629,6 +660,10 @@ class Group(object):
|
||||
|
||||
assert all(map(lambda g: isinstance(g, Group), subgroups))
|
||||
|
||||
if self.key == GUEST_GROUP:
|
||||
# don't allow dangerous subgroups on the guests group
|
||||
subgroups = list(filter(lambda g: not g.dangerous, subgroups))
|
||||
|
||||
dirty = False
|
||||
for group in subgroups:
|
||||
if group.is_toggleable() and group not in self._subgroups:
|
||||
@@ -639,7 +674,6 @@ class Group(object):
|
||||
|
||||
def remove_subgroups_from_group(self, subgroups):
|
||||
"""Removes a list of subgroups from a group"""
|
||||
"""Adds a list of subgroups to a group"""
|
||||
if not self.is_changeable():
|
||||
raise GroupCantBeChanged(self.key)
|
||||
|
||||
@@ -677,7 +711,7 @@ class Group(object):
|
||||
|
||||
@property
|
||||
def subgroups(self):
|
||||
return filter(lambda g: g is not None, self._subgroups)
|
||||
return list(filter(lambda g: g is not None, self._subgroups))
|
||||
|
||||
@property
|
||||
def needs(self):
|
||||
|
||||
@@ -69,6 +69,10 @@ class OctoPrintPermission(Permission):
|
||||
def key(self, value):
|
||||
self._key = value
|
||||
|
||||
@property
|
||||
def dangerous(self):
|
||||
return self._dangerous
|
||||
|
||||
@property
|
||||
def default_groups(self):
|
||||
return self._default_groups
|
||||
|
||||
@@ -4,6 +4,9 @@ $(function () {
|
||||
|
||||
access.loginState = parameters[0];
|
||||
|
||||
var GROUP_ADMINS = "admins";
|
||||
var GROUP_GUESTS = "guests";
|
||||
|
||||
//~~ Users ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
access.users = (function () {
|
||||
@@ -43,6 +46,9 @@ $(function () {
|
||||
}),
|
||||
apikey: ko.observable(undefined),
|
||||
active: ko.observable(undefined),
|
||||
permissionSelectable: function (permission) {
|
||||
return true;
|
||||
},
|
||||
permissionSelected: function (permission) {
|
||||
var index = self.editor.permissions().indexOf(permission);
|
||||
return index >= 0;
|
||||
@@ -86,7 +92,13 @@ $(function () {
|
||||
self.editor.password().trim() &&
|
||||
!self.editor.passwordMismatch()))
|
||||
);
|
||||
})
|
||||
}),
|
||||
dangerRestricted: function () {
|
||||
return false;
|
||||
},
|
||||
dangerRestrictedText: gettext(
|
||||
"This user may not have dangerous permissions."
|
||||
)
|
||||
};
|
||||
|
||||
self.userEditorDialog = undefined;
|
||||
@@ -395,6 +407,10 @@ $(function () {
|
||||
permissions: ko.observableArray([]),
|
||||
subgroups: ko.observableArray([]),
|
||||
default: ko.observable(false),
|
||||
permissionSelectable: function (permission) {
|
||||
// guests may not get dangerous permissions
|
||||
return self.editor.key() !== GROUP_GUESTS || !permission.dangerous;
|
||||
},
|
||||
permissionSelected: function (permission) {
|
||||
var index = self.editor.permissions().indexOf(permission);
|
||||
return index >= 0;
|
||||
@@ -409,6 +425,13 @@ $(function () {
|
||||
}
|
||||
self.editor.permissions(permissions);
|
||||
},
|
||||
subgroupSelectable: function (subgroup) {
|
||||
// guests may not get dangerous subgroups
|
||||
return (
|
||||
self.editor.key() !== subgroup.key &&
|
||||
(self.editor.key() !== GROUP_GUESTS || !subgroup.dangerous)
|
||||
);
|
||||
},
|
||||
subgroupSelected: function (subgroup) {
|
||||
var index = self.editor.subgroups().indexOf(subgroup);
|
||||
return index >= 0;
|
||||
@@ -431,7 +454,13 @@ $(function () {
|
||||
confirm: undefined,
|
||||
valid: ko.pureComputed(function () {
|
||||
return self.editor.name() && self.editor.name().trim();
|
||||
})
|
||||
}),
|
||||
dangerRestricted: function () {
|
||||
return self.editor.key() === GROUP_GUESTS;
|
||||
},
|
||||
dangerRestrictedText: gettext(
|
||||
"This group may not have dangerous permissions or subgroups."
|
||||
)
|
||||
};
|
||||
|
||||
self.groupEditorDialog = undefined;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<p data-bind="visible: $parent.editor.dangerRestricted(), text: $parent.editor.dangerRestrictedText"></p>
|
||||
|
||||
<table class="table table-condensed table-hover settings_accesscontrol_permissions_list">
|
||||
<tbody data-bind="foreach: permissionList()">
|
||||
<tr>
|
||||
<td class="settings_accesscontrol_permissions_list_checkbox"><input type="checkbox" data-bind="checkedValue: key, checked: $parents[1].editor.permissions"></td>
|
||||
<td class="settings_accesscontrol_permissions_list_name" style="cursor: pointer" data-bind="click: function() { $parents[1].editor.togglePermission($data.key) }, attr: {title: description}">
|
||||
<span class="name" data-bind="text: name, style: { fontWeight: ($parents[1].editor.permissionSelected($data.key)) ? 'bold' : 'normal' }"></span> <span class="label label-info" data-bind="visible: typeof(plugin) !== 'undefined'">{{ _('Plugin') }}</span> <span class="label label-important" data-bind="visible: dangerous">{{ _('Warning') }}</span><br>
|
||||
<td class="settings_accesscontrol_permissions_list_checkbox"><input type="checkbox" data-bind="checkedValue: key, checked: $parents[1].editor.permissions, enable: $parents[1].editor.permissionSelectable($data)"></td>
|
||||
<td class="settings_accesscontrol_permissions_list_name" style="cursor: pointer" data-bind="click: function() { if ($parents[1].editor.permissionSelectable($data)) { $parents[1].editor.togglePermission($data.key) } }, attr: {title: description}">
|
||||
<span class="name" data-bind="text: name, style: { fontWeight: ($parents[1].editor.permissionSelected($data.key)) ? 'bold' : 'normal' }"></span> <span class="label label-info" data-bind="visible: typeof(plugin) !== 'undefined'">{{ _('Plugin') }}</span> <span class="label label-important" data-bind="visible: dangerous">{{ _('Dangerous') }}</span><br>
|
||||
<small class="description muted" data-bind="text: description"></small>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<p data-bind="visible: $parent.editor.dangerRestricted(), text: $parent.editor.dangerRestrictedText"></p>
|
||||
|
||||
<table class="table table-condensed table-hover settings_accesscontrol_groups_list">
|
||||
<tbody data-bind="foreach: groupsList()">
|
||||
<tr>
|
||||
<td class="settings_accesscontrol_subgroups_list_checkbox"><input type="checkbox" data-bind="checkedValue: key, checked: $parents[1].editor.subgroups, enable: toggleable"></td>
|
||||
<td class="settings_accesscontrol_subgroups_list_name" style="cursor: pointer" data-bind="click: function() { if ($data.toggleable) { $parents[1].editor.toggleSubgroup($data.key) } }, attr: {title: description}">
|
||||
<span class="name" data-bind="text: name, style: { fontWeight: ($parents[1].editor.subgroupSelected($data.name)) ? 'bold' : 'normal' }"></span> <small class="label label-info" data-bind="visible: !$data.toggleable" title="{{ _('Fixed groups can\'t be added or removed to other groups.')|edq }}">{{ _('Fixed') }}</small><br>
|
||||
<td class="settings_accesscontrol_subgroups_list_checkbox"><input type="checkbox" data-bind="checkedValue: key, checked: $parents[1].editor.subgroups, enable: toggleable && $parents[1].editor.subgroupSelectable($data)"></td>
|
||||
<td class="settings_accesscontrol_subgroups_list_name" style="cursor: pointer" data-bind="click: function() { if ($data.toggleable && $parents[1].editor.subgroupSelectable($data)) { $parents[1].editor.toggleSubgroup($data.key) } }, attr: {title: description}">
|
||||
<span class="name" data-bind="text: name, style: { fontWeight: ($parents[1].editor.subgroupSelected($data.name)) ? 'bold' : 'normal' }"></span> <small class="label label-info" data-bind="visible: !$data.toggleable" title="{{ _('Fixed groups can\'t be added or removed to other groups.')|edq }}">{{ _('Fixed') }}</small> <span class="label label-important" data-bind="visible: dangerous">{{ _('Dangerous') }}</span><br>
|
||||
<small class="description" data-bind="text: description"></small><br>
|
||||
<small class="permissions muted" data-bind="text: $parents[1].editor.joinedGroupPermissions($data)"></small>
|
||||
</td>
|
||||
|
||||
Reference in new issue
Block a user