-
Notifications
You must be signed in to change notification settings - Fork 60
feat(cli): add Zsh shell integration #349
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| const zshShellInit = `# Infisical automatic command wrapper | ||
| if [[ -o interactive ]]; then | ||
| _infisical_auto_run_prefixes=(npm pnpm bun node) | ||
|
|
||
| _infisical_auto_run_accept_line() { | ||
| local command="${BUFFER%%[[:space:]]*}" | ||
| local prefix | ||
|
|
||
| for prefix in "${_infisical_auto_run_prefixes[@]}"; do | ||
| if [[ "$command" == "$prefix" ]]; then | ||
| BUFFER="infisical run -- $BUFFER" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Knowledge Base Used: |
||
| break | ||
| fi | ||
| done | ||
|
|
||
| zle .accept-line | ||
| } | ||
|
|
||
| zle -N accept-line _infisical_auto_run_accept_line | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a user already has a custom or plugin-provided Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| fi | ||
| ` | ||
|
|
||
| var shellInitCmd = &cobra.Command{ | ||
| Use: "shell-init [zsh]", | ||
| Short: "prints shell integration for automatically injecting secrets", | ||
| Args: cobra.ExactArgs(1), | ||
| DisableFlagsInUseLine: true, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if args[0] != "zsh" { | ||
| return fmt.Errorf("unsupported shell %q, supported shells: zsh", args[0]) | ||
| } | ||
|
|
||
| _, err := fmt.Fprint(cmd.OutOrStdout(), zshShellInit) | ||
| return err | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| RootCmd.AddCommand(shellInitCmd) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestZshShellInit(t *testing.T) { | ||
| for _, expected := range []string{ | ||
| "if [[ -o interactive ]]; then", | ||
| "_infisical_auto_run_prefixes=(npm pnpm bun node)", | ||
| "BUFFER=\"infisical run -- $BUFFER\"", | ||
| "zle .accept-line", | ||
| } { | ||
| if !strings.Contains(zshShellInit, expected) { | ||
| t.Errorf("shell initialization script does not contain %q", expected) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user runs
npm install,pnpm install,bun install, or a Node script in an untrusted project, this unconditional rewrite launches it throughinfisical run, and project-controlled code inherits the injected secrets and can exfiltrate them. How this was verified: The hook routes every matching command through the run path, which overlays fetched secrets onto the launched process environment.Context Used: Flag SSRF risks (source)
Knowledge Base Used:
infisical runSecret Injection Flow