@@ -13,7 +13,6 @@ import (
13
13
"sync"
14
14
15
15
"github.com/go-chi/chi/v5"
16
- "github.com/go-chi/cors"
17
16
"github.com/google/uuid"
18
17
"go.opentelemetry.io/otel/trace"
19
18
"nhooyr.io/websocket"
@@ -364,22 +363,7 @@ func (s *Server) HandleSubdomain(middlewares ...func(http.Handler) http.Handler)
364
363
365
364
// Use the passed in app middlewares before checking authentication and
366
365
// passing to the proxy app.
367
- mws := chi .Middlewares (append (middlewares , cors .Handler (cors.Options {
368
- AllowOriginFunc : func (r * http.Request , origin string ) bool {
369
- originApp , ok := s .parseOrigin (origin )
370
- return ok && originApp .Username == app .Username
371
- },
372
- AllowedMethods : []string {
373
- http .MethodHead ,
374
- http .MethodGet ,
375
- http .MethodPost ,
376
- http .MethodPut ,
377
- http .MethodPatch ,
378
- http .MethodDelete ,
379
- },
380
- AllowedHeaders : []string {"*" },
381
- AllowCredentials : true ,
382
- })))
366
+ mws := chi .Middlewares (append (middlewares , httpmw .WorkspaceAppCors (s .HostnameRegex , app )))
383
367
mws .Handler (http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
384
368
if ! s .handleAPIKeySmuggling (rw , r , AccessMethodSubdomain ) {
385
369
return
@@ -411,22 +395,6 @@ func (s *Server) HandleSubdomain(middlewares ...func(http.Handler) http.Handler)
411
395
}
412
396
}
413
397
414
- func (s * Server ) parseOrigin (rawOrigin string ) (httpapi.ApplicationURL , bool ) {
415
- origin , err := url .Parse (rawOrigin )
416
- if rawOrigin == "" || origin .Host == "" || err != nil {
417
- return httpapi.ApplicationURL {}, false
418
- }
419
- subdomain , ok := httpapi .ExecuteHostnamePattern (s .HostnameRegex , origin .Host )
420
- if ! ok {
421
- return httpapi.ApplicationURL {}, false
422
- }
423
- app , err := httpapi .ParseSubdomainAppURL (subdomain )
424
- if err != nil {
425
- return httpapi.ApplicationURL {}, false
426
- }
427
- return app , true
428
- }
429
-
430
398
// parseHostname will return if a given request is attempting to access a
431
399
// workspace app via a subdomain. If it is, the hostname of the request is parsed
432
400
// into an httpapi.ApplicationURL and true is returned. If the request is not
0 commit comments