Skip to content

Commit 2038b38

Browse files
authored
fix: allow credentialed public CORS (#79)
1 parent 92b7ed5 commit 2038b38

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

apps/druid/adapters/http/handlers/routes.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ func RegisterPublicRoutes(app *fiber.App, handlers RouteHandlers) {
5252
authorizer = handlers.Server.ScrollHandler.authorizer
5353
}
5454
app.Use(cors.New(cors.Config{
55-
AllowOrigins: "*",
56-
AllowMethods: "GET,POST,PUT,DELETE,PATCH,OPTIONS,HEAD,PROPFIND,MOVE,MKCOL,COPY",
57-
AllowHeaders: "Origin,Content-Type,Accept,Authorization,X-Requested-With,Cache-Control,DNT,Keep-Alive,User-Agent,If-Modified-Since,Depth,Destination,Overwrite,If,Lock-Token,Timeout,Dav",
58-
ExposeHeaders: "Druid-Version",
55+
AllowOrigins: "https://app.druid.gg,http://localhost:3000,http://127.0.0.1:3000",
56+
AllowMethods: "GET,POST,PUT,DELETE,PATCH,OPTIONS,HEAD,PROPFIND,MOVE,MKCOL,COPY",
57+
AllowHeaders: "Origin,Content-Type,Accept,Authorization,X-Requested-With,Cache-Control,DNT,Keep-Alive,User-Agent,If-Modified-Since,Depth,Destination,Overwrite,If,Lock-Token,Timeout,Dav",
58+
AllowCredentials: true,
59+
ExposeHeaders: "Druid-Version",
5960
}))
6061
app.Get("/health", handlers.Server.GetHealthAuth)
6162
app.Get("/.well-known/jwks.json", RuntimeJWKS(authorizer))

apps/druid/adapters/http/handlers/routes_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ func TestPublicRoutesAnswerCorsPreflight(t *testing.T) {
5050
if resp.StatusCode != http.StatusNoContent {
5151
t.Fatalf("preflight status = %d, want 204", resp.StatusCode)
5252
}
53-
if got := resp.Header.Get("Access-Control-Allow-Origin"); got != "*" {
54-
t.Fatalf("allow origin = %q, want *", got)
53+
if got := resp.Header.Get("Access-Control-Allow-Origin"); got != "http://127.0.0.1:3000" {
54+
t.Fatalf("allow origin = %q, want request origin", got)
55+
}
56+
if got := resp.Header.Get("Access-Control-Allow-Credentials"); got != "true" {
57+
t.Fatalf("allow credentials = %q, want true", got)
5558
}
5659
}
5760

config/helm-charts/druid-cli/chart_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func TestChartRendersDefaultAndCustomValues(t *testing.T) {
7272
"runtime.example.test",
7373
"name: public",
7474
"nginx.ingress.kubernetes.io/enable-cors",
75+
"nginx.ingress.kubernetes.io/cors-allow-origin",
76+
"nginx.ingress.kubernetes.io/cors-allow-credentials",
7577
"storageClassName: \"local-path\"",
7678
} {
7779
if !strings.Contains(customManifest, want) {

config/helm-charts/druid-cli/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ ingress:
4141
className: nginx
4242
annotations:
4343
nginx.ingress.kubernetes.io/enable-cors: "true"
44+
nginx.ingress.kubernetes.io/cors-allow-origin: "https://app.druid.gg"
45+
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
4446
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, PUT, POST, DELETE, PATCH, OPTIONS, PROPFIND, MOVE, MKCOL, COPY"
4547
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,depth,destination,overwrite,if,lock-token,timeout,dav"
4648
nginx.ingress.kubernetes.io/cors-expose-headers: "Druid-Version"

0 commit comments

Comments
 (0)