Skip to content

Commit f33d6a8

Browse files
alnrory-bot
authored andcommitted
fix: context passing and limit response size
GitOrigin-RevId: feda18ad48f8ba9dcd3a81ac7a5a941c7ddad43c
1 parent d0e0659 commit f33d6a8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

fosite/authorize_request_handler.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ import (
1111
"strings"
1212

1313
"github.com/go-jose/go-jose/v3"
14+
"github.com/hashicorp/go-retryablehttp"
15+
"github.com/pkg/errors"
1416
"go.opentelemetry.io/otel/trace"
1517

18+
"github.com/ory/go-convenience/stringslice"
1619
"github.com/ory/hydra/v2/fosite/i18n"
1720
"github.com/ory/hydra/v2/fosite/token/jwt"
1821
"github.com/ory/x/errorsx"
1922
"github.com/ory/x/otelx"
20-
21-
"github.com/pkg/errors"
22-
23-
"github.com/ory/go-convenience/stringslice"
2423
)
2524

2625
func wrapSigningKeyFailure(outer *RFC6749Error, inner error) *RFC6749Error {
@@ -66,11 +65,16 @@ func (f *Fosite) authorizeRequestParametersFromOpenIDConnectRequest(ctx context.
6665
}
6766

6867
hc := f.Config.GetHTTPClient(ctx)
69-
response, err := hc.Get(location)
68+
req, err := retryablehttp.NewRequestWithContext(ctx, "GET", location, nil)
69+
if err != nil {
70+
return errorsx.WithStack(ErrInvalidRequestURI.WithHintf("Unable to fetch OpenID Connect request parameters from 'request_uri' because: %s.", err.Error()).WithWrap(err).WithDebug(err.Error()))
71+
}
72+
response, err := hc.Do(req)
7073
if err != nil {
7174
return errorsx.WithStack(ErrInvalidRequestURI.WithHintf("Unable to fetch OpenID Connect request parameters from 'request_uri' because: %s.", err.Error()).WithWrap(err).WithDebug(err.Error()))
7275
}
7376
defer response.Body.Close()
77+
response.Body = io.NopCloser(io.LimitReader(response.Body, 10*1024*1024)) // limit to 10MiB
7478

7579
if response.StatusCode != http.StatusOK {
7680
return errorsx.WithStack(ErrInvalidRequestURI.WithHintf("Unable to fetch OpenID Connect request parameters from 'request_uri' because status code '%d' was expected, but got '%d'.", http.StatusOK, response.StatusCode))

0 commit comments

Comments
 (0)