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

add another regex for finding state tokens #1064

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 15 additions & 5 deletions pkg/provider/okta/okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,22 @@ func (oc *Client) getStateToken(req *http.Request, loginDetails *creds.LoginDeta
}

func getStateTokenFromOktaPageBody(responseBody string) (string, error) {
re := regexp.MustCompile("var stateToken = [\"|'](.*)[\"|'];")
match := re.FindStringSubmatch(responseBody)
if len(match) < 2 {
return "", errors.New("cannot find state token")
regexes := []*regexp.Regexp{
regexp.MustCompile("var stateToken = [\"|'](.*)[\"|'];"),
// Found on the "extra verification" page
// hiding in a Javascript object
regexp.MustCompile(`"stateToken":"([^"]*)"`),
}
return strings.Replace(match[1], `\x2D`, "-", -1), nil

for _, re := range regexes {
match := re.FindStringSubmatch(responseBody)
if len(match) >= 2 {
return strings.Replace(match[1], `\x2D`, "-", -1), nil
}
}

return "", errors.New("cannot find state token")

}

func parseMfaIdentifer(json string, arrayPosition int) (string, string, string) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/okta/okta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func TestGetStateTokenFromOktaPageBody(t *testing.T) {
stateToken: "12345-6789",
err: nil,
},
{
title: "javascript state token inside JSON",
body: `U0h8","stateToken":"c0ffeeda7e","helpLinks":{"help"`,
stateToken: "c0ffeeda7e",
err: nil,
},
}
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
Expand Down