oauth2-proxy: cookies are not correctly set for hostnames with ports

Related to https://github.com/oauth2-proxy/oauth2-proxy/issues/2055

Currently, the following code will print the warning Warning: request host %q did not match any of the specific cookie domains of %q and default to the shortest domain when the hostname of a request and cookie are not matched:

https://github.com/oauth2-proxy/oauth2-proxy/blob/dd4fa414eadb065f0d0c38d9b21421c333f88b98/pkg/cookies/cookies.go#L19-L26

However, this is NOT the correct behavior (and may result in setting the cookie on the incorrect domain), because as discussed in this stack overflow thread, browsers do not distinguish the ports of cookies.

Therefore, we should be stripping off any :XXXX port suffix from the request host when checking which cookie_domain to match it to.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 19 (8 by maintainers)

Most upvoted comments

This is a 1.5 year issue that had a PR that was closed…

This will also prevent to make multiple cookie domains work since it won’t match any… That’s sad.

The comment on the PR:

Reading through the description, it seems that you are stripping the port from the matching part of the algorithm, which would be a breaking change and mean that there are potentially more matches than would be expected. Rather, would it be better instead to leave the matching algorithm as is, but then strip the port of the cookie when the cookie is constructed?

I don’t understand what you are implying here @JoelSpeed…

Cookies are per domain and does not include ports…

Besides that, the change only applies to the GetCookieDomain function which tries to match the fqdn on the request with a domain specified on the cookies… Cookies will later be (correctly) set to the domain and not using port at all…

This issue is not yet resolved (this is why I don’t like stale bots, because they make it harder to identify valid issues which just havent been solved yet).