Skip to content

Commit cb97257

Browse files
committed
TUN-7424: Add CORS headers to host_details responses
1 parent c43e07d commit cb97257

File tree

8 files changed

+548
-1
lines changed

8 files changed

+548
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ require (
6666
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
6767
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
6868
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
69+
github.com/go-chi/cors v1.2.1 // indirect
6970
github.com/go-logr/logr v1.2.3 // indirect
7071
github.com/go-logr/stdr v1.2.2 // indirect
7172
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwv
156156
github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
157157
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
158158
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
159+
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
160+
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
159161
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
160162
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
161163
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=

management/service.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/go-chi/chi/v5"
13+
"github.com/go-chi/cors"
1314
"github.com/google/uuid"
1415
"github.com/rs/zerolog"
1516
"nhooyr.io/websocket"
@@ -67,7 +68,17 @@ func New(managementHostname string,
6768
r.Get("/ping", ping)
6869
r.Head("/ping", ping)
6970
r.Get("/logs", s.logs)
70-
r.Get("/host_details", s.getHostDetails)
71+
r.Route("/host_details", func(r chi.Router) {
72+
// CORS middleware required to allow dash to access management.argotunnel.com requests
73+
r.Use(cors.Handler(cors.Options{
74+
// Allows for any subdomain of cloudflare.com
75+
AllowedOrigins: []string{"https://*.cloudflare.com"},
76+
// Required to present cookies or other authentication across origin boundries
77+
AllowCredentials: true,
78+
MaxAge: 300, // Maximum value not ignored by any of major browsers
79+
}))
80+
r.Get("/", s.getHostDetails)
81+
})
7182
s.router = r
7283
return s
7384
}

vendor/github.com/go-chi/cors/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-chi/cors/README.md

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)