urlfilter

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: GPL-3.0 Imports: 4 Imported by: 9

README

Build Status Code Coverage Go Report Card GolangCI Go Doc

AdGuard content blocking library

Pure GO library that implements AdGuard filtering rules syntax.

You can learn more about AdGuard filtering rules syntax from this article.

TODO:
  • Basic filtering rules
  • Benchmark basic rules matching
  • Hosts matching rules
    • /etc/hosts matching
    • $badfilter support for host-blocking network rules
  • Memory optimization
  • Tech document
  • Cosmetic rules
    • Basic element hiding and CSS rules
      • Proper CSS rules validation
    • ExtCSS rules
    • Scriptlet rules
    • JS rules
  • Proxy implementation
    • Simple MITM proxy example
    • Add cosmetic filters to the proxy example
    • Handling cosmetic modifiers $elemhide, $generichide, $jsinject
    • (!) Server certificate verification - it should pass badssl.com/dashboard/
    • Unit tests coverage
    • Fix TODOs
    • Proxy - handle CSP (including tags with CSP)
    • Proxy - proper blocking page code
    • Proxy - unblocking via a temporary cookie
    • Proxy - content script caching
    • Proxy - content script compression
    • Proxy - brotli support (see here)
    • Content script - babel plugin
    • Content script - apply ExtCSS rules
    • Content script - styles protection
    • Content script - JS unit tests
    • Content script - GO unit tests
  • HTML filtering rules
  • Advanced modifiers
    • $important
    • $replace
    • $csp
    • $cookie
    • $redirect
    • $badfilter
How to use

TODO

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CosmeticEngine

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

CosmeticEngine combines all the cosmetic rules and allows to quickly find all rules matching this or that hostname

func NewCosmeticEngine

func NewCosmeticEngine(s *filterlist.RuleStorage) *CosmeticEngine

NewCosmeticEngine builds a new cosmetic engine from the specified rule storage

func (*CosmeticEngine) Match

func (e *CosmeticEngine) Match(hostname string, includeCSS bool, includeJS bool, includeGenericCSS bool) CosmeticResult

Match builds scripts and styles that needs to be injected into the specified page hostname is the page hostname includeCSS defines if we should inject any CSS and element hiding rules (see $elemhide) includeJS defines if we should inject JS into the page (see $jsinject) includeGenericCSS defines if we should inject generic CSS and element hiding rules (see $generichide) TODO: Additionally, we should provide a method that writes result to an io.Writer

type CosmeticResult

type CosmeticResult struct {
	ElementHiding StylesResult
	CSS           StylesResult
	JS            ScriptsResult
}

CosmeticResult represents all scripts and styles that needs to be injected into the page

type DNSEngine

type DNSEngine struct {
	RulesCount int // count of rules loaded to the engine
	// contains filtered or unexported fields
}

DNSEngine combines host rules and network rules and is supposed to quickly find matching rules for hostnames. First, it looks over network rules and returns first rule found. Then, if nothing found, it looks up the host rules.

func NewDNSEngine

func NewDNSEngine(s *filterlist.RuleStorage) *DNSEngine

NewDNSEngine parses the specified filter lists and returns a DNSEngine built from them. key of the map is the filter list ID, value is the raw content of the filter list.

func (*DNSEngine) Match

func (d *DNSEngine) Match(hostname string) ([]rules.Rule, bool)

Match finds a matching rule for the specified hostname. It returns true and the list of rules found or false and nil. The list of rules can be found when there're multiple host rules matching the same domain. For instance: 192.168.0.1 example.local 2000::1 example.local

type Engine

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

Engine represents the filtering engine with all the loaded rules

func NewEngine

func NewEngine(s *filterlist.RuleStorage) *Engine

NewEngine parses the filtering rules and creates a filtering engine of them

func (*Engine) GetCosmeticResult added in v0.6.0

func (e *Engine) GetCosmeticResult(hostname string, option rules.CosmeticOption) CosmeticResult

GetCosmeticResult gets cosmetic result for the specified hostname and cosmetic options

func (*Engine) MatchRequest added in v0.6.0

func (e *Engine) MatchRequest(r *rules.Request) rules.MatchingResult

MatchRequest - matches the specified request against the filtering engine and returns the matching result.

type NetworkEngine

type NetworkEngine struct {
	RulesCount int // RulesCount -- count of rules added to the engine
	// contains filtered or unexported fields
}

NetworkEngine is the engine that supports quick search over network rules

func NewNetworkEngine

func NewNetworkEngine(s *filterlist.RuleStorage) *NetworkEngine

NewNetworkEngine builds an instance of the network engine

func (*NetworkEngine) Match

func (n *NetworkEngine) Match(r *rules.Request) (*rules.NetworkRule, bool)

Match searches over all filtering rules loaded to the engine It returns true if a match was found alongside the matching rule

func (*NetworkEngine) MatchAll

func (n *NetworkEngine) MatchAll(r *rules.Request) []*rules.NetworkRule

MatchAll finds all rules matching the specified request regardless of the rule types It will find both whitelist and blacklist rules

type ScriptsResult added in v0.6.0

type ScriptsResult struct {
	Generic  []string
	Specific []string
}

ScriptsResult contains scripts to be executed on a page

type StylesResult added in v0.6.0

type StylesResult struct {
	Generic        []string `json:"generic"`
	Specific       []string `json:"specific"`
	GenericExtCSS  []string `json:"genericExtCss"`
	SpecificExtCSS []string `json:"specificExtCss"`
}

StylesResult contains either element hiding or CSS rules

Directories

Path Synopsis
examples
proxy command
internal
tools module

Jump to

Keyboard shortcuts

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