Documentation
¶
Overview ¶
Package fetch provides an SSRF-hardened HTTP client for safely retrieving content from external URLs. It enforces HTTPS-only access, domain allowlists, DNS pre-resolution with IP validation, and DNS-rebinding protection via transport-level IP pinning.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultPolicy = FetchPolicy{ AllowedDomains: []string{"github.com", "raw.githubusercontent.com"}, MaxSizeBytes: 10 * 1024 * 1024, Timeout: 30 * time.Second, }
DefaultPolicy is a sensible default policy allowing GitHub content hosts.
Functions ¶
func AppendFetchAudit ¶
func AppendFetchAudit(logPath string, entry FetchAuditEntry) error
AppendFetchAudit writes a fetch audit entry as a JSON line to the given log path.
func ComputeSHA256 ¶
ComputeSHA256 returns the lowercase hex-encoded SHA-256 digest of data.
Types ¶
type FetchAuditEntry ¶
type FetchAuditEntry struct {
TraceID string `json:"trace_id"`
FetchTime time.Time `json:"fetch_time"`
URL string `json:"url"`
SHA256 string `json:"sha256"`
FetchType string `json:"fetch_type"`
AllowedBy string `json:"allowed_by"`
CacheHit bool `json:"cache_hit"`
}
FetchAuditEntry is a JSONL audit record for a remote resource fetch.
type FetchPolicy ¶
type FetchPolicy struct {
// AllowedDomains is the list of permitted hostnames. Entries may use a
// wildcard prefix (e.g. "*.example.com") to match any subdomain,
// including multi-level subdomains (e.g. "deep.sub.example.com").
AllowedDomains []string
// AllowedPorts restricts which ports may be used. When empty, only
// port 443 is permitted.
AllowedPorts []string
// MaxSizeBytes is the maximum response body size in bytes.
MaxSizeBytes int64
// Timeout is the overall HTTP request timeout.
Timeout time.Duration
// Offline, when true, causes FetchURL to reject all requests immediately.
Offline bool
// contains filtered or unexported fields
}
FetchPolicy controls the security constraints applied when fetching a URL.
Click to show internal directories.
Click to hide internal directories.