Add path attribute to split cookies (#6298)

* Add "Path" attribute to "/"

Without this the browser defaults to a path of the parent of the
path in the request. See:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#pathpath-value

This means the cookie isn't included in api requests since the path
is too restrictive

* Update tests with split cookie path attribute
rand-read-reverting
hashicc 4 months ago committed by GitHub
parent 7d3c0b4732
commit ef75427403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -92,6 +92,8 @@ func TestAuthenticationHandler(t *testing.T) {
assert.NotEmpty(t, cookies[handlers.JsVisibleCookieName].Value)
assert.True(t, cookies[handlers.HttpOnlyCookieName].HttpOnly)
assert.False(t, cookies[handlers.JsVisibleCookieName].HttpOnly)
assert.Equal(t, cookies[handlers.HttpOnlyCookieName].Path, "/")
assert.Equal(t, cookies[handlers.JsVisibleCookieName].Path, "/")
tok = cookies[handlers.JsVisibleCookieName].Value
pubId = attrs["id"].(string)

@ -114,11 +114,13 @@ func OutgoingResponseFilter(ctx context.Context, w http.ResponseWriter, m proto.
jsTok := http.Cookie{
Name: JsVisibleCookieName,
Value: tok[:half],
Path: "/",
}
httpTok := http.Cookie{
Name: HttpOnlyCookieName,
Value: tok[half:],
HttpOnly: true,
Path: "/",
}
http.SetCookie(w, &jsTok)
http.SetCookie(w, &httpTok)

@ -26,8 +26,8 @@ func TestOutgoingSplitCookie(t *testing.T) {
require.NoError(t, err)
require.NoError(t, OutgoingResponseFilter(context.Background(), rec, &pbs.AuthenticateResponse{Attrs: &pbs.AuthenticateResponse_Attributes{Attributes: attrs}, Type: "cookie"}))
assert.ElementsMatch(t, rec.Result().Cookies(), []*http.Cookie{
{Name: HttpOnlyCookieName, Value: "34567890", HttpOnly: true, Raw: "wt-http-token-cookie=34567890; HttpOnly"},
{Name: JsVisibleCookieName, Value: "t_abc_12", Raw: "wt-js-token-cookie=t_abc_12"},
{Name: HttpOnlyCookieName, Value: "34567890", HttpOnly: true, Path: "/", Raw: "wt-http-token-cookie=34567890; Path=/; HttpOnly"},
{Name: JsVisibleCookieName, Value: "t_abc_12", Path: "/", Raw: "wt-js-token-cookie=t_abc_12; Path=/"},
})
}

Loading…
Cancel
Save