// This file is part of the happyDomain (R) project. // Copyright (c) 2020-2026 happyDomain // Authors: Pierre-Olivier Mercier, et al. package checker import ( "context" "fmt" "net/http" ) // ObservationKeyWellKnown is the Extensions[] key under which // wellknownCollector publishes its observation. const ObservationKeyWellKnown = "wellknown" // WellKnownData captures whether each well-known URI returned a usable // document. It is intentionally narrow: per-URI presence and HTTP status // are enough for the current rule set; deeper parsing (e.g. PGP-signed // security.txt fields) is left to dedicated collectors when the need // arises. type WellKnownData struct { URIs map[string]WellKnownProbe `json:"uris"` } // WellKnownProbe is a single (URI → outcome) entry. type WellKnownProbe = PathProbe // wellknownCollector probes a small, fixed set of standardised URIs // served at the apex of the host. Today it covers: // // - /.well-known/security.txt (RFC 9116) — security disclosure contact // - /robots.txt (RFC 9309) — crawler directives // // It uses the first IP only because these documents are expected to be // host-uniform: there is nothing to learn from probing every backend. type wellknownCollector struct{} func (wellknownCollector) Key() string { return ObservationKeyWellKnown } func (wellknownCollector) Collect(ctx context.Context, t Target) (any, error) { if len(t.IPs) == 0 { return nil, fmt.Errorf("no IPs to probe") } transport, cleanup := newPinnedHTTPSTransport(t.IPs[0], t.Host, t.Timeout) defer cleanup() client := &http.Client{Transport: transport} uris := []string{"/.well-known/security.txt", "/robots.txt"} out := WellKnownData{URIs: make(map[string]WellKnownProbe, len(uris))} for _, path := range uris { out.URIs[path] = fetchHTTPSPath(ctx, client, t.Host, path, t.UserAgent, 64<<10) } return &out, nil } func init() { RegisterCollector(wellknownCollector{}) }