Skip to content

Commit

Permalink
state mismatch error fix
Browse files Browse the repository at this point in the history
Signed-off-by: iamazzeez <[email protected]>
  • Loading branch information
iamazzeez committed Jan 15, 2025
1 parent 0c4aab6 commit 2770c20
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions components/session-service/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,14 +838,24 @@ func (s *Server) newHandler(w http.ResponseWriter, r *http.Request) {
}
}

relayState, err := generateRelayState()
if err != nil {
s.log.Errorf("couldn't generate random relay state: %s", err)
httpError(w, http.StatusInternalServerError)
return
// Get client state and use it as relay state if provided
clientState := r.FormValue("state")
var relayState string
var err error

if clientState != "" {
relayState = clientState
} else {
relayState, err = generateRelayState()
if err != nil {
s.log.Errorf("couldn't generate random relay state: %s", err)
httpError(w, http.StatusInternalServerError)
return
}
}
// take state we've gotten from the client, store it
if clientState := r.FormValue("state"); clientState != "" {

// Store client state only if it's different from relay state
if clientState != "" && clientState != relayState {
s.log.Debugf("storing clientState %s", clientState)
if err := sess.PutString(w, clientStateKeyPrefix+relayState, clientState); err != nil {
http.Error(w, "failed to set client state", http.StatusInternalServerError)
Expand Down

0 comments on commit 2770c20

Please sign in to comment.