Enable Split Cookies (#318)
This commit is contained in:
1 parent
a4c20164f3
commit
0aba6db720
11 files changed
+174
-49
No files matched your search
@@ -25,12 +25,6 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
HeaderAuthMethod = "Authorization"
|
||||
HttpOnlyCookieName = "wt-http-token-cookie"
|
||||
JsVisibleCookieName = "wt-js-token-cookie"
|
||||
)
|
||||
|
||||
type TokenFormat int
|
||||
|
||||
const (
|
||||
@@ -554,10 +548,10 @@ func GetTokenFromRequest(logger hclog.Logger, kmsCache *kms.Kms, req *http.Reque
|
||||
if receivedTokenType != AuthTokenTypeBearer {
|
||||
var httpCookiePayload string
|
||||
var jsCookiePayload string
|
||||
if hc, err := req.Cookie(HttpOnlyCookieName); err == nil {
|
||||
if hc, err := req.Cookie(handlers.HttpOnlyCookieName); err == nil {
|
||||
httpCookiePayload = hc.Value
|
||||
}
|
||||
if jc, err := req.Cookie(JsVisibleCookieName); err == nil {
|
||||
if jc, err := req.Cookie(handlers.JsVisibleCookieName); err == nil {
|
||||
jsCookiePayload = jc.Value
|
||||
}
|
||||
if httpCookiePayload != "" && jsCookiePayload != "" {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/servers"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
@@ -317,8 +318,8 @@ func TestAuthTokenAuthenticator(t *testing.T) {
|
||||
{
|
||||
name: "Split cookie token",
|
||||
cookies: []http.Cookie{
|
||||
{Name: HttpOnlyCookieName, Value: httpCookieVal},
|
||||
{Name: JsVisibleCookieName, Value: jsCookieVal},
|
||||
{Name: handlers.HttpOnlyCookieName, Value: httpCookieVal},
|
||||
{Name: handlers.JsVisibleCookieName, Value: jsCookieVal},
|
||||
},
|
||||
userId: at.GetIamUserId(),
|
||||
tokenFormat: AuthTokenTypeSplitCookie,
|
||||
@@ -326,14 +327,14 @@ func TestAuthTokenAuthenticator(t *testing.T) {
|
||||
{
|
||||
name: "Split cookie token only http cookie",
|
||||
cookies: []http.Cookie{
|
||||
{Name: HttpOnlyCookieName, Value: httpCookieVal},
|
||||
{Name: handlers.HttpOnlyCookieName, Value: httpCookieVal},
|
||||
},
|
||||
tokenFormat: AuthTokenTypeUnknown,
|
||||
},
|
||||
{
|
||||
name: "Split cookie token only js cookie",
|
||||
cookies: []http.Cookie{
|
||||
{Name: JsVisibleCookieName, Value: jsCookieVal},
|
||||
{Name: handlers.JsVisibleCookieName, Value: jsCookieVal},
|
||||
},
|
||||
tokenFormat: AuthTokenTypeUnknown,
|
||||
},
|
||||
@@ -341,8 +342,8 @@ func TestAuthTokenAuthenticator(t *testing.T) {
|
||||
name: "Cookie and auth header",
|
||||
headers: map[string]string{"Authorization": fmt.Sprintf("Bearer %s", tokValue)},
|
||||
cookies: []http.Cookie{
|
||||
{Name: HttpOnlyCookieName, Value: httpCookieVal},
|
||||
{Name: JsVisibleCookieName, Value: jsCookieVal},
|
||||
{Name: handlers.HttpOnlyCookieName, Value: httpCookieVal},
|
||||
{Name: handlers.JsVisibleCookieName, Value: jsCookieVal},
|
||||
},
|
||||
userId: at.GetIamUserId(),
|
||||
tokenFormat: AuthTokenTypeBearer,
|
||||
|
||||
Reference in new issue
Block a user