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

x/term: ReadPassword doesn't return when given input > 1023 characters #50897

Closed
jesselang opened this issue Jan 28, 2022 · 1 comment
Closed

Comments

@jesselang
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.17.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes. 1.17.6 is the latest release at the time of creation of this issue.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jdlang/Library/Caches/go-build"
GOENV="/Users/jdlang/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jdlang/dev/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jdlang/dev/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.17.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.6/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD="/Users/jdlang/play/readpassword/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/yd/6gthgn951hlbr9xmst_p_bb1smsz_1/T/go-build2642420630=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I want the user to paste a JWT token (currently 1,141 characters) via os.Stdin without echoing it on the terminal. ReadPassword seemed like a good candidate for this use case. Using the shell script below, the random output generated can be copied and pasted into this basic program.

package main

import (
	"fmt"
	"os"

	"golang.org/x/term"
)

func main() {
	fmt.Print("> ")
	p, err := term.ReadPassword(int(os.Stdin.Fd()))
	if err != nil {
		panic(err)
	}

	fmt.Printf("Length: %d\n", len(p))
}
#!/usr/bin/env bash

set -e
for length in $(seq 1020 1 1030); do
    cat /dev/urandom | LC_ALL=C tr -dc '[:alnum:]' | head -c $length
    echo

    go run main.go
done

What did you expect to see?

ReadPassword to return when given input greater than 1,023 characters.

What did you see instead?

ReadPassword does not return when given input greater than 1,023 characters.

Conclusion

I'm looking for guidance on how users should paste an input of arbitrarily long length into a CLI program without the input being echoed to the terminal. Thank you very much!

@gopherbot gopherbot added this to the Unreleased milestone Jan 28, 2022
@ianlancetaylor
Copy link
Contributor

I don't think ReadPassword has any inherent limitation to 1023 bytes. This may have something to do with the terminal driver on your system.

For the more general operation of not echoing, see the implementation of term.ReadPassword, which for Darwin is at https://go.googlesource.com/term/+/refs/heads/master/term_unix.go#75. That shows how to disable echoing using the golang.org/x/sys/unix package.

Closing because I don't think there is anything to fix in the Go package here. For questions about using Go, please see https://go.dev/wiki/Questions. Please comment if you disagree. Thanks.

@golang golang locked and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants