Skip to content

Commit

Permalink
do not parse url unless not found in dns registry
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmel committed Feb 22, 2024
1 parent d5b8316 commit 5569aaf
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,27 @@ func (s *suaveRuntime) doHTTPRequest(request types.HttpRequest) ([]byte, error)
body = bytes.NewReader(request.Body)
}

// decode the url and check if the domain is allowed
parsedURL, err := url.Parse(request.Url)
if err != nil {
panic(err)
}

var allowed bool
// resolve dns if possible
if endpoint, ok := s.suaveContext.Backend.DnsRegistry[request.Url]; ok {
request.Url = endpoint
allowed = true
} else {
// decode the url and check if the domain is allowed
parsedURL, err := url.Parse(request.Url)
if err != nil {
panic(err)
}

// check if the domain is allowed
for _, allowedDomain := range s.suaveContext.Backend.ExternalWhitelist {
if allowedDomain == "*" || allowedDomain == parsedURL.Hostname() {
allowed = true
break
}
}
}

if !allowed {
return nil, fmt.Errorf("domain %s is not allowed", parsedURL.Hostname())
if !allowed {
return nil, fmt.Errorf("domain %s is not allowed", parsedURL.Hostname())
}
}

req, err := http.NewRequest(request.Method, request.Url, body)
Expand Down

0 comments on commit 5569aaf

Please sign in to comment.