Documentation
¶
Overview ¶
Package privacy implements Sweef's built-in tracker/ad blocking policy: a compact domain blocklist, first-party/third-party classification, HTTPS upgrade, referrer trimming, GPC/DNT headers and third-party cookie filtering. It is pure Go and independent of the engine; internal/app wires it to engine tabs.
Index ¶
- func Compile(src string) []byte
- func IsLocalHost(h string) bool
- func SameSite(a, b string) bool
- type Blocklist
- type Decision
- type Engine
- func (e *Engine) Active(topHost, cookieHost string) bool
- func (e *Engine) Check(topURL, reqURL string) Decision
- func (e *Engine) CookieOK(topHost, cookieHost string) bool
- func (e *Engine) Headers() map[string]string
- func (e *Engine) Settings() Settings
- func (e *Engine) Total() int64
- func (e *Engine) TrimReferrer(referrer, target string) string
- func (e *Engine) Update(s Settings)
- func (e *Engine) Upgrade(raw string) (string, bool)
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
Compile turns a text list into the compact binary form. Accepted lines: `example.com`, `||example.com^` (Adblock-style domain rule), `@@example.com` or `@@||example.com^` (exception), `# comment`, `! comment`, hosts-file lines `0.0.0.0 example.com`. Each rule covers the domain and all its subdomains.
func IsLocalHost ¶
IsLocalHost reports hosts that must never be upgraded or blocked.
Types ¶
type Blocklist ¶
type Blocklist struct {
// contains filtered or unexported fields
}
Blocklist answers "is this host blocked" over the compiled form.
func FromCompiled ¶
FromCompiled wraps already compiled data.
func NewBlocklist ¶
NewBlocklist creates a lazily loaded blocklist: loader runs on first lookup, never at construction (start-up costs nothing).
func SeedList ¶
func SeedList() *Blocklist
SeedList returns the embedded seed blocklist (compiled lazily on first lookup, so merely linking it costs nothing at start-up). It is seed data, not a complete filter list.
type Decision ¶
type Decision struct {
Block bool
Rule string // matching blocklist domain
Reason string // "tracker" | ""
}
Decision is the verdict for one request.
type Engine ¶
type Engine struct {
List *Blocklist
S atomic.Pointer[Settings]
Exceptions func(topOrigin string) (noBlock bool)
// contains filtered or unexported fields
}
Engine decides per request. Exceptions is consulted with the top-level page's origin so users can turn protection off per site.
func (*Engine) Active ¶
Active reports whether third-party cookie blocking applies to a response from cookieHost while the top-level page is on topHost.
func (*Engine) Check ¶
Check decides whether reqURL, requested by a page at topURL, is blocked. Only third-party requests are ever blocked, and never the top-level document itself.
func (*Engine) CookieOK ¶
CookieOK reports whether a cookie set for cookieHost while the top-level page is topHost may be stored (third-party cookie blocking).
func (*Engine) TrimReferrer ¶
TrimReferrer applies the strict-origin-when-cross-origin policy used by default in modern browsers: same-origin keeps the path, cross-origin sends only the origin, and https->http sends nothing. Credentials and fragments are always stripped. With trimming off, only credentials/fragments go.
type Settings ¶
type Settings struct {
BlockTrackers bool
HTTPSUpgrade bool
BlockThirdPartyCookies bool
SendGPC bool
TrimReferrer bool
}
Settings is the privacy configuration (mirrors the stored settings).
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings is what a fresh profile gets.