Skip to content
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

Use interactive mode for darwin #26

Closed
wants to merge 2 commits into from

Conversation

snorberhuis
Copy link

This fixes issue #24 . I needed to implement this library for a project and saw this open security issue. Because that project needs to ship I made a fix for it.

I tried to think of a way of testing this but I am ensure how to add an automatic test for it and I see no other tests that test on darwin.

Please let me know if I can make improvements to code style.

}

// Write the command to stdIn.
command := fmt.Sprintf("add-generic-password -U -s %s -a %s -w %s\n", service, username, password)
Copy link
Member

Choose a reason for hiding this comment

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

Hi, I completely lost track of this PR. Sorry about that.

I'm a bit concerned about this because the user input is no longer parameterized meaning you can change the command that is executed here. So it solves one security issue but introduces another, and I'm not sure about the trade off.

Choose a reason for hiding this comment

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

I'm not sure if there exists a Golang version of this but shellescape (https://github.com/xxorax/node-shell-escape/blob/master/shell-escape.js) is pretty robust in protection against injection attacks

Copy link

Choose a reason for hiding this comment

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

Drive-by comment: darwin keychain could probably be switched to use the DLL like this python lib and there wouldn't be any worries about CLI usage.

Copy link

Choose a reason for hiding this comment

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

keybase/go-keychain uses cgo to communicate with the macOS Keychain API in the Security.framework. This also has the benefit of isolating keychain item access to the signed go binary using it (instead of the /usr/bin/security binary).

Copy link
Member

Choose a reason for hiding this comment

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

This would also solve the referenced issue from kooky.

Choose a reason for hiding this comment

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

I'm not sure if there exists a Golang version of this but shellescape (https://github.com/xxorax/node-shell-escape/blob/master/shell-escape.js) is pretty robust in protection against injection attacks

Potentially something like shellescape could work here.

Copy link

Choose a reason for hiding this comment

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

cgo here would make cross-compilation for darwin quite rough.

Copy link

Choose a reason for hiding this comment

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

I'm not sure if there exists a Golang version of this but shellescape (https://github.com/xxorax/node-shell-escape/blob/master/shell-escape.js) is pretty robust in protection against injection attacks

Potentially something like shellescape could work here.

This is input for the security tool not a shell and would likely require a different kind of escaping. I can't test it without access to a macos machine though.

"-i", // start in interactive mode to be able to pass the password using stdIn.
)

stdIn, err := cmd.StdinPipe()
Copy link

@srlehn srlehn Oct 11, 2020

Choose a reason for hiding this comment

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

There is no need for the io import
EOT (0x04 / Ctrl-D) signals EOF (might be unnecessary)
(untested)

command := fmt.Sprintf("add-generic-password -U -s %s -a %s -w %s\n\x04", service, username, password) 
cmd.Stdin = strings.NewReader(command)

@marco-m
Copy link

marco-m commented Sep 11, 2022

@Piccirello is it correct that this PR can be closed, since an alternative implementation to solve the same problem has been merged from PR #65 ?

@Piccirello
Copy link
Contributor

Indeed, this PR is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants