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:
parent
2cfb4b8e49
commit
9eca8a924f
1 changed files with 27 additions and 20 deletions
|
|
@ -729,6 +729,7 @@ func (p *processor) locateProviderMetadata(
|
||||||
client := p.httpClient()
|
client := p.httpClient()
|
||||||
|
|
||||||
tryURL := func(url string) (bool, error) {
|
tryURL := func(url string) (bool, error) {
|
||||||
|
log.Printf("Trying: %v\n", url)
|
||||||
res, err := client.Get(url)
|
res, err := client.Get(url)
|
||||||
if err != nil || res.StatusCode != http.StatusOK ||
|
if err != nil || res.StatusCode != http.StatusOK ||
|
||||||
res.Header.Get("Content-Type") != "application/json" {
|
res.Header.Get("Content-Type") != "application/json" {
|
||||||
|
|
@ -762,32 +763,38 @@ func (p *processor) locateProviderMetadata(
|
||||||
// Read from security.txt
|
// Read from security.txt
|
||||||
|
|
||||||
path := "https://" + domain + "/.well-known/security.txt"
|
path := "https://" + domain + "/.well-known/security.txt"
|
||||||
|
log.Printf("Searching in: %v\n", path)
|
||||||
res, err := client.Get(path)
|
res, err := client.Get(path)
|
||||||
if err != nil {
|
if err == nil && res.StatusCode == http.StatusOK {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
loc, err := func() (string, error) {
|
loc, err := func() (string, error) {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
return p.extractProviderURL(res.Body)
|
return p.extractProviderURL(res.Body)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error: %v\n", err)
|
log.Printf("did not find provider URL in /.well-known/security.txt, error: %v\n", err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if loc != "" {
|
if loc != "" {
|
||||||
if _, err = tryURL(loc); err == errContinue {
|
if _, err = tryURL(loc); err == errContinue {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read from DNS path
|
||||||
|
|
||||||
|
path = "https://csaf.data.security." + domain
|
||||||
|
ok, err := tryURL(path)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errStop
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) extractProviderURL(r io.Reader) (string, error) {
|
func (p *processor) extractProviderURL(r io.Reader) (string, error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue