From f168ef9989de15180d2f22e02996ebb2157fed3b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 17 Mar 2024 23:42:40 -0700 Subject: [PATCH] implement a flag to specify custom crossdomain.xml (#19262) fixes #16909 --- cmd/common-main.go | 8 ++++++++ cmd/crossdomain-xml-handler.go | 8 ++++++-- cmd/globals.go | 1 + cmd/server-main.go | 8 +++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 2a06e02b3..cd493eae1 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -361,6 +361,14 @@ func buildServerCtxt(ctx *cli.Context, ctxt *serverCtxt) (err error) { ctxt.ConsoleAddr = ctx.String("console-address") } + if cxml := ctx.String("crossdomain-xml"); cxml != "" { + buf, err := os.ReadFile(cxml) + if err != nil { + return err + } + ctxt.CrossDomainXML = string(buf) + } + // Check "no-compat" flag from command line argument. ctxt.StrictS3Compat = !(ctx.IsSet("no-compat") || ctx.GlobalIsSet("no-compat")) diff --git a/cmd/crossdomain-xml-handler.go b/cmd/crossdomain-xml-handler.go index 14856e6af..78cd96525 100644 --- a/cmd/crossdomain-xml-handler.go +++ b/cmd/crossdomain-xml-handler.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2021 MinIO, Inc. +// Copyright (c) 2015-2024 MinIO, Inc. // // This file is part of MinIO Object Storage stack // @@ -32,10 +32,14 @@ const crossDomainXMLEntity = "/crossdomain.xml" // policy file that grants access to the source domain, allowing the client to continue the transaction. func setCrossDomainPolicyMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + cxml := crossDomainXML + if globalServerCtxt.CrossDomainXML != "" { + cxml = globalServerCtxt.CrossDomainXML + } // Look for 'crossdomain.xml' in the incoming request. if r.URL.Path == crossDomainXMLEntity { // Write the standard cross domain policy xml. - w.Write([]byte(crossDomainXML)) + w.Write([]byte(cxml)) // Request completed, no need to serve to other handlers. return } diff --git a/cmd/globals.go b/cmd/globals.go index d3309bcf4..10f0d5563 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -171,6 +171,7 @@ type serverCtxt struct { ReadHeaderTimeout time.Duration MaxIdleConnsPerHost int + CrossDomainXML string // The layout of disks as interpreted Layout disksLayout } diff --git a/cmd/server-main.go b/cmd/server-main.go index 9268d000e..d4098e6af 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2023 MinIO, Inc. +// Copyright (c) 2015-2024 MinIO, Inc. // // This file is part of MinIO Object Storage stack // @@ -161,6 +161,12 @@ var ServerFlags = []cli.Flag{ Name: "sftp", Usage: "enable and configure an SFTP server", }, + cli.StringFlag{ + Name: "crossdomain-xml", + Usage: "provide a custom crossdomain-xml configuration to report at http://endpoint/crossdomain.xml", + Hidden: true, + EnvVar: "MINIO_CROSSDOMAIN_XML", + }, } var gatewayCmd = cli.Command{