Skip to content

Commit 095efdc

Browse files
author
Franz646
committed
fix: replace requires_admin with explicit user.is_admin check in delete/export/ignore_list handlers — v4.0.4
requires_admin is not a HomeAssistantView attribute and was silently ignored. All three destructive endpoints now explicitly check: user = request.get('hass_user') if user is None or not user.is_admin: return 403 Using the safer 'is None or not is_admin' shape as suggested by @frenck.
1 parent 1cb996e commit 095efdc

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

custom_components/orphan_cleaner/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
PANEL_ICON = "mdi:broom"
4848

4949
# Versione corrente (usata per cache-busting)
50-
VERSION = "4.0.3"
50+
VERSION = "4.0.4"

custom_components/orphan_cleaner/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"iot_class": "local_push",
1414
"issue_tracker": "https://github.com/Franz646/orphan-cleaner/issues",
1515
"requirements": [],
16-
"version": "4.0.3"
16+
"version": "4.0.4"
1717
}

custom_components/orphan_cleaner/panel_api.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Tutte le route sono registrate tramite HomeAssistantView, che applica
55
l'autenticazione di Home Assistant per default (requires_auth = True).
66
Gli endpoint che leggono o modificano lo stato del registry richiedono
7-
inoltre privilegi di amministratore (requires_admin = True).
7+
inoltre un controllo esplicito su user.is_admin nel handler.
88
"""
99
from __future__ import annotations
1010

@@ -153,13 +153,16 @@ async def get(self, request: web.Request) -> web.Response:
153153
class OrphanCleanerDeleteView(HomeAssistantView):
154154
"""POST /api/orphan_cleaner/delete - elimina le entità specificate. Richiede admin."""
155155

156-
url = "/api/orphan_cleaner/delete"
157-
name = "api:orphan_cleaner:delete"
158-
requires_auth = True
159-
requires_admin = True
156+
url = "/api/orphan_cleaner/delete"
157+
name = "api:orphan_cleaner:delete"
158+
requires_auth = True
160159

161160
async def post(self, request: web.Request) -> web.Response:
162161
hass: HomeAssistant = request.app["hass"]
162+
user = request.get("hass_user")
163+
if user is None or not user.is_admin:
164+
return web.Response(status=403, content_type="application/json",
165+
text='{"error":"Admin privileges required"}')
163166
try:
164167
body = await request.json()
165168
except Exception:
@@ -188,16 +191,19 @@ async def post(self, request: web.Request) -> web.Response:
188191

189192

190193
class OrphanCleanerExportView(HomeAssistantView):
191-
"""POST /api/orphan_cleaner/export - salva un backup JSON. Richiede admin
192-
perché scrive un file nella directory di configurazione."""
194+
"""POST /api/orphan_cleaner/export - salva un backup JSON.
195+
Richiede admin perché scrive un file nella directory di configurazione."""
193196

194-
url = "/api/orphan_cleaner/export"
195-
name = "api:orphan_cleaner:export"
196-
requires_auth = True
197-
requires_admin = True
197+
url = "/api/orphan_cleaner/export"
198+
name = "api:orphan_cleaner:export"
199+
requires_auth = True
198200

199201
async def post(self, request: web.Request) -> web.Response:
200202
hass: HomeAssistant = request.app["hass"]
203+
user = request.get("hass_user")
204+
if user is None or not user.is_admin:
205+
return web.Response(status=403, content_type="application/json",
206+
text='{"error":"Admin privileges required"}')
201207
try:
202208
body = await request.json()
203209
except Exception:
@@ -251,7 +257,7 @@ async def get(self, request: web.Request) -> web.Response:
251257
async def post(self, request: web.Request) -> web.Response:
252258
hass: HomeAssistant = request.app["hass"]
253259
user = request.get("hass_user")
254-
if user is not None and not user.is_admin:
260+
if user is None or not user.is_admin:
255261
return web.Response(status=403, content_type="application/json",
256262
text='{"error":"Admin privileges required"}')
257263
try:

0 commit comments

Comments
 (0)