Skip to content

Commit 98548e8

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 5978107 commit 98548e8

File tree

1 file changed

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

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,27 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
257257
payload[param] = await resolve_value(value)
258258

259259
# create headers for auth services
260-
headers = {}
260+
auth_headers = {}
261261
for auth_service, token_getter in self.__auth_service_token_getters.items():
262-
headers[self.__get_auth_header(auth_service)] = await resolve_value(
262+
auth_headers[self.__get_auth_header(auth_service)] = await resolve_value(
263263
token_getter
264264
)
265265
for client_header_name, client_header_val in self.__client_headers.items():
266-
headers[client_header_name] = await resolve_value(client_header_val)
266+
auth_headers[client_header_name] = await resolve_value(client_header_val)
267+
268+
# ID tokens contain sensitive user information (claims). Transmitting
269+
# these over HTTP exposes the data to interception and unauthorized
270+
# access. Always use HTTPS to ensure secure communication and protect
271+
# user privacy.
272+
if auth_headers and not self.__url.startswith("https://"):
273+
warn(
274+
"Sending ID token over HTTP. User data may be exposed. Use HTTPS for secure communication."
275+
)
267276

268277
async with self.__session.post(
269278
self.__url,
270279
json=payload,
271-
headers=headers,
280+
headers=auth_headers,
272281
) as resp:
273282
body = await resp.json()
274283
if resp.status < 200 or resp.status >= 300:

0 commit comments

Comments
 (0)