Skip to content

Commit 7dbf087

Browse files
authored
fix(toolbox-core)!: Throw PermissionError on unauthenticated tool invocation (#233)
* chore: Add unit test cases * chore: Delint * 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. * fix!: Warn about https only during tool initialization * fix!: Make unauth call error message as PermissionError * chore: Fix tests
1 parent aa69aab commit 7dbf087

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
239239
for s in self.__required_authn_params.values():
240240
req_auth_services.update(s)
241241
req_auth_services.update(self.__required_authz_tokens)
242-
raise ValueError(
242+
raise PermissionError(
243243
f"One or more of the following authn services are required to invoke this tool"
244244
f": {','.join(req_auth_services)}"
245245
)

packages/toolbox-core/tests/test_e2e.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def test_run_tool_no_auth(self, toolbox: ToolboxClient):
147147
"""Tests running a tool requiring auth without providing auth."""
148148
tool = await toolbox.load_tool("get-row-by-id-auth")
149149
with pytest.raises(
150-
Exception,
150+
PermissionError,
151151
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
152152
):
153153
await tool(id="2")
@@ -188,7 +188,7 @@ async def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxClient):
188188
"""Tests running a tool with a param requiring auth, without auth."""
189189
tool = await toolbox.load_tool("get-row-by-email-auth")
190190
with pytest.raises(
191-
ValueError,
191+
PermissionError,
192192
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
193193
):
194194
await tool()

packages/toolbox-core/tests/test_sync_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def test_auth_with_load_tool_fail_no_token(
541541

542542
tool = sync_client.load_tool(tool_name_auth)
543543
with pytest.raises(
544-
ValueError,
544+
PermissionError,
545545
match="One or more of the following authn services are required to invoke this tool: my-auth-service",
546546
):
547547
tool(argA=15, argB=True)

packages/toolbox-core/tests/test_sync_e2e.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_run_tool_no_auth(self, toolbox: ToolboxSyncClient):
129129
"""Tests running a tool requiring auth without providing auth."""
130130
tool = toolbox.load_tool("get-row-by-id-auth")
131131
with pytest.raises(
132-
Exception,
132+
PermissionError,
133133
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
134134
):
135135
tool(id="2")
@@ -156,7 +156,7 @@ def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxSyncClient):
156156
"""Tests running a tool with a param requiring auth, without auth."""
157157
tool = toolbox.load_tool("get-row-by-email-auth")
158158
with pytest.raises(
159-
ValueError,
159+
PermissionError,
160160
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
161161
):
162162
tool()

0 commit comments

Comments
 (0)