Skip to content

access: prevent login with username-password when using wrong keys #174

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str

var encodedParams string
var err error
usingAPIKeySecretKey := false

if len(r.Config.ActiveProfile.APIKey) > 0 && len(r.Config.ActiveProfile.SecretKey) > 0 {
apiKey := r.Config.ActiveProfile.APIKey
Expand All @@ -230,7 +231,7 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
encodedParams = encodedParams + fmt.Sprintf("&signature=%s", url.QueryEscape(signature))
params = nil
}

usingAPIKeySecretKey = true
} else if len(r.Config.ActiveProfile.Username) > 0 && len(r.Config.ActiveProfile.Password) > 0 {
sessionKey, err := Login(r)
if err != nil {
Expand All @@ -253,7 +254,7 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
}
config.Debug("NewAPIRequest response status code:", response.StatusCode)

if response.StatusCode == http.StatusUnauthorized {
if response.StatusCode == http.StatusUnauthorized && !usingAPIKeySecretKey {
r.Client().Jar, _ = cookiejar.New(nil)
sessionKey, err := Login(r)
if err != nil {
Expand Down