return 403 for wrapping requests when no token provided (#18859)
* return 403 for wrapping requests when no token provided * add changelog entry * fix changelog * use errors.As * simplify error response string
This commit is contained in:
parent
a74cc88c45
commit
6cb6157d37
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
core/auth: Return a 403 instead of a 500 for wrapping requests when token is not provided
|
||||||
|
```
|
|
@ -2,6 +2,7 @@ package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -366,4 +367,20 @@ func TestHTTP_Wrapping(t *testing.T) {
|
||||||
}) {
|
}) {
|
||||||
t.Fatalf("secret data did not match expected: %#v", secret.Data)
|
t.Fatalf("secret data did not match expected: %#v", secret.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that wrapping lookup without a client token responds correctly
|
||||||
|
client.ClearToken()
|
||||||
|
secret, err = client.Logical().Read("sys/wrapping/lookup")
|
||||||
|
if secret != nil {
|
||||||
|
t.Fatalf("expected no response: %#v", secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error")
|
||||||
|
}
|
||||||
|
|
||||||
|
var respError *api.ResponseError
|
||||||
|
if errors.As(err, &respError); respError.StatusCode != 403 {
|
||||||
|
t.Fatalf("expected 403 response, actual: %d", respError.StatusCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -561,7 +561,7 @@ func (c *Core) handleCancelableRequest(ctx context.Context, req *logical.Request
|
||||||
// be revoked after the call. So we have to do the validation here.
|
// be revoked after the call. So we have to do the validation here.
|
||||||
valid, err := c.validateWrappingToken(ctx, req)
|
valid, err := c.validateWrappingToken(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error validating wrapping token: %w", err)
|
return logical.ErrorResponse(fmt.Sprintf("error validating wrapping token: %s", err.Error())), logical.ErrPermissionDenied
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
return nil, consts.ErrInvalidWrappingToken
|
return nil, consts.ErrInvalidWrappingToken
|
||||||
|
|
Loading…
Reference in New Issue