From d96be4628c5eef99b31532b631930a27a41df6fa Mon Sep 17 00:00:00 2001 From: Jonas Lejon Date: Wed, 2 Sep 2026 11:38:00 +0200 Subject: [PATCH] Fix the User-Agent header name sent by mp_ua_header() `mp_ua_header()` returned the key `UserAgent`, which is not the HTTP `User-Agent` header, so the MSTICPy identifier was sent under a header name nothing reads while httpx filled in the real `User-Agent` with its own default. Outbound requests were seen by services as `python-httpx/`. `azure_monitor_driver` read `mp_ua_header()["UserAgent"]` to obtain the string for `UserAgentPolicy`. It now uses the exported `MSTICPY_USER_AGENT` constant, which is what it wants and is independent of the header name. Providers that declare their own `User-Agent` are unaffected: the guard in `http_provider.py` still leaves them alone, and now works as written. --- msticpy/common/utility/package.py | 2 +- msticpy/data/drivers/azure_monitor_driver.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/msticpy/common/utility/package.py b/msticpy/common/utility/package.py index 73844d0f..4464af82 100644 --- a/msticpy/common/utility/package.py +++ b/msticpy/common/utility/package.py @@ -191,7 +191,7 @@ def _get_mp_ua(): @export def mp_ua_header() -> dict[str, str]: """Return headers dict for MSTICPy User Agent.""" - return {"UserAgent": _get_mp_ua()} + return {"User-Agent": _get_mp_ua()} @export diff --git a/msticpy/data/drivers/azure_monitor_driver.py b/msticpy/data/drivers/azure_monitor_driver.py index a6176416..568c61ee 100644 --- a/msticpy/data/drivers/azure_monitor_driver.py +++ b/msticpy/data/drivers/azure_monitor_driver.py @@ -43,7 +43,7 @@ from ...common.provider_settings import get_protected_setting from ...common.settings import get_http_proxies, get_http_timeout from ...common.timespan import TimeSpan -from ...common.utility import export, mp_ua_header +from ...common.utility import MSTICPY_USER_AGENT, export, mp_ua_header from ...common.wsconfig import WorkspaceConfig from ..core.query_defns import DataEnvironment from .driver_base import DriverBase, DriverProps, QuerySource @@ -117,7 +117,7 @@ def __init__(self, connection_str: str | None = None, **kwargs): {"list": self._format_list}, ) self._loaded = True - self._ua_policy = UserAgentPolicy(user_agent=mp_ua_header()["UserAgent"]) + self._ua_policy = UserAgentPolicy(user_agent=MSTICPY_USER_AGENT) self._def_timeout = kwargs.get( "timeout", kwargs.get("server_timeout", self._DEFAULT_TIMEOUT) )