Skip to content

Commit

Permalink
Fix possible panic in aws app access (#39673)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis authored Mar 21, 2024
1 parent 62ccdac commit a683fa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/srv/app/aws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ func rewriteRequest(ctx context.Context, r *http.Request, re *endpoints.Resolved
outReq.URL.Scheme = "https"
outReq.URL.Host = u.Host
}
outReq.Body = io.NopCloser(io.LimitReader(r.Body, teleport.MaxHTTPRequestSize))
outReq.Body = http.NoBody
if r.Body != nil {
outReq.Body = io.NopCloser(io.LimitReader(r.Body, teleport.MaxHTTPRequestSize))
}
// need to rewrite the host header as well. The oxy forwarder will do this for us,
// since we use the PassHostHeader(false) option, but if host is a signed header
// then we must make the host match the URL host before signing the request or AWS
Expand Down
14 changes: 14 additions & 0 deletions lib/srv/app/aws/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@ func TestAWSSignerHandler(t *testing.T) {
}
}

func TestRewriteRequest(t *testing.T) {
expectedReq, err := http.NewRequest("GET", "https://example.com", http.NoBody)
require.NoError(t, err)
ctx := context.Background()

inputReq := mustNewRequest(t, "GET", "https://example.com", nil)
actualOutReq, err := rewriteRequest(ctx, inputReq, &endpoints.ResolvedEndpoint{})
require.NoError(t, err)
require.Equal(t, expectedReq, actualOutReq, err)

_, err = io.ReadAll(actualOutReq.Body)
require.NoError(t, err)
}

func TestURLForResolvedEndpoint(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit a683fa2

Please sign in to comment.