From 90953c2a01810bedc44080d6772d361f5c1600fc Mon Sep 17 00:00:00 2001 From: Michiel <918128+mvanderlee@users.noreply.github.com> Date: Wed, 21 Sep 2022 21:27:58 -0300 Subject: [PATCH 1/3] Only accept gzip and deflate encoding and handle the encoding --- pipeline/mutate/mutator_hydrator.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pipeline/mutate/mutator_hydrator.go b/pipeline/mutate/mutator_hydrator.go index 278a5646dc..371a455ded 100644 --- a/pipeline/mutate/mutator_hydrator.go +++ b/pipeline/mutate/mutator_hydrator.go @@ -22,6 +22,8 @@ package mutate import ( "bytes" + "compress/gzip" + "compress/zlib" "crypto/md5" "encoding/json" "fmt" @@ -51,6 +53,8 @@ const ( ErrNoCredentialsProvided = "No credentials were provided in mutator configuration" contentTypeHeaderKey = "Content-Type" contentTypeJSONHeaderValue = "application/json" + acceptEncodingHeaderKey = "Accept-Encoding" + acceptEncodingHeaderValue = "gzip, deflate" ) type MutatorHydrator struct { @@ -188,6 +192,7 @@ func (a *MutatorHydrator) Mutate(r *http.Request, session *authn.AuthenticationS req.SetBasicAuth(credentials.Username, credentials.Password) } req.Header.Set(contentTypeHeaderKey, contentTypeJSONHeaderValue) + req.Header.Set(acceptEncodingHeaderKey, acceptEncodingHeaderValue) var client *http.Client @@ -234,9 +239,22 @@ func (a *MutatorHydrator) Mutate(r *http.Request, session *authn.AuthenticationS default: return errors.New(ErrNon200ResponseFromAPI) } + + // Handle compressed data + var reader io.ReadCloser + switch res.Header.Get("Content-Encoding") { + case "gzip": + reader, err = gzip.NewReader(res.Body) + defer reader.Close() + case "deflate": + reader, err = zlib.NewReader(res.Body) + defer reader.Close() + default: + reader = res.Body + } sessionFromUpstream := authn.AuthenticationSession{} - err = json.NewDecoder(res.Body).Decode(&sessionFromUpstream) + err = json.NewDecoder(reader).Decode(&sessionFromUpstream) if err != nil { return errors.WithStack(err) } From 4d277ae273df449154c95eec1bdd60164d12ffc7 Mon Sep 17 00:00:00 2001 From: ory-bot <60093411+ory-bot@users.noreply.github.com> Date: Thu, 22 Sep 2022 00:30:12 +0000 Subject: [PATCH 2/3] autogen(openapi): regenerate swagger spec and internal client [skip ci] --- pipeline/mutate/mutator_hydrator.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pipeline/mutate/mutator_hydrator.go b/pipeline/mutate/mutator_hydrator.go index 371a455ded..c78569dbdb 100644 --- a/pipeline/mutate/mutator_hydrator.go +++ b/pipeline/mutate/mutator_hydrator.go @@ -27,6 +27,7 @@ import ( "crypto/md5" "encoding/json" "fmt" + "io" "net/http" "net/url" "time" @@ -53,8 +54,8 @@ const ( ErrNoCredentialsProvided = "No credentials were provided in mutator configuration" contentTypeHeaderKey = "Content-Type" contentTypeJSONHeaderValue = "application/json" - acceptEncodingHeaderKey = "Accept-Encoding" - acceptEncodingHeaderValue = "gzip, deflate" + acceptEncodingHeaderKey = "Accept-Encoding" + acceptEncodingHeaderValue = "gzip, deflate" ) type MutatorHydrator struct { @@ -239,7 +240,7 @@ func (a *MutatorHydrator) Mutate(r *http.Request, session *authn.AuthenticationS default: return errors.New(ErrNon200ResponseFromAPI) } - + // Handle compressed data var reader io.ReadCloser switch res.Header.Get("Content-Encoding") { From 1954dd04ac4b50540113d09f2bf264cc6cd9ba97 Mon Sep 17 00:00:00 2001 From: Michiel <918128+mvanderlee@users.noreply.github.com> Date: Wed, 21 Sep 2022 21:34:37 -0300 Subject: [PATCH 3/3] add io import --- pipeline/mutate/mutator_hydrator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pipeline/mutate/mutator_hydrator.go b/pipeline/mutate/mutator_hydrator.go index 371a455ded..ef2f81190e 100644 --- a/pipeline/mutate/mutator_hydrator.go +++ b/pipeline/mutate/mutator_hydrator.go @@ -27,6 +27,7 @@ import ( "crypto/md5" "encoding/json" "fmt" + "io" "net/http" "net/url" "time"