@@ -45,7 +45,6 @@ import (
45
45
type RouteHandlerConfig struct {
46
46
Config * Config
47
47
DefaultTransport http.RoundTripper
48
- CorsHandler mux.MiddlewareFunc
49
48
WorkspaceAuthHandler mux.MiddlewareFunc
50
49
}
51
50
@@ -61,14 +60,9 @@ func WithDefaultAuth(infoprov common.WorkspaceInfoProvider) RouteHandlerConfigOp
61
60
62
61
// NewRouteHandlerConfig creates a new instance.
63
62
func NewRouteHandlerConfig (config * Config , opts ... RouteHandlerConfigOpt ) (* RouteHandlerConfig , error ) {
64
- corsHandler , err := corsHandler (config .CorsEnabled , config .GitpodInstallation .Scheme , config .GitpodInstallation .HostName )
65
- if err != nil {
66
- return nil , err
67
- }
68
63
cfg := & RouteHandlerConfig {
69
64
Config : config ,
70
65
DefaultTransport : createDefaultTransport (config .TransportConfig ),
71
- CorsHandler : corsHandler ,
72
66
WorkspaceAuthHandler : func (h http.Handler ) http.Handler { return h },
73
67
}
74
68
for _ , o := range opts {
@@ -185,7 +179,6 @@ func (ir *ideRoutes) HandleSSHHostKeyRoute(route *mux.Route, hostKeyList []ssh.S
185
179
}
186
180
r := route .Subrouter ()
187
181
r .Use (logRouteHandlerHandler ("HandleSSHHostKeyRoute" ))
188
- r .Use (ir .Config .CorsHandler )
189
182
r .NewRoute ().HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
190
183
rw .Header ().Add ("Content-Type" , "application/json" )
191
184
rw .Write (byt )
@@ -195,7 +188,6 @@ func (ir *ideRoutes) HandleSSHHostKeyRoute(route *mux.Route, hostKeyList []ssh.S
195
188
func (ir * ideRoutes ) HandleCreateKeyRoute (route * mux.Route , hostKeyList []ssh.Signer ) {
196
189
r := route .Subrouter ()
197
190
r .Use (logRouteHandlerHandler ("HandleCreateKeyRoute" ))
198
- r .Use (ir .Config .CorsHandler )
199
191
200
192
r .Use (ir .workspaceMustExistHandler )
201
193
r .Use (ir .Config .WorkspaceAuthHandler )
@@ -260,7 +252,6 @@ func extractCloseErrorCode(errStr string) string {
260
252
func (ir * ideRoutes ) HandleSSHOverWebsocketTunnel (route * mux.Route , sshGatewayServer * sshproxy.Server ) {
261
253
r := route .Subrouter ()
262
254
r .Use (logRouteHandlerHandler ("HandleSSHOverWebsocketTunnel" ))
263
- r .Use (ir .Config .CorsHandler )
264
255
r .Use (ir .workspaceMustExistHandler )
265
256
r .Use (ir .Config .WorkspaceAuthHandler )
266
257
@@ -304,7 +295,6 @@ func (ir *ideRoutes) HandleSSHOverWebsocketTunnel(route *mux.Route, sshGatewaySe
304
295
func (ir * ideRoutes ) HandleDirectSupervisorRoute (route * mux.Route , authenticated bool , proxyPassOpts ... proxyPassOpt ) {
305
296
r := route .Subrouter ()
306
297
r .Use (logRouteHandlerHandler (fmt .Sprintf ("HandleDirectSupervisorRoute (authenticated: %v)" , authenticated )))
307
- r .Use (ir .Config .CorsHandler )
308
298
r .Use (ir .workspaceMustExistHandler )
309
299
if authenticated {
310
300
r .Use (ir .Config .WorkspaceAuthHandler )
@@ -389,7 +379,6 @@ type BlobserveInlineVars struct {
389
379
func (ir * ideRoutes ) HandleRoot (route * mux.Route ) {
390
380
r := route .Subrouter ()
391
381
r .Use (logRouteHandlerHandler ("handleRoot" ))
392
- r .Use (ir .Config .CorsHandler )
393
382
r .Use (ir .workspaceMustExistHandler )
394
383
395
384
proxyPassWoSensitiveCookies := sensitiveCookieHandler (ir .Config .Config .GitpodInstallation .HostName )(proxyPass (ir .Config , ir .InfoProvider , workspacePodResolver ))
@@ -523,7 +512,6 @@ func installDebugWorkspaceRoutes(r *mux.Router, config *RouteHandlerConfig, info
523
512
}
524
513
525
514
r .Use (logHandler )
526
- r .Use (config .CorsHandler )
527
515
r .Use (config .WorkspaceAuthHandler )
528
516
// filter all session cookies
529
517
r .Use (sensitiveCookieHandler (config .Config .GitpodInstallation .HostName ))
@@ -661,54 +649,6 @@ func buildWorkspacePodURL(protocol api.PortProtocol, ipAddress string, port stri
661
649
return url .Parse (fmt .Sprintf ("%v://%v:%v" , portProtocol , ipAddress , port ))
662
650
}
663
651
664
- // corsHandler produces the CORS handler for workspaces.
665
- func corsHandler (enabled bool , scheme , hostname string ) (mux.MiddlewareFunc , error ) {
666
- if ! enabled {
667
- // empty handler
668
- return func (h http.Handler ) http.Handler {
669
- return h
670
- }, nil
671
- }
672
- origin := fmt .Sprintf ("%s://%s" , scheme , hostname )
673
-
674
- domainRegex := strings .ReplaceAll (hostname , "." , "\\ ." )
675
- originRegex , err := regexp .Compile (".*" + domainRegex )
676
- if err != nil {
677
- return nil , err
678
- }
679
-
680
- return handlers .CORS (
681
- handlers .AllowedOriginValidator (func (origin string ) bool {
682
- // Is the origin a subdomain of the installations hostname?
683
- matches := originRegex .Match ([]byte (origin ))
684
- return matches
685
- }),
686
- // TODO(gpl) For domain-based workspace access with authentication (for accessing the IDE) we need to respond with the precise Origin header that was sent
687
- handlers .AllowedOrigins ([]string {origin }),
688
- handlers .AllowedMethods ([]string {
689
- "GET" ,
690
- "POST" ,
691
- "OPTIONS" ,
692
- }),
693
- handlers .AllowedHeaders ([]string {
694
- // "Accept", "Accept-Language", "Content-Language" are allowed per default
695
- "Cache-Control" ,
696
- "Content-Type" ,
697
- "DNT" ,
698
- "If-Modified-Since" ,
699
- "Keep-Alive" ,
700
- "Origin" ,
701
- "User-Agent" ,
702
- "X-Requested-With" ,
703
- }),
704
- handlers .AllowCredentials (),
705
- // required to be able to read Authorization header in frontend
706
- handlers .ExposedHeaders ([]string {"Authorization" }),
707
- handlers .MaxAge (60 ),
708
- handlers .OptionStatusCode (200 ),
709
- ), nil
710
- }
711
-
712
652
type wsproxyContextKey struct {}
713
653
714
654
var (
0 commit comments