Skip to content

Require roots for all CLI tools #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 2, 2025
Merged

Require roots for all CLI tools #101

merged 6 commits into from
May 2, 2025

Conversation

jakemac53
Copy link
Contributor

Updates all CLI tools to only allow them to be ran under one of the client specified roots.

  • If paths are specified, those also must not escape the roots.
  • Make roots not required any longer, use the client specified roots by default for all tools.
  • Create some shared constants for argument names and a shared function to create the schemas for the roots parameters.

@jakemac53
Copy link
Contributor Author

cc @domesticmouse I know you said you were giving a demo soon, this could affect that so I will wait to land this until your demo is done, please let me know when its safe :)

Copy link

github-actions bot commented May 1, 2025

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

/// Returns whether or not [rootUri] is an allowed root, either exactly matching
/// or under on of the [knownRoots].
bool _isAllowedRoot(String rootUri, List<Root> knownRoots) =>
knownRoots.any((knownRoot) => knownRoot.uri.startsWith(rootUri));
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this check that rootUri.startsWith(knownRoot.uri) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote this to also make sure you can't circumvent it using ../ and added tests

// BSD-style license that can be found in the LICENSE file.

/// A namespace for all the parameter names.
extension ParameterNames on Never {
Copy link
Contributor

Choose a reason for hiding this comment

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

why extend Never rather than just creating a new abstract class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extensions are a bit more restricted (can't be implemented/extended etc), and don't create a real type (they disappear at runtime entirely) so they are technically cheaper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note also that static methods on extensions are not actually added to Never either, so this has no impact on the Never type anywhere it appears.

Copy link
Contributor

@kenzieschmoll kenzieschmoll left a comment

Choose a reason for hiding this comment

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

a couple comments but overall lgtm

@jakemac53 jakemac53 merged commit 66c01cc into main May 2, 2025
13 checks passed
@jakemac53 jakemac53 deleted the require-roots branch May 2, 2025 16:11
sigurdm pushed a commit to sigurdm/ai that referenced this pull request May 6, 2025
Updates all CLI tools to only allow them to be ran under one of the client specified roots.

- If paths are specified, those also must not escape the roots.
- Make roots not required any longer, use the client specified roots by default for all tools.
- Create some shared constants for argument names and a shared function to create the schemas for the roots parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants