Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check content-length header in lowercase #530

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: check content-length header in lowercase
Issue #422 didn't fix the problem with the requests' Content-Length
being copied in the responses because the check was case-sensitive and
unit tests didn't cover it.
  • Loading branch information
flusflas committed Sep 29, 2020
commit 85877425531e833a938808e1c8dd365537e5f4b0
3 changes: 2 additions & 1 deletion api/decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package api

import (
"net/http"
"strings"

"github.com/ory/oathkeeper/pipeline/authn"
"github.com/ory/oathkeeper/x"
Expand Down Expand Up @@ -123,7 +124,7 @@ func (h *DecisionHandler) decisions(w http.ResponseWriter, r *http.Request) {

for k := range s.Header {
// Avoid copying the original Content-Length header from the client
if k == "content-length" {
if strings.ToLower(k) == "content-length" {
continue
}

Expand Down
5 changes: 4 additions & 1 deletion api/decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package api_test

import (
"bytes"
"context"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -95,6 +96,7 @@ func TestDecisionAPI(t *testing.T) {
for k, tc := range []struct {
url string
code int
reqBody []byte
messages []string
rulesRegexp []rule.Rule
rulesGlob []rule.Rule
Expand Down Expand Up @@ -303,6 +305,7 @@ func TestDecisionAPI(t *testing.T) {
Mutators: []rule.Handler{{Handler: "noop"}},
Upstream: rule.Upstream{URL: ""},
}},
reqBody: []byte("non-empty body"),
transform: func(r *http.Request) {
r.Header.Add("Content-Length", "1337")
},
Expand All @@ -313,7 +316,7 @@ func TestDecisionAPI(t *testing.T) {
t.Run(fmt.Sprintf("case=%d/description=%s", k, tc.d), func(t *testing.T) {
testFunc := func(strategy configuration.MatchingStrategy) {
require.NoError(t, reg.RuleRepository().SetMatchingStrategy(context.Background(), strategy))
req, err := http.NewRequest("GET", tc.url, nil)
req, err := http.NewRequest("GET", tc.url, bytes.NewBuffer(tc.reqBody))
require.NoError(t, err)
if tc.transform != nil {
tc.transform(req)
Expand Down