Skip to content

Commit

Permalink
gatewayclient: fix domain compare when match cookie (#647)
Browse files Browse the repository at this point in the history
kwilteam/kgw#18 made changes to what's get set as domain in cookie, kwil-cli didn't change accordingly.

So when call `.build/kwil-cli database call --action owner_only --name testdb --kwil-provider http://localhost:8090 --authenticate` multiple times, got prompted every time.
The issue is that after cookie is loaded, we compared the cookie domain and `--kwil-provider`, it won't match if provider has `:port`
  • Loading branch information
Yaiba authored Apr 9, 2024
1 parent 55eb39e commit ea5f86e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/gatewayclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/http/cookiejar"
"net/url"
"strings"

"github.com/kwilteam/kwil-db/core/client"
rpcClient "github.com/kwilteam/kwil-db/core/rpc/client"
Expand Down Expand Up @@ -189,7 +190,11 @@ func (c *GatewayClient) GetAuthCookie() (cookie *http.Cookie, found bool) {
// If the cookie is not valid for the client target, it returns an error.
// It will overwrite any existing authentication cookie.
func (c *GatewayClient) SetAuthCookie(cookie *http.Cookie) error {
if cookie.Domain != "" && cookie.Domain != c.target.Host {
// ref https://stackoverflow.com/a/16328399.
// KGW already set the cookie domain without port in
// https://github.com/kwilteam/kgw/pull/18/files#diff-5b365c916e8b28d0115f136435a03daa1ef6df8cf0eb49479c556923545b56c7R60
targetDomain := strings.Split(c.target.Host, ":")[0]
if cookie.Domain != "" && cookie.Domain != targetDomain {
return fmt.Errorf("cookie domain %s not valid for host %s", cookie.Domain, c.target.Host)
}
if cookie.Name != kgwAuthCookieName && cookie.Name != kgwAuthCookieNameSecure {
Expand Down

0 comments on commit ea5f86e

Please sign in to comment.