@@ -2206,8 +2206,9 @@ func (c *Core) PopulateTokenEntry(ctx context.Context, req *logical.Request) err
2206
2206
token := req .ClientToken
2207
2207
var err error
2208
2208
req .InboundSSCToken = token
2209
+ decodedToken := token
2209
2210
if IsSSCToken (token ) {
2210
- token , err = c .CheckSSCToken (ctx , token , c .isLoginRequest (ctx , req ), c .perfStandby )
2211
+ decodedToken , err = c .CheckSSCToken (ctx , token , c .isLoginRequest (ctx , req ), c .perfStandby )
2211
2212
// If we receive an error from CheckSSCToken, we can assume the token is bad somehow, and the client
2212
2213
// should receive a 403 bad token error like they do for all other invalid tokens, unless the error
2213
2214
// specifies that we should forward the request or retry the request.
@@ -2218,12 +2219,18 @@ func (c *Core) PopulateTokenEntry(ctx context.Context, req *logical.Request) err
2218
2219
return logical .ErrPermissionDenied
2219
2220
}
2220
2221
}
2221
- req .ClientToken = token
2222
+ req .ClientToken = decodedToken
2223
+ // We ignore the token returned from CheckSSCToken here as Lookup also decodes the SSCT, and
2224
+ // it may need the original SSCT to check state.
2222
2225
te , err := c .LookupToken (ctx , token )
2223
2226
if err != nil {
2227
+ // If we're missing required state, return that error as-is to the client
2228
+ if errors .Is (err , logical .ErrPerfStandbyPleaseForward ) || errors .Is (err , logical .ErrMissingRequiredState ) {
2229
+ return err
2230
+ }
2224
2231
// If we have two dots but the second char is a dot it's a vault
2225
2232
// token of the form s.SOMETHING.nsid, not a JWT
2226
- if ! IsJWT (token ) {
2233
+ if ! IsJWT (decodedToken ) {
2227
2234
return fmt .Errorf ("error performing token check: %w" , err )
2228
2235
}
2229
2236
}
0 commit comments