-
Notifications
You must be signed in to change notification settings - Fork 79
Add AWS Bedrock as an alternative API provider #112
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
Open
shivamtiwari3
wants to merge
3
commits into
ankitvgupta:main
Choose a base branch
from
shivamtiwari3:feature/aws-bedrock-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import type { HookCallback } from "@anthropic-ai/claude-agent-sdk"; | ||
| import type { CliToolConfig } from "../../../shared/types"; | ||
|
|
||
| /** | ||
| * Characters permitted in a CLI tool command string. | ||
| * | ||
| * An allowlist is fundamentally more secure than a blocklist: instead of | ||
| * enumerating known-dangerous characters (and inevitably missing some), | ||
| * we explicitly permit only characters that are safe in shell arguments. | ||
| * | ||
| * Permitted: letters, digits, spaces, hyphens, underscores, dots, forward | ||
| * slashes (paths), colons, equals, commas, @, tildes, square brackets, and | ||
| * single/double quotes (safe without $, `, or \ which are not in the set). | ||
| * | ||
| * Rejected (implicitly, by absence): ; & | ` $ > < ( ) { } \ ! ? and | ||
| * newlines — all of which enable command chaining or shell expansion. | ||
| */ | ||
| const SAFE_COMMAND_PATTERN = /^[a-zA-Z0-9 \-_./\:=,@~[\]"']*$/; | ||
|
|
||
| /** | ||
| * Build a PreToolUse hook that gates Bash commands against the CLI tool allowlist. | ||
| * | ||
| * Returns null if no CLI tools are configured (Bash won't be in the tools list). | ||
| * When active, each Bash invocation is checked: | ||
| * 1. The full command string must match SAFE_COMMAND_PATTERN (allowlist). | ||
| * 2. The base command (first token) must be in the configured CLI tool set. | ||
| */ | ||
| export function buildBashPreToolUseHook( | ||
| cliTools: CliToolConfig[], | ||
| ): { matcher: string; hooks: HookCallback[] } | null { | ||
| const activeCli = cliTools.filter((t) => t.command.trim()); | ||
| if (activeCli.length === 0) return null; | ||
|
|
||
| const allowedCommands = new Set(activeCli.map((t) => t.command.trim())); | ||
|
|
||
| const hook: HookCallback = async (input) => { | ||
| const toolInput = (input as Record<string, unknown>).tool_input as | ||
| | { command?: string } | ||
| | undefined; | ||
| const command = toolInput?.command ?? ""; | ||
|
|
||
| // Reject any character outside the safe allowlist. | ||
| // This closes bypass vectors that a blocklist misses: subshells (()), | ||
| // brace expansion ({}), line continuation (\), history expansion (!), | ||
| // and command substitution ($(), ``). | ||
| if (!SAFE_COMMAND_PATTERN.test(command)) { | ||
| return { | ||
| hookSpecificOutput: { | ||
| hookEventName: "PreToolUse" as const, | ||
| permissionDecision: "deny" as const, | ||
| permissionDecisionReason: | ||
| "Command contains characters not permitted in CLI tool commands. " + | ||
| "Only letters, digits, spaces, and common path/option characters are allowed.", | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| // Extract the base command (first token, stripping any path prefix) | ||
| const firstToken = command.trim().split(/\s+/)[0] ?? ""; | ||
| const baseCommand = firstToken.split("/").pop() ?? firstToken; | ||
|
|
||
| if (allowedCommands.has(baseCommand)) { | ||
| return { | ||
| hookSpecificOutput: { | ||
| hookEventName: "PreToolUse" as const, | ||
| permissionDecision: "allow" as const, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| hookSpecificOutput: { | ||
| hookEventName: "PreToolUse" as const, | ||
| permissionDecision: "deny" as const, | ||
| permissionDecisionReason: | ||
| `Command "${baseCommand}" is not in the allowed CLI tools list. ` + | ||
| `Allowed commands: ${[...allowedCommands].join(", ")}`, | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| return { matcher: "Bash", hooks: [hook] }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.