🗃️ Check loopback hostnames in HTTP client repository

This commit is contained in:
Maxim Lebedev 2022-07-29 01:24:56 +05:00
parent 61f1324c27
commit fcc2a9aa0f
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package http
import (
"context"
"fmt"
"net"
http "github.com/valyala/fasthttp"
@ -33,6 +34,19 @@ func NewHTTPClientRepository(c *http.Client) client.Repository {
}
func (repo *httpClientRepository) Get(ctx context.Context, cid *domain.ClientID) (*domain.Client, error) {
ips, err := net.LookupIP(cid.URL().Hostname())
if err != nil {
return nil, fmt.Errorf("cannot resolve client IP by id: %w", err)
}
for _, ip := range ips {
if !ip.IsLoopback() {
continue
}
return nil, client.ErrNotExist
}
req := http.AcquireRequest()
defer http.ReleaseRequest(req)
req.SetRequestURI(cid.String())