Filip Troníček da1053e101
Make auth cookie stricter (#19973)
* Use `__Host-` prefix for cookie

* Fix tests

* Remove domain from cookie

* Fix logout

* remove unused fn

* fix user logout properly

* [server] Make domain-only cookie work for GitHub oauth login

... by adding additional step so we can set the cookie for the base domain only

* test: fix by redirecting before callbacl/authorize

* [server] SessionHandler: Allow to login with both primary and secondary cookies

* [server] Clear 2ndary cookie on logout

* Fix filtering cookie values when primary cookie is empty

* Fix logouts

* Fix tests

---------

Co-authored-by: Gero Posmyk-Leinemann <gero@gitpod.io>
2024-07-01 08:53:14 +02:00

14 lines
436 B
Go

// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package lib
import "regexp"
func CookieNameFromDomain(domain string) string {
// replace all non-word characters with underscores
derived := regexp.MustCompile(`[\W_]+`).ReplaceAllString(domain, "_")
return "__Host-_" + derived + "_jwt2_"
}