From b1140c3a208d3181325baf9bffe29cbc75ad58d5 Mon Sep 17 00:00:00 2001 From: Nick Irvine Date: Tue, 2 Apr 2019 16:50:59 -0700 Subject: [PATCH] MFA input validation (#139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addressing some possible confusion around current “index out of range” runtime errors when selecting an MFA option. --- lib/okta.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/okta.go b/lib/okta.go index 6485150c..03f4088d 100644 --- a/lib/okta.go +++ b/lib/okta.go @@ -278,6 +278,9 @@ func (o *OktaClient) selectMFADevice() (*OktaUserAuthnFactor, error) { log.Infof("%d: %s (%s)", i, f.Provider, f.FactorType) } i, err := Prompt("Select MFA method", false) + if i == "" { + return nil, errors.New("Invalid selection - Please use an option that is listed") + } if err != nil { return nil, err } @@ -285,6 +288,9 @@ func (o *OktaClient) selectMFADevice() (*OktaUserAuthnFactor, error) { if err != nil { return nil, err } + if factorIdx > (len(factors) - 1) { + return nil, errors.New("Invalid selection - Please use an option that is listed") + } return &factors[factorIdx], nil }