Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Conversation

@valtzu
Copy link
Contributor

@valtzu valtzu commented Jul 7, 2025

Resolves #360

@valtzu valtzu force-pushed the tools-security branch 2 times, most recently from 32b5a03 to 8a0aa6c Compare July 7, 2025 20:20
@valtzu valtzu force-pushed the tools-security branch 4 times, most recently from 4504d93 to d75c01e Compare July 7, 2025 20:42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the Symfony one instead? it's basically the same code besides Tool as a subject - but I can't spot where you need that

Copy link
Contributor Author

@valtzu valtzu Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would mean requiring symfony/security-http instead of just symfony/security-core, and that pulls in a lot of dependencies, f.e. symfony/http-foundation and symfony/http-kernel.

Of course since it's an optional dependency, maybe that's ok? And in practice I think most people use this library with the bundle & likely have full Symfony setup anyway so 🤷


it's basically the same code besides Tool as a subject

it's about what arguments the Closure gets. If we use the built-in IsGranted, then should we provide Request object to the callback like the typehint says?

Also it could be misleading that an expression in a single #[IsGranted] attribute would get different parameters for evaluation depending on the context:

  • symfony http request: ['request' => ...,' 'args' => ...]
  • php-llm tool call: ['tool' => ...,' 'args' => ...]

Do you have a take on this @OskarStark ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, yea, reusing the "original" one is not a great idea - you're right.
it's just confusing since I compared it to the other one and the controller is also not part of the attribute payload, but if you're sure the tool itself should be part of the payload - fair enough. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, the controller is part of the request's attributes

Copy link
Contributor Author

@valtzu valtzu Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess more analogous to Request would be a ToolCall instance, but for some reason I didn't include it in the ToolCallArgumentsResolved event 🤔

EDIT: the reason was that the event already contains the denormalized arguments & tool metadata, and I didn't see a point of including a structure that includes normalized args in addition

Copy link
Contributor

@OskarStark OskarStark Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also not reuse it and maybe use a more tailored name like IsGrantedTool ?

@valtzu
Copy link
Contributor Author

valtzu commented Jul 10, 2025

A slight security concern: this library does not depend on symfony/event-dispatcher – so we cannot really create an event dispatcher & attach the listener by default in case no dispatcher provided. This means that someone could be using the #[IsGrantedTool] attribute and think it's doing access control, while in reality it's not doing anything without the event dispatcher that has the listener attached.

@OskarStark
Copy link
Contributor

OskarStark commented Jul 10, 2025

If the class is not available we can throw an exception, no? "For using.... EventDispatcher is needed, Try running composer require ...." like Symfony is doing it

@valtzu
Copy link
Contributor Author

valtzu commented Jul 10, 2025

I tried adding the check directly to the top of the IsGrantedTool file, but then realized it does not get executed before $attr->newInstance() call in the listener.

Can't think of any place except the toolbox itself where you could check it, and if you do, then it kinda defeats the purpose of using events to decouple logic/domains

@valtzu valtzu changed the title feat: Add #[IsGranted] for tool access control feat: Add #[IsGrantedTool] for tool access control Jul 10, 2025
@chr-hertel
Copy link
Member

We have the same issue with the #[AsEventListener] which only works in context of Symfony's DIC, right?

I feel like this feature is relying quite a lot on the infrastructure the Symfony framework is providing and therefore should go to the bundle instead. WDYT?

@valtzu
Copy link
Contributor Author

valtzu commented Jul 10, 2025

should go to the bundle

Sounds good to me

@valtzu valtzu closed this Jul 12, 2025
chr-hertel added a commit to symfony/ai that referenced this pull request Jul 14, 2025
…l (valtzu)

This PR was merged into the main branch.

Discussion
----------

[AIBundle] Add `#[IsGrantedTool]` for tool access control

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| Docs?         | yes
| Issues        | Fix php-llm/llm-chain#360
| License       | MIT

Add `#[IsGrantedTool]` attribute for tool access control with similar behavior as `#[IsGranted]` in `symfony/security-http`.

Moved from php-llm/llm-chain#382

Commits
-------

40761da [AIBundle] Add `#[IsGrantedTool]` for tool access control
symfony-splitter pushed a commit to symfony/ai-bundle that referenced this pull request Jul 14, 2025
…l (valtzu)

This PR was merged into the main branch.

Discussion
----------

[AIBundle] Add `#[IsGrantedTool]` for tool access control

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| Docs?         | yes
| Issues        | Fix php-llm/llm-chain#360
| License       | MIT

Add `#[IsGrantedTool]` attribute for tool access control with similar behavior as `#[IsGranted]` in `symfony/security-http`.

Moved from php-llm/llm-chain#382

Commits
-------

40761da [AIBundle] Add `#[IsGrantedTool]` for tool access control
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool access control

3 participants