From bd9a303e2974d9933b865404f7ed52cba9c5723c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 6 Apr 2021 16:53:32 +0300 Subject: [PATCH] oracle: URI host validation is only relevant for https NeoFS doesn't have hosts. --- pkg/services/oracle/request.go | 53 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/pkg/services/oracle/request.go b/pkg/services/oracle/request.go index f0d5f48ee..df7cc82dd 100644 --- a/pkg/services/oracle/request.go +++ b/pkg/services/oracle/request.go @@ -97,35 +97,40 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error { } resp := &transaction.OracleResponse{ID: req.ID} u, err := url.ParseRequestURI(req.Req.URL) - if err == nil && !o.MainCfg.AllowPrivateHost { - err = o.URIValidator(u) - } if err != nil { resp.Code = transaction.Forbidden } else if u.Scheme == "https" { - r, err := o.Client.Get(req.Req.URL) - switch { - case err != nil: - resp.Code = transaction.Error - case r.StatusCode == http.StatusOK: - result, err := readResponse(r.Body, transaction.MaxOracleResultSize) + if !o.MainCfg.AllowPrivateHost { + err = o.URIValidator(u) if err != nil { - if errors.Is(err, ErrResponseTooLarge) { - resp.Code = transaction.ResponseTooLarge - } else { - resp.Code = transaction.Error - } - break + resp.Code = transaction.Forbidden + } + } + if err == nil { + r, err := o.Client.Get(req.Req.URL) + switch { + case err != nil: + resp.Code = transaction.Error + case r.StatusCode == http.StatusOK: + result, err := readResponse(r.Body, transaction.MaxOracleResultSize) + if err != nil { + if errors.Is(err, ErrResponseTooLarge) { + resp.Code = transaction.ResponseTooLarge + } else { + resp.Code = transaction.Error + } + break + } + resp.Code, resp.Result = filterRequest(result, req.Req) + case r.StatusCode == http.StatusForbidden: + resp.Code = transaction.Forbidden + case r.StatusCode == http.StatusNotFound: + resp.Code = transaction.NotFound + case r.StatusCode == http.StatusRequestTimeout: + resp.Code = transaction.Timeout + default: + resp.Code = transaction.Error } - resp.Code, resp.Result = filterRequest(result, req.Req) - case r.StatusCode == http.StatusForbidden: - resp.Code = transaction.Forbidden - case r.StatusCode == http.StatusNotFound: - resp.Code = transaction.NotFound - case r.StatusCode == http.StatusRequestTimeout: - resp.Code = transaction.Timeout - default: - resp.Code = transaction.Error } } else if err == nil && u.Scheme == neofs.URIScheme { ctx, cancel := context.WithTimeout(context.Background(), time.Duration(o.MainCfg.NeoFS.Timeout)*time.Millisecond)