Skip to content

Commit 0f45b69

Browse files
committed
feat: Warn on insecure tool invocation with authentication
This change introduces a warning that is displayed immediately before a tool invocation if: 1. The invocation includes an authentication header. 2. The connection is being made over non-secure HTTP. > [!IMPORTANT] The purpose of this warning is to alert the user to the security risk of sending credentials over an unencrypted channel and to encourage the use of HTTPS.
1 parent 60a45df commit 0f45b69

File tree

1 file changed

+14
-4
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+14
-4
lines changed

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from inspect import Signature
1717
from types import MappingProxyType
1818
from typing import Any, Callable, Coroutine, Mapping, Optional, Sequence, Union
19+
from warnings import warn
1920

2021
from aiohttp import ClientSession
2122

@@ -245,18 +246,27 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
245246
payload[param] = await resolve_value(value)
246247

247248
# create headers for auth services
248-
headers = {}
249+
auth_headers = {}
249250
for auth_service, token_getter in self.__auth_service_token_getters.items():
250-
headers[self.__get_auth_header(auth_service)] = await resolve_value(
251+
auth_headers[self.__get_auth_header(auth_service)] = await resolve_value(
251252
token_getter
252253
)
253254
for client_header_name, client_header_val in self.__client_headers.items():
254-
headers[client_header_name] = await resolve_value(client_header_val)
255+
auth_headers[client_header_name] = await resolve_value(client_header_val)
256+
257+
# ID tokens contain sensitive user information (claims). Transmitting
258+
# these over HTTP exposes the data to interception and unauthorized
259+
# access. Always use HTTPS to ensure secure communication and protect
260+
# user privacy.
261+
if auth_headers and not self.__url.startswith("https://"):
262+
warn(
263+
"Sending ID token over HTTP. User data may be exposed. Use HTTPS for secure communication."
264+
)
255265

256266
async with self.__session.post(
257267
self.__url,
258268
json=payload,
259-
headers=headers,
269+
headers=auth_headers,
260270
) as resp:
261271
body = await resp.json()
262272
if resp.status < 200 or resp.status >= 300:

0 commit comments

Comments
 (0)