mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 04:16:31 +02:00
Remove DEL characters from password input (#5837)
* Remove DEL characters from password input iTerm password manager sends \x03\0x7f before sending a password from its password manager to make sure the password is not being echoed to the screen. Unfortunately, vault login does not handle the Space DEL sequence, causing the login to fail when using the password manager. This patch uses a simple method to delete the sequence if present anywhere in the string, although it is strictly only needed at the start of input. * Simplify iTerm handling to only remove iTerm prefix The logic now only removes the two byte prefix sent in by iTerm instead of trying to remove all deletes in the string. This has been tested to work with the iTerm password manager. As a small correction, the byte sequence is \x20\x7f. The earlier commit message incorrectly stated it was \x03\x7f.
This commit is contained in:
parent
f075ed5d40
commit
8bdd74cfe6
@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ErrInterrupted = errors.New("interrupted")
|
||||
@ -34,7 +35,7 @@ func Read(f *os.File) (string, error) {
|
||||
case <-ch:
|
||||
return "", ErrInterrupted
|
||||
case <-doneCh:
|
||||
return result, resultErr
|
||||
return removeiTermDelete(result), resultErr
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,3 +63,7 @@ func readline(f *os.File) (string, error) {
|
||||
|
||||
return string(resultBuf), nil
|
||||
}
|
||||
|
||||
func removeiTermDelete(input string) string {
|
||||
return strings.TrimPrefix(input, "\x20\x7f")
|
||||
}
|
||||
|
||||
27
helper/password/password_test.go
Normal file
27
helper/password/password_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package password
|
||||
|
||||
import "testing"
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}
|
||||
|
||||
func TestRemoveiTermDelete(t *testing.T) {
|
||||
var tests = []testCase{
|
||||
{"NoDelete", "TestingStuff", "TestingStuff"},
|
||||
{"SingleDelete", "Testing\x7fStuff", "Testing\x7fStuff"},
|
||||
{"DeleteFirst", "\x7fTestingStuff", "\x7fTestingStuff"},
|
||||
{"DoubleDelete", "\x7f\x7fTestingStuff", "\x7f\x7fTestingStuff"},
|
||||
{"SpaceFirst", "\x20TestingStuff", "\x20TestingStuff"},
|
||||
{"iTermDelete", "\x20\x7fTestingStuff", "TestingStuff"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := removeiTermDelete(test.input)
|
||||
if result != test.expected {
|
||||
t.Errorf("Test %s failed, input: '%s', expected: '%s', output: '%s'", test.name, test.input, test.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user