From d747a596961b2a4c201d6c111babae6a7eb6bdae Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 24 Jun 2025 12:10:36 +0200 Subject: [PATCH] Fix CLI/Observer access token property (#5973) The access token token_validation() code in the security middleware potentially accesses the access token property before the Supervisor starts the CLI/Observer plugins, which leads to an KeyError when trying to access the `access_token` property. This change ensures that no key error is raised, but just None is returned. --- supervisor/plugins/cli.py | 5 ++--- supervisor/plugins/observer.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/supervisor/plugins/cli.py b/supervisor/plugins/cli.py index 5ea83ebdd..954089920 100644 --- a/supervisor/plugins/cli.py +++ b/supervisor/plugins/cli.py @@ -6,7 +6,6 @@ Code: https://github.com/home-assistant/plugin-cli from collections.abc import Awaitable import logging import secrets -from typing import cast from awesomeversion import AwesomeVersion @@ -54,9 +53,9 @@ class PluginCli(PluginBase): return self.sys_updater.version_cli @property - def supervisor_token(self) -> str: + def supervisor_token(self) -> str | None: """Return an access token for the Supervisor API.""" - return cast(str, self._data[ATTR_ACCESS_TOKEN]) + return self._data.get(ATTR_ACCESS_TOKEN) @Job( name="plugin_cli_update", diff --git a/supervisor/plugins/observer.py b/supervisor/plugins/observer.py index 428fd3fc4..6c5ab6355 100644 --- a/supervisor/plugins/observer.py +++ b/supervisor/plugins/observer.py @@ -5,7 +5,6 @@ Code: https://github.com/home-assistant/plugin-observer import logging import secrets -from typing import cast import aiohttp from awesomeversion import AwesomeVersion @@ -60,9 +59,9 @@ class PluginObserver(PluginBase): return self.sys_updater.version_observer @property - def supervisor_token(self) -> str: + def supervisor_token(self) -> str | None: """Return an access token for the Observer API.""" - return cast(str, self._data[ATTR_ACCESS_TOKEN]) + return self._data.get(ATTR_ACCESS_TOKEN) @Job( name="plugin_observer_update",