From 0776a479dadfbc899bd3839054673d63a7bf9f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 19 Aug 2026 11:28:00 +0200 Subject: [PATCH] send all /data throught middleware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/proxy/pkg/command/server.go | 2 +- services/proxy/pkg/middleware/datagateway.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 5f13856ec5..2a9a5cc0ba 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -360,7 +360,7 @@ func loadMiddlewares(logger log.Logger, cfg *config.Config, // 2. Rewrite datagateway url tokens to dataprovider endpoint and // rewrite Location headers in TUS responses to signed datagateway urls - middleware.NewDataGatewayMiddleware(cfg.TransferSecret, cfg.TransferTimeout).Handler, + middleware.NewDataGatewayMiddleware("/data", cfg.TransferSecret, cfg.TransferTimeout).Handler, middleware.Security(cspConfig), diff --git a/services/proxy/pkg/middleware/datagateway.go b/services/proxy/pkg/middleware/datagateway.go index 3c3deaba0f..6fd9bb877a 100644 --- a/services/proxy/pkg/middleware/datagateway.go +++ b/services/proxy/pkg/middleware/datagateway.go @@ -26,12 +26,14 @@ type transferClaims struct { // DataGatewayMiddleware handles both routing of /data requests and rewriting TUS Location headers. type DataGatewayMiddleware struct { + Prefix string Secret string Timeout time.Duration } -func NewDataGatewayMiddleware(secret string, timeout time.Duration) *DataGatewayMiddleware { +func NewDataGatewayMiddleware(prefix, secret string, timeout time.Duration) *DataGatewayMiddleware { return &DataGatewayMiddleware{ + Prefix: prefix, Secret: secret, Timeout: timeout, } @@ -41,10 +43,14 @@ func NewDataGatewayMiddleware(secret string, timeout time.Duration) *DataGateway func (m *DataGatewayMiddleware) Handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // --- REQUEST PHASE: Handle tus PATCH, DELETE and GET /data requests --- - isTusPatchRequest := strings.HasPrefix(r.URL.Path, "/data") && r.Header.Get("Tus-Resumable") == "1.0.0" + // --- REQUEST PHASE: Handle /data requests --- + // Not only the TUS PATCH requests by clients need to be rewritten. + // Services like antivirus make GET requests to check the file content + // and a DELETE reuquest is used to cancel an upload. + // All of these requests need to be routed through the datagateway. + isDataGatewayRequest := strings.HasPrefix(r.URL.Path, m.Prefix) - if isTusPatchRequest { + if isDataGatewayRequest { token := r.Header.Get(TokenTransportHeader) if token == "" { token = path.Base(r.URL.Path)