From e9e96224b3d6f1f58bc673cd6a16359229d45070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Wed, 25 Nov 2020 12:50:34 +0100 Subject: [PATCH] Fix in-path sink signature matching The eventbus payload contained the trailing /__sink=..., so path matching failed. --- system/service/sink.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/system/service/sink.go b/system/service/sink.go index c9dd70997..317b9b2c8 100644 --- a/system/service/sink.go +++ b/system/service/sink.go @@ -164,7 +164,7 @@ func (svc *sink) ProcessRequest(w http.ResponseWriter, r *http.Request) { body = http.MaxBytesReader(w, r.Body, 32<<10) // 32k limit } - if err := svc.process(srup.ContentType, w, r, body); err != nil { + if err := svc.process(srup, w, r, body); err != nil { return SinkErrProcessingError(sap).Wrap(err) } @@ -281,11 +281,12 @@ func (svc sink) handleRequest(r *http.Request) (*SinkRequestUrlParams, *errors.E // b) Max-body-size check might be limited via sink params // and io.Reader that is passed is limited w/ io.LimitReader // -func (svc *sink) process(contentType string, w http.ResponseWriter, r *http.Request, body io.Reader) error { +func (svc *sink) process(srup *SinkRequestUrlParams, w http.ResponseWriter, r *http.Request, body io.Reader) error { var ( - err error - ctx = r.Context() - sap = &sinkActionProps{ + err error + ctx = r.Context() + contentType = srup.ContentType + sap = &sinkActionProps{ contentType: contentType, } ) @@ -330,6 +331,14 @@ func (svc *sink) process(contentType string, w http.ResponseWriter, r *http.Requ sanitizedURL.Path = sanitizedURL.Path[i+len(SinkBaseURL):] } + // Step 3: remove sink suffix if in path + if srup.SignatureInPath { + i := strings.Index(sanitizedURL.Path, SinkSignUrlParamName) + if i > 0 { + sanitizedURL.Path = sanitizedURL.Path[0 : i-1] + } + } + r.URL = sanitizedURL r.RequestURI = sanitizedURL.String()