Skip to content

Commit 384b746

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 4405195 commit 384b746

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
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515

16+
from warnings import warn
1617
import types
1718
from inspect import Signature
1819
from typing import Any, Callable, Coroutine, Mapping, Optional, Sequence, Union
@@ -217,18 +218,27 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
217218
payload[param] = await resolve_value(value)
218219

219220
# create headers for auth services
220-
headers = {}
221+
auth_headers = {}
221222
for auth_service, token_getter in self.__auth_service_token_getters.items():
222-
headers[self.__get_auth_header(auth_service)] = await resolve_value(
223+
auth_headers[self.__get_auth_header(auth_service)] = await resolve_value(
223224
token_getter
224225
)
225226
for client_header_name, client_header_val in self.__client_headers.items():
226-
headers[client_header_name] = await resolve_value(client_header_val)
227+
auth_headers[client_header_name] = await resolve_value(client_header_val)
228+
229+
# ID tokens contain sensitive user information (claims). Transmitting
230+
# these over HTTP exposes the data to interception and unauthorized
231+
# access. Always use HTTPS to ensure secure communication and protect
232+
# user privacy.
233+
if auth_headers and not self.__url.startswith("https://"):
234+
warn(
235+
"Sending ID token over HTTP. User data may be exposed. Use HTTPS for secure communication."
236+
)
227237

228238
async with self.__session.post(
229239
self.__url,
230240
json=payload,
231-
headers=headers,
241+
headers=auth_headers,
232242
) as resp:
233243
body = await resp.json()
234244
if resp.status < 200 or resp.status >= 300:

0 commit comments

Comments
 (0)