threatfeed

package
v1.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package threatfeed is the local threat-feed manager: it downloads, persists, and provides instant offline lookups for known-malicious URL/domain lists. Zero external API dependency — all feeds are freely available without registration or rate limits.

Feeds:

The feed data is stored in a JSON file so the proxy survives restarts without waiting for a fresh download. A background goroutine re-syncs on the configured interval (default: 6 hours).

Extracted from package main per ADR-0002. The package is a pure leaf: the SSRF private-IP table comes from internal/ssrf, durable writes from internal/fileutil, and logging from the obs facade (including the new obs.Debugf for the sync-start debug line). package main keeps the globalThreatFeed singleton and the admin/cluster surfaces behind a type alias.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormaliseURL

func NormaliseURL(raw string) (norm, host string)

NormaliseURL parses a raw URL string into a canonical lookup key (scheme + host + path, no query or fragment) and the bare hostname. Returns ("", "") for invalid, private-IP, or non-HTTP(S) entries.

Types

type Feed

type Feed struct {
	// contains filtered or unexported fields
}

Feed manages local copies of public threat intelligence lists. All methods are safe for concurrent use.

func New

func New() *Feed

New returns an idle Feed with the same shape as the pre-extraction package-main literal: initialised maps and the 6-hour default sync interval. Init configures and enables it.

func (*Feed) AddDomainAllowlist

func (tf *Feed) AddDomainAllowlist(domain string)

AddDomainAllowlist adds a domain to the allowlist and persists.

func (*Feed) CheckDomain

func (tf *Feed) CheckDomain(domain string) (malicious bool, source string)

CheckDomain looks up a bare hostname against the threat feed. Returns (isMalicious, sourceName).

func (*Feed) CheckURL

func (tf *Feed) CheckURL(rawURL string) (malicious bool, source string)

CheckURL looks up a full URL against the threat feed. Returns (isMalicious, sourceName).

func (*Feed) DomainAllowlist

func (tf *Feed) DomainAllowlist() []string

DomainAllowlist returns the current allowlist entries sorted.

func (*Feed) DomainAllowlisted

func (tf *Feed) DomainAllowlisted(domain string) bool

DomainAllowlisted reports whether a domain is on the threat-feed allowlist (domain-level blocking skipped; URL-level blocking still applies).

func (*Feed) Enabled

func (tf *Feed) Enabled() bool

Enabled reports whether the feed is active.

func (*Feed) ExportDomains

func (tf *Feed) ExportDomains() map[string]int64

ExportDomains returns a copy of the domain threat map as domain→unix-timestamp. Used by the Control Plane to include feed data in config sync.

func (*Feed) ExportURLs

func (tf *Feed) ExportURLs() map[string]int64

ExportURLs returns a copy of the URL threat map as url→unix-timestamp. Used by the Control Plane to include feed data in config sync.

func (*Feed) ImportFeedData

func (tf *Feed) ImportFeedData(urls map[string]int64, domains map[string]int64)

ImportFeedData replaces the in-memory URL and domain maps with data received from the Control Plane config sync. Each value is a unix timestamp (added_at). The source is set to "cluster-sync" to distinguish from direct feed downloads.

func (*Feed) Init

func (tf *Feed) Init(dbPath string, syncInterval time.Duration)

Init configures the feed manager and loads any persisted DB from disk. dbPath may be "" to disable persistence (feed data lives in-memory only).

func (*Feed) RemoveDomainAllowlist

func (tf *Feed) RemoveDomainAllowlist(domain string)

RemoveDomainAllowlist removes a domain from the allowlist and persists.

func (*Feed) Save

func (tf *Feed) Save()

Save is the caller-facing wrapper around saveToDisk. Used by paths like applyConfigSnapshot that mutate via ImportFeedData — which does NOT auto-persist (unlike SetDomainAllowlist / AddDomainAllowlist / RemoveDomainAllowlist which call saveToDisk internally). Errors are logged, not returned, to match the void-Save convention of the other Bucket-1 snapshot stores (policyStore, globalProfileStore, etc.).

func (*Feed) SeedForTest

func (tf *Feed) SeedForTest(urls, domains map[string]string)

SeedForTest inserts URL and domain entries directly (value = source name), replacing the whitebox map pokes package main's integration tests used pre-extraction. AddedAt is stamped now; totalEntries tracks the URL count.

func (*Feed) SetDBPathForTest

func (tf *Feed) SetDBPathForTest(path string) (old string)

SetDBPathForTest swaps the persistence path and returns the previous one. Test support for main-side durability tests that point the process-wide feed at a temp dir; pair the restore with ImportFeedData(nil, nil) to clear seeded data.

func (*Feed) SetDomainAllowlist

func (tf *Feed) SetDomainAllowlist(domains []string)

SetDomainAllowlist replaces the entire allowlist and persists to disk.

func (*Feed) Start

func (tf *Feed) Start(ctx context.Context)

Start launches the background sync goroutine. An immediate sync is performed when the cache is empty or has never synced.

func (*Feed) Stats

func (tf *Feed) Stats() (int64, time.Time, time.Duration)

Stats returns (totalEntries, lastSync, syncInterval) for monitoring.

func (*Feed) Sync

func (tf *Feed) Sync()

Sync downloads all configured feeds and atomically replaces the in-memory lookup tables. Safe to call concurrently; calls run sequentially.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL