Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set the Secure flag on auth cookies when appropriate #6930

Merged
merged 4 commits into from Dec 8, 2023

Conversation

jmazzitelli
Copy link
Collaborator

fixes: #6912

nrfox
nrfox previously approved these changes Dec 7, 2023
config/config.go Outdated
@@ -873,6 +873,11 @@ func (conf *Config) AllNamespacesAccessible() bool {
return conf.Deployment.ClusterWideAccess
}

// IsServerHttps returns true if the server endpoint should use HTTPS. If false, only plaintext HTTP is supported.
func (conf *Config) IsServerHttps() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor nit that you can ignore if you like: but note that if you accept this suggestion you'll probably have to update it everywhere else.

Suggested change
func (conf *Config) IsServerHttps() bool {
func (conf *Config) IsServerHTTPS() bool {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had it that way, and then the Code editor made the suggestion to change it to camel case. What is our typical code convention here? I was just following the editor blindly :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're inconsistent but it's a generally accepted style for abbreviations in go: https://github.com/golang/go/wiki/CodeReviewComments#initialisms.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. See latest commit

@@ -372,6 +372,7 @@ func (c OpenIdAuthController) redirectToAuthServerHandler(w http.ResponseWriter,
nonceCookie := http.Cookie{
Expires: expirationTime,
HttpOnly: true,
Secure: conf.IsServerHttps(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is setting this to false the same as not setting this? In other words:

http.Cookie{} == http.Cookie{Secure: false}

I think so because the default value is false.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I almost think it has to be because the "Secure" flag is just that -- a flag in the cookie. So the set-cookie header doesn't have "Secure=true" or "Secure=false" its just "Secure" or not specified.

And yes the default is false.

see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#syntax and https://http.dev/set-cookie#secure

@jmazzitelli
Copy link
Collaborator Author

I pushed a rebase to fix the conflict in server/server.go

@jmazzitelli
Copy link
Collaborator Author

as per @nrfox ... If there is a proxy in front that uses https (but the kiali endpoint doesn't use https), we still want to set the Secure flag.

Copy link
Contributor

@nrfox nrfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 comment but non-blocking

@@ -367,12 +367,14 @@ func (c OpenIdAuthController) redirectToAuthServerHandler(w http.ResponseWriter,
return
}

guessedKialiURL := httputil.GuessKialiURL(r)
secureFlag := conf.IsServerHTTPS() || strings.HasPrefix(guessedKialiURL, "https:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is repeated a bunch of places now can it just be its own function? Something like IsSecureCookie(...)?

@jmazzitelli jmazzitelli merged commit 4491ed2 into kiali:master Dec 8, 2023
7 checks passed
@jmazzitelli jmazzitelli deleted the 6912-cookie-secure branch December 8, 2023 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Set Secure Attribute on Session Cookie
2 participants