Skip to content

Commit 5ff4b7b

Browse files
committed
fix!: Warn about https only during tool initialization
1 parent 0f45b69 commit 5ff4b7b

File tree

1 file changed

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

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ def __init__(
119119
# map of client headers to their value/callable/coroutine
120120
self.__client_headers = client_headers
121121

122+
# ID tokens contain sensitive user information (claims). Transmitting
123+
# these over HTTP exposes the data to interception and unauthorized
124+
# access. Always use HTTPS to ensure secure communication and protect
125+
# user privacy.
126+
if (
127+
required_authn_params or required_authz_tokens or client_headers
128+
) and not self.__url.startswith("https://"):
129+
warn(
130+
"Sending ID token over HTTP. User data may be exposed. Use HTTPS for secure communication."
131+
)
132+
122133
@property
123134
def _name(self) -> str:
124135
return self.__name__
@@ -246,27 +257,18 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
246257
payload[param] = await resolve_value(value)
247258

248259
# create headers for auth services
249-
auth_headers = {}
260+
headers = {}
250261
for auth_service, token_getter in self.__auth_service_token_getters.items():
251-
auth_headers[self.__get_auth_header(auth_service)] = await resolve_value(
262+
headers[self.__get_auth_header(auth_service)] = await resolve_value(
252263
token_getter
253264
)
254265
for client_header_name, client_header_val in self.__client_headers.items():
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-
)
266+
headers[client_header_name] = await resolve_value(client_header_val)
265267

266268
async with self.__session.post(
267269
self.__url,
268270
json=payload,
269-
headers=auth_headers,
271+
headers=headers,
270272
) as resp:
271273
body = await resp.json()
272274
if resp.status < 200 or resp.status >= 300:

0 commit comments

Comments
 (0)