fix CORS origins to avoid domain hijacking

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
Marcos Lilljedahl
2023-03-02 01:49:38 -03:00
parent 2b95e66079
commit ed82247c9a

View File

@@ -70,10 +70,10 @@ func Register(extend HandlerExtender) {
corsHandler := gh.CORS(gh.AllowCredentials(), gh.AllowedHeaders([]string{"x-requested-with", "content-type"}), gh.AllowedMethods([]string{"GET", "POST", "HEAD", "DELETE"}), gh.AllowedOriginValidator(func(origin string) bool {
if strings.Contains(origin, "localhost") ||
strings.HasSuffix(origin, "play-with-docker.com") ||
strings.HasSuffix(origin, "play-with-kubernetes.com") ||
strings.HasSuffix(origin, "docker.com") ||
strings.HasSuffix(origin, "play-with-go.dev") {
strings.HasSuffix(origin, ".play-with-docker.com") ||
strings.HasSuffix(origin, ".play-with-kubernetes.com") ||
strings.HasSuffix(origin, ".docker.com") ||
strings.HasSuffix(origin, ".play-with-go.dev") {
return true
}
return false