Skip to content

Commit b1d4140

Browse files
committed
Update docker resolver to authorize redirects
Allows redirects to be authorized if authorization is provided for the redirected to host. The authorization will always go to the redirect and never to the referrer. Signed-off-by: Derek McGowan <derek@mcg.dev>
1 parent fe5d349 commit b1d4140

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

remotes/docker/resolver.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,21 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
539539
if err := r.authorize(ctx, req); err != nil {
540540
return nil, errors.Wrap(err, "failed to authorize")
541541
}
542-
resp, err := ctxhttp.Do(ctx, r.host.Client, req)
542+
543+
var client = &http.Client{}
544+
if r.host.Client != nil {
545+
*client = *r.host.Client
546+
}
547+
if client.CheckRedirect == nil {
548+
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
549+
if len(via) >= 10 {
550+
return errors.New("stopped after 10 redirects")
551+
}
552+
return errors.Wrap(r.authorize(ctx, req), "failed to authorize redirect")
553+
}
554+
}
555+
556+
resp, err := ctxhttp.Do(ctx, client, req)
543557
if err != nil {
544558
return nil, errors.Wrap(err, "failed to do request")
545559
}

0 commit comments

Comments
 (0)