1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Improved searching for provider-metadata.json

* Changes order to try the DNS path after security.txt.
* Add diagnostic output which URL is looked for.
This commit is contained in:
Bernhard Reiter 2022-05-17 16:08:38 +02:00
parent 2cfb4b8e49
commit 9eca8a924f
No known key found for this signature in database
GPG key ID: 2B7BA3BF9BC3A554

View file

@ -729,6 +729,7 @@ func (p *processor) locateProviderMetadata(
client := p.httpClient()
tryURL := func(url string) (bool, error) {
log.Printf("Trying: %v\n", url)
res, err := client.Get(url)
if err != nil || res.StatusCode != http.StatusOK ||
res.Header.Get("Content-Type") != "application/json" {
@ -762,32 +763,38 @@ func (p *processor) locateProviderMetadata(
// Read from security.txt
path := "https://" + domain + "/.well-known/security.txt"
log.Printf("Searching in: %v\n", path)
res, err := client.Get(path)
if err != nil {
return err
}
if res.StatusCode != http.StatusOK {
return nil
}
if err == nil && res.StatusCode == http.StatusOK {
loc, err := func() (string, error) {
defer res.Body.Close()
return p.extractProviderURL(res.Body)
}()
if err != nil {
log.Printf("error: %v\n", err)
return nil
log.Printf("did not find provider URL in /.well-known/security.txt, error: %v\n", err)
}
if loc != "" {
if _, err = tryURL(loc); err == errContinue {
err = nil
}
return err
}
}
// Read from DNS path
path = "https://csaf.data.security." + domain
ok, err := tryURL(path)
if err != nil {
return err
}
if ok {
return nil
}
return errStop
}
func (p *processor) extractProviderURL(r io.Reader) (string, error) {