Brave's Rust-based adblock engine

Overview

Ad Block engine in Rust

docs.rs crates.io npmjs.com Build Status

Native Rust module for Adblock Plus syntax (e.g. EasyList, EasyPrivacy) filter parsing and matching.

It uses a tokenisation approach for quickly reducing the potentially matching rule search space against a URL.

The algorithm is inspired by, and closely follows the algorithm of uBlock Origin and Cliqz.

Somewhat graphical explanation of the algorithm:

Ad Block Algorithm

Demo

Demo use in Rust:

use adblock::engine::Engine;
use adblock::lists::{FilterSet, ParseOptions};

fn main() {
    let rules = vec![
        String::from("-advertisement-icon."),
        String::from("-advertisement-management/"),
        String::from("-advertisement."),
        String::from("-advertisement/script."),
    ];

    let mut filter_set = FilterSet::new(true);
    filter_set.add_filters(&rules, ParseOptions::default());

    let blocker = Engine::from_filter_set(filter_set, true);
    let blocker_result = blocker.check_network_urls("http://example.com/-advertisement-icon.", "http://example.com/helloworld", "image");

    println!("Blocker result: {:?}", blocker_result);
}

Node.js module demo

Note the Node.js module has overheads inherent to boundary crossing between JS and native code.

const AdBlockClient = require('adblock-rs');
let el_rules = fs.readFileSync('./data/easylist.to/easylist/easylist.txt', { encoding: 'utf-8' }).split('\n');
let ubo_unbreak_rules = fs.readFileSync('./data/uBlockOrigin/unbreak.txt', { encoding: 'utf-8' }).split('\n');
let rules = el_rules.concat(ubo_unbreak_rules);
let resources = AdBlockClient.uBlockResources('uBlockOrigin/src/web_accessible_resources', 'uBlockOrigin/src/js/redirect-engine.js', 'uBlockOrigin/assets/resources/scriptlets.js');

const filterSet = new AdBlockClient.FilterSet(true);
filterSet.addFilters(rules);
const client = new AdBlockClient.Engine(filterSet, true);
client.useResources(resources);

const serializedArrayBuffer = client.serializeRaw(); // Serialize the engine to an ArrayBuffer

console.log(`Engine size: ${(serializedArrayBuffer.byteLength / 1024 / 1024).toFixed(2)} MB`);

console.log("Matching:", client.check("http://example.com/-advertisement-icon.", "http://example.com/helloworld", "image"))
// Match with full debuging info
console.log("Matching:", client.check("http://example.com/-advertisement-icon.", "http://example.com/helloworld", "image", true))
// No, but still with debugging info
console.log("Matching:", client.check("https://github.githubassets.com/assets/frameworks-64831a3d.js", "https://github.com/AndriusA", "script", true))
// Example that inlcludes a redirect response
console.log("Matching:", client.check("https://bbci.co.uk/test/analytics.js", "https://bbc.co.uk", "script", true))

Optional features

CSS validation during rule parsing

When parsing cosmetic filter rules, it's possible to include a built-in implementation of CSS validation (through the selectors and cssparser crates) by enabling the css-validation feature. This will cause adblock-rust to reject cosmetic filter rules with invalid CSS syntax.

Content blocking format translation

Enabling the content-blocking feature gives adblock-rust support for conversion of standard ABP-style rules into Apple's content-blocking format, which can be exported for use on iOS and macOS platforms.

External domain resolution

By default, adblock-rust ships with a built-in domain resolution implementation (through the addr crate) that will generally suffice for standalone use-cases. For more advanced use-cases, disabling the embedded-domain-resolver feature will allow adblock-rust to use an external domain resolution implementation instead. This is extremely useful to reduce binary bloat and improve consistency when embedding adblock-rust within a browser.

Parsing resources from uBlock Origin's formats

adblock-rust uses uBlock Origin-compatible resources for scriptlet injection and redirect rules. The resource-assembler feature allows adblock-rust to parse these resources directly from the file formats used by the uBlock Origin repository.

Comments
  • Replace ABP-Japanese with Adguard Japanese (brave/adblock-lists#355)

    Replace ABP-Japanese with Adguard Japanese (brave/adblock-lists#355)

    Based on: https://github.com/brave/adblock-lists/issues/355 request. The most comprehensive list and also used by uBO as the default Japanese filter.

    Since ABP Japanese is not well supported and has many problematic filters; This change will help fix a few work arounds we needed to make (which will need to be reverted)

    https://github.com/brave/adblock-lists/pull/366 https://github.com/brave/adblock-lists/pull/319 https://github.com/brave/adblock-lists/pull/274 https://github.com/brave/adblock-lists/pull/270

    More Japanese filter issues, https://github.com/brave/adblock-lists/pulls?q=is%3Apr+is%3Aclosed+label%3Aregional

    opened by ryanbr 24
  • Added my Nordic list

    Added my Nordic list

    In light of recent developments that gave me a pretty good list conversion script, and closer connections to Fanboy (who seem to occasionally contribute to you guys), I will hereby do this new attempt at getting my Nordic list added to Brave Browser's adblocker.

    Some of the strings I replaced with "xxxxxxxxxx", as it was not obvious to me how to fill them with correct information when they're edited with GitHub's web GUI. You should almost guaranteed have been given full rights to do changes of your own to my PR branch.

    opened by DandelionSprout 15
  • make the library thread-safe

    make the library thread-safe

    I've tried to share an instance of Engine across threads and encountered that it can not be shared across threads as it is not thread-safe. Can you please replace Rc and RefCell with Arc and RwLock/Mutex so we can use this library in threads? Thanks!

    enhancement 
    opened by wavenator 12
  • ruadlist doesn't work right with Brave's adblocker

    ruadlist doesn't work right with Brave's adblocker

    Since Brave's adblocker announced it's compatible with UbO's filters, I used RuAdList-uBO.txt only to realize it doesn't support a filter including other filters like that. I ended up have to add each filter file of the ruadlist collection manually (so many of them!). It's somewhat worked, but still not as optimal as it is on UbO. On news.mail.ru there is still empty ad container boxes. These boxes should be removed (as they are on UbO). I'm always using dark mode, having a white box on a dark background make my eyes hurt. Please fix it.

    Update: my guess is Brave's adblocker does not fully support all of UbO's features so filter lists like css-fixes-experimental.txt and js-fixes-experimental.txt doesn't work optimally, I might have to install Stylus and ViolenMonkey to use the corresponding fixes like when using with Adblock Plus as stated on the easylist forum. But, it shouldn't be the case! Brave's adblocker should be compatible with all UbO filters isn't it?

    opened by tn1997tn 9
  • Add support for hostname filters in standard mode

    Add support for hostname filters in standard mode

    There was an issue in EasyList recently that broke some ad blockers. Even though the report doesn't mention Brave, the issue should have affected Brave too. Meanwhile, uBlock Origin was barely affected because it interpreted the filter in question as a hostname.

    Now this raises the question as to how such filters should be interpreted in general.

    The Brave implementation has two modes: standard and hosts. In hosts mode, a hostname on a line by itself is interpreted as a hostname. In standard mode, the same hostname must be specified using Adblock Plus syntax. For example, example.com must be encoded as ||example.com^.

    Should Brave adopt the uBlock Origin style in standard mode?

    The crux of the issue is that Adblock Plus-style filters tend to overblock by default. A filter like ad.png would block not only the URL https://example.com/ad.png (intended) but also the URL https://example.com/ipad.png (not intended). Similarly, the filter example.com would block https://example.com/ad.png (intended) but would also block https://example.computer/ad.png (not intended).

    Whereas filter developers are aware of such nuances, and indeed there are no such filters in EasyList et al, the average user who types a filter into a box (https://github.com/brave/brave-browser/issues/8838) is unlikely to go look up the syntax, learn it, and then correctly specify the hostname example.com as ||example.com^. In other words, the Adblock Plus syntax is not exactly user-friendly. Based on the recent incident, it also appears to be a bit of a footgun. We don't know how many end users are experiencing broken web pages because they were savvy enough to write their own filters by hand.

    The principle of least surprise dictates that if the pattern in a URL filter looks like a hostname, it should be interpreted as a hostname.

    $ grep -Ei '^(@@)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*(\$.*)?$' easylist.txt easyprivacy.txt | wc -l
    0
    

    This new "shorthand" syntax for hostnames would break 0 existing filters in EasyList and EasyPrivacy.

    $ grep -Ei '^(@@)?\|\|[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*\^(\$.*)?$' easylist.txt easyprivacy.txt | wc -l
    31825
    

    On the other hand, there are nearly 32,000 filters in EasyList and EasyPrivacy, out of a combined total of about 81,000 filters, that could be converted to use the new syntax at some point, reducing the size of the raw filter text by ~100 KiB.

    Not only would the shorthand syntax be more user-friendly, it might also have bandwidth, memory, and disk usage benefits over time.

    WDYT?

    opened by mjethani 8
  • Cosmetic filtering subsystem documentation

    Cosmetic filtering subsystem documentation

    Rules with statically typed attributes don't seem to be handled by the library. For instance, div[class='a-class'] is equivalent to div.a-class. However, in the code below and unless I am mistaking, the "hidden_class_id_selectors" method should return a non empty vector corresponding to the first rule in the set.

    The "hidden_class_id_selectors" seems to be using the masks set in the CosmeticFilter object related to the rule ("div[class='a-class']") , however, printing it shows no masks being set for it, which causes the CosmeticFilterCache to store the rule in misc_generic_selectors which is in turn ignored by the method "hidden_class_id_selectors".

    let rules = [
                String::from("##div[class='a-class']"),
                String::from("##div[class*=\"Ads\"]"),
                String::from("##.a-class")
            ];
    // For debugging purpose
    rules.iter().for_each(|rule| {
        let cf: CosmeticFilter = CosmeticFilter::parse(rule, false).unwrap();
        println!("{:?}", cf);
    });
    //----
    
    let blocker = Engine::from_rules_debug(&rules, FilterFormat::Standard)
    let example_class_report = blocker.hidden_class_id_selectors(&["div.a-class".into()], &[], &HashSet::default());
    
    println!("Report for a-class: {:?}", example_class_report);
    

    Are these rules supported in the current version ? If yes, how are they supposed to be used ? Similarly, are composed rules (for example, "div#ads > .advertisement") also handled ? Some additional documentation/examples should be added regarding the usage of cosmetic rules.

    Please let me know if my facts are wrong as I am getting started with the Rust language/library.

    opened by naifmeh 8
  • Replace Prebake with Easylist Cookie

    Replace Prebake with Easylist Cookie

    Since Prebake Cookie hasn't been updated since 2018, we should replace this with Easylist Cookie.

    Should help with cookie notices and resolve brave/brave-browser#5318 Will be more affective when we roll out cosmetic filtering.

    Rebase of https://github.com/brave/adblock-rust/pull/67 (just had some merge issues)

    Also re-did component_id: and base64_public_key:

    PEM's also updated/uploaded.

    opened by ryanbr 8
  • Bump tokio from 1.8.0 to 1.8.4

    Bump tokio from 1.8.0 to 1.8.4

    Bumps tokio from 1.8.0 to 1.8.4.

    Release notes

    Sourced from tokio's releases.

    Tokio v1.8.4

    1.8.4 (November 15, 2021)

    This release backports a bugfix for a data race when sending and receiving on a closed oneshot channel ([RUSTSEC-2021-0124]) from v1.13.1.

    Fixed

    • sync: fix a data race between oneshot::Sender::send and awaiting a oneshot::Receiver when the oneshot has been closed (#4226)

    Tokio v1.8.3

    1.8.3 (July 22, 2021)

    This release backports two fixes from 1.9.0

    Fixed

    • Fix leak if output of future panics on drop (#3967)
    • Fix leak in LocalSet (#3978)

    #3967: tokio-rs/tokio#3967 #3978: tokio-rs/tokio#3978

    Tokio 1.8.2

    Fixes a missed edge case from 1.8.1.

    Fixed

    • runtime: drop canceled future on next poll (#3965)

    Tokio 1.8.1

    Forward ports 1.5.1 fixes.

    Fixed

    • runtime: remotely abort tasks on JoinHandle::abort (#3934)

    #3934: tokio-rs/tokio#3934

    Commits
    • 2273eb1 chore: fix CI on master (#4008)
    • 249f05c chore: fix output of macro after new rustc release (#4189)
    • 2bf6132 macros: fix type resolution error in #[tokio::main] (#4176)
    • c9228bf macros: make tokio-macros attributes more IDE friendly (#4162)
    • 441427c macros: fix wrong error messages (#4067)
    • cc7d9e1 chore: explicitly relaxed clippy lint for runtime entry macro (#4030)
    • f49b7fc tokio-macros: compat with clippy::unwrap_used (#3926)
    • ea87e4e net: fix the uds_datagram tests with the latest nightly stdlib (#3952)
    • e2e7b5e examples: replace time crate with httpdate (#4169)
    • 9a58f7f tests: update Nix to 0.22.0 (#3951)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies rust 
    opened by dependabot[bot] 6
  • Add Notification list to Brave

    Add Notification list to Brave

    This will block Notification servers being used in Brave;

    From our recent merge of Notification lists; https://github.com/brave/adblock-lists/pull/297

    Any questions let me know.

    opened by ryanbr 6
  • Resolve compilation errors and add CI task

    Resolve compilation errors and add CI task

    On a fresh clone of v0.5.6 I encountered a few compilation errors. After this PR, the project should compile without errors or warnings using RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --all-features, and that command has been added to CI to prevent compilation errors from hiding behind feature flags in the future.

    All tests pass except for live.rs tests, which require a BRAVE_SERVICE_KEY that isn't checked into the repo. I managed to find that key, which does not appear to be a secret. However, I want to understand the purpose of the BraveServiceKey header before I fix those tests.

    The changes are organized into three commits:

    1. Swapped native-tls for rustls-tls in the reqwest dev dependency, which should be less sensitive to version changes in OS-specific openssl libraries. (I use Ubuntu 22.04, which uses libssl3 instead of libssl1.1, so I run into this problem frequently.)
    2. Added CI step to keep main branch free of warnings & errors
    3. Removed feature flag full-domain-matching which since 2019 would cause the build to fail. I also moved & rewrote an old failing test from tests/hashing_test.rs to src/filters/network.rs.

    resolve #225

    opened by denosaurtrain 5
  • `redirect-url` filter option

    `redirect-url` filter option

    Add a new filter option to adblock called redirect-url (similar to redirect=) that allows loading of replacement resources via a URL instead of having to bundle all replacement resources in the client.

    opened by ShivanKaul 5
  • Bump tokio from 1.21.1 to 1.23.1

    Bump tokio from 1.21.1 to 1.23.1

    Bumps tokio from 1.21.1 to 1.23.1.

    Release notes

    Sourced from tokio's releases.

    Tokio v1.23.1

    This release forward ports changes from 1.18.4.

    Fixed

    • net: fix Windows named pipe server builder to maintain option when toggling pipe mode (#5336).

    #5336: tokio-rs/tokio#5336

    Tokio v1.23.0

    Fixed

    • net: fix Windows named pipe connect (#5208)
    • io: support vectored writes for ChildStdin (#5216)
    • io: fix async fn ready() false positive for OS-specific events (#5231)

    Changed

    • runtime: yield_now defers task until after driver poll (#5223)
    • runtime: reduce amount of codegen needed per spawned task (#5213)
    • windows: replace winapi dependency with windows-sys (#5204)

    #5208: tokio-rs/tokio#5208 #5216: tokio-rs/tokio#5216 #5213: tokio-rs/tokio#5213 #5204: tokio-rs/tokio#5204 #5223: tokio-rs/tokio#5223 #5231: tokio-rs/tokio#5231

    Tokio v1.22.0

    Added

    • runtime: add Handle::runtime_flavor (#5138)
    • sync: add Mutex::blocking_lock_owned (#5130)
    • sync: add Semaphore::MAX_PERMITS (#5144)
    • sync: add merge() to semaphore permits (#4948)
    • sync: add mpsc::WeakUnboundedSender (#5189)

    Added (unstable)

    • process: add Command::process_group (#5114)
    • runtime: export metrics about the blocking thread pool (#5161)
    • task: add task::id() and task::try_id() (#5171)

    Fixed

    • macros: don't take ownership of futures in macros (#5087)
    • runtime: fix Stacked Borrows violation in LocalOwnedTasks (#5099)
    • runtime: mitigate ABA with 32-bit queue indices when possible (#5042)
    • task: wake local tasks to the local queue when woken by the same thread (#5095)
    • time: panic in release mode when mark_pending called illegally (#5093)
    • runtime: fix typo in expect message (#5169)

    ... (truncated)

    Commits
    • 1a997ff chore: prepare Tokio v1.23.1 release
    • a8fe333 Merge branch 'tokio-1.20.x' into tokio-1.23.x
    • ba81945 chore: prepare Tokio 1.20.3 release
    • 763bdc9 ci: run WASI tasks using latest Rust
    • 9f98535 Merge remote-tracking branch 'origin/tokio-1.18.x' into fix-named-pipes-1.20
    • 9241c3e chore: prepare Tokio v1.18.4 release
    • 699573d net: fix named pipes server configuration builder
    • 3ce5a26 chore: prepare Tokio v1.23 release (#5270)
    • 644cb82 rt: fix *_closed false positives (#5231)
    • a1316cd io: impl std::io::BufRead on SyncIoBridge\<T> (#5265)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies rust 
    opened by dependabot[bot] 0
  • Support for better match-case regex filters.

    Support for better match-case regex filters.

    Used in uBO, https://github.com/uBlockOrigin/uAssets/blob/master/filters/badware.txt#L881 https://github.com/uBlockOrigin/uAssets/blob/master/filters/filters.txt#L19296

    The match-case regex filters used for revolving adserver domains. From what I see, they are ignored in Brave

    badware.txt:/^https:\/\/[0-9a-z]{3,}\.[-a-z]{10,}\.(?:li[fv]e|top|xyz)\/[a-z]{8}\/\?utm_campaign=\w{40,}/$doc,match-case,domain=life|live|top|xyz
    badware.txt:/^https?:\/\/((?!www)[a-z]{3,}|\d{2})?\.?[-0-9a-z]{6,}\.[a-z]{2,6}\/(?:[a-z]{6,8}\/)?\/?\?u=[0-9a-z]{7}&o=[0-9a-z]{7}/$doc,frame,match-case,domain=buzz|com|de|fun|guru|info|life|live|mobi|online|pw|site|space|top|us|xyz
    badware.txt:/^https?:\/\/((?!www)[a-z]{3,}|\d{2})?\.?[-0-9a-z]{6,}\.[a-z]{2,6}\/(?:[a-z]{6,8}\/)?\/?\?o=[0-9a-z]{7}&u=[0-9a-z]{7}/$doc,frame,match-case,domain=buzz|com|de|fun|guru|info|life|live|mobi|online|pw|site|space|top|us|xyz
    badware.txt:/^https:\/\/(?:www\d\.)?[-a-z]{6,}\.(?:com|info|net|org)\/(?=[-_a-zA-Z]{0,42}\d)(?=[-_0-9a-z]{0,42}[A-Z])[-_0-9a-zA-Z]{43}\/\?cid=[-_0-9a-zA-Z]{16,36}(?:&qs\d=\S+)?&sid=[_0-9a-f]{1,32}$/$doc,match-case,domain=com|info|net|org
    badware.txt:/^https:\/\/(?:www\d\.)?[-a-z]{6,}\.(?:com|info|net|org)\/(?=[-_a-zA-Z]{0,42}\d)(?=[-_0-9a-z]{0,42}[A-Z])[-_0-9a-zA-Z]{43}\/\?sid=[_0-9a-f]{1,32}(?:&qs\d=\S+)?&cid=[-_0-9a-zA-Z]{16,36}$/$doc,match-case,domain=com|info|net|org
    badware.txt:/^http:\/\/[a-z]{5}\.[a-z]{5}\.com\/[a-z]{10}\.apk$/$doc,match-case,domain=com
    filters.txt:/\/[A-Z]\/[-0-9a-z]{5,}\.com\/(?:[0-9a-f]{2}\/){3}[0-9a-f]{32}\.js$/$script,1p,match-case
    filters.txt:/^https?:\/\/(?:[a-z]{2}\.)?[0-9a-z]{7,16}\.com\/[a-z](?=[a-z]{0,25}[0-9A-Z])[0-9a-zA-Z]{3,26}\/(?:[1-5]\d{4}|[3-9]\d{3})\??(?:_=\d+|v=\d)?$/$frame,script,xhr,popup,3p,match-case
    filters.txt:/^https?:\/\/(?:[a-z]{2}\.)?[0-9a-z]{7,16}\.website\/[a-z](?=[a-z]{0,25}[0-9A-Z])[0-9a-zA-Z]{3,26}\/(?:[1-5]\d{4}|[3-9]\d{3})\??(?:_=\d+|v=\d)?$/$frame,script,xhr,popup,3p,match-case
    filters.txt:/^https?:\/\/[a-z]{8,15}\.top(\/(?:\d{1,5}|0NaN|articles?|browse|index|movie|news|pages?|static|view|web|wiki)){1,4}(?:\.html|\/)$/$frame,3p,match-case
    filters.txt:/^https?:\/\/[a-z]{8,15}\.top\/[a-z]{4,}\.json$/$xhr,3p,match-case
    filters.txt:/^https?:\/\/[a-z]{8,15}\.top\/[-a-z]{4,}\.css\?aHR0c[\/0-9a-zA-Z]{33,}=?=?$/$css,3p,match-case
    filters.txt:/^https?:\/\/[a-z]{8,15}\.top\/[a-z]{4,}\.png\?aHR0c[\/0-9a-zA-Z]{33,}=?=?$/$image,3p,match-case
    filters.txt:/^https?:\/\/[a-z]{8,15}\.xyz(\/(?:\d{1,5}|0NaN|articles?|browse|index|movie|news|pages?|static|view|web|wiki)){1,4}(?:\.html|\/)$/$frame,3p,match-case
    filters-2022.txt:/^https?:\/\/cdn\.[a-z]{4,6}\.xyz\/app\.js$/$script,3p,match-case
    filters-2022.txt:/^https:\/\/a\.[-0-9a-z]{4,16}\.(?:club|com?|cyou|info|net|ru|site|top?|xxx|xyz)\/(?=[a-z]{0,6}[0-9A-Z])[0-9a-zA-Z]{7}\.js$/$script,match-case
    privacy.txt:/^https:\/\/cdn\.jsdelivr\.net\/npm\/[-a-z_]{4,22}@latest\/dist\/script\.min\.js$/$script,3p,match-case
    privacy.txt:/^https?:\/\/[-.0-9a-z]+\/script\.js$/$script,1p,strict3p,match-case
    
    opened by ryanbr 0
  • Add a global RegexManager

    Add a global RegexManager

    For https://github.com/brave/brave-browser/issues/26892

    The idea is to use global regular expression storage instead of individual ones. This allows to challenge the long-term regexp memory consumption problem in the next PRs. A new RegexManager is in charge of matching/spawning/deleting regex instances. NetworkFilter is enforced to match using RegexManager.

    Plans:

    • track the last regex usage and drop the instance it after a few time;
    • use less effective, but more memory-saving algorithms for some of the reg exps until it becomes a hot path;

    Note:

    • Thread safety is dropped, but could be restored via adding Mutex for RegexManager under the flag (do we really need it?).
    • Using a standard hasher for u64 instead of AHasher results in 3% performance drop.. Not sure AHasher is the best option. I am open to other suggestions.
    • Replacing a standard hasher in other places could also give a perf boost, worst trying.
    • get_debug_info() method is supposed to be exposed to something like brave://adblock-internals.
    opened by atuchin-m 1
  • Using backslash (\) to escape special characters doesn't work properly in Brave adblocker

    Using backslash (\) to escape special characters doesn't work properly in Brave adblocker

    I noticed this problem which shouldn't be crucial for most people but it would be nice if it gets fixed eventually, it applies to both, Custom filters and Internal/Default Lists.

    But, I use uBo-Scriptlets and they have some nice scriptlets. When I was testing the ones to add Local storage items in Brave, I noticed that I can't get Brave to use the quotes symbol in a string.

    This issue seems to only apply to backslash, and single and double quotes, so it is like the adblocker just decided to ignore any quote or double backslash (to add one backslash) in the rules.

    Since many Local Storage items are JSON, they would need the quotes to work properly.

    For example if I add the scritplet for setLocalItem to Brave and then use brave.com##+js(sli, test, {\"m-tcon\":true\,\"m-other\":true\,\"m-owl\":true\,\"m-game\":true\,\"m-ffz\":true\,\"m-addon\":true}) the quotes get ignored even if technically it should just work and don't act as normal quotes.

    Using the backslash with the commas works as expected though, since the backslash is needed so the commas don't act as individual arguments for the scriptlet which would crash the browser if too many are in the rule.

    So, it is not a huge issue and my workaround was to modify the scriptlet and use replace() and then it replaces the | to quotes symbol, so it is easy, but it would be nice if it just worked just by adding the backslashes to quotes (or without using backslashes for these symbols like uBlock does it automatically) instead of modifying the scriptlet.

    Thank you.

    opened by ghost 2
  • Support pre-processing directories and add env_brave

    Support pre-processing directories and add env_brave

    I don't know if pre-processing directories are supported or not, https://github.com/brave-experiments/ad-block/issues/114 is archived without any notion. In particular, if-condition to speficy Brave Shield (env_brave or something) will be useful to list maintainer. Sure, Brave has its own unbreak list, but if a Brave-specific issue like https://github.com/brave/adblock-lists/issues/614 can be fixed in upstream lists by specifying Brave, this will save time of both Brave list maintainer (@ryanbr ) and me (or whoever filter author who mind Brave). Moreover, it will encourage more people to create and maintain lists for Brave. I believe if you can implement this, Adguard (@ameshkov) and uBlock Origin (@gorhill ) can add the same directive whose value will be false on them (this is completely different from https://github.com/uBlockOrigin/uBlock-issues/issues/1213).

    opened by Yuki2718 0
Owner
Brave Software
We're reinventing the browser as a user-first platform for speed, privacy, better ads, and beyond
Brave Software
Modular, structure-aware, and feedback-driven fuzzing engine for Rust functions

Fuzzcheck Fuzzcheck is a modular, structure-aware, and feedback-driven fuzzing engine for Rust functions. Given a function test: (T) -> bool, you can

Loïc Lecrenier 397 Jan 6, 2023
symbolic execution engine for Rust

Seer: Symbolic Execution Engine for Rust Seer is a fork of miri that adds support for symbolic execution, using z3 as a solver backend. Given a progra

David Renshaw 313 Dec 26, 2022
Symbolic execution of LLVM IR with an engine written in Rust

haybale: Symbolic execution of LLVM IR, written in Rust haybale is a general-purpose symbolic execution engine written in Rust. It operates on LLVM IR

UCSD PLSysSec 404 Jan 1, 2023
Automated property based testing for Rust (with shrinking).

quickcheck QuickCheck is a way to do property based testing using randomly generated input. This crate comes with the ability to randomly generate and

Andrew Gallant 2k Dec 27, 2022
Fast, Concurrent, Rust based Tidal-Media-Downloader implementation.

tdl tdl is a rust implementation of the Python Script Tidal-Media-Downloader. Overview tdl offers significant performance improvements over the origin

null 42 Mar 18, 2023
delegated, decentralized, capabilities based authorization token

Biscuit authentication/authorization token Goals Biscuit is an authentication and authorization token for microservices architectures with the followi

null 580 Jan 1, 2023
A utility like pkg-audit for Arch Linux. Based on Arch Security Team data.

arch-audit pkg-audit-like utility for Arch Linux. Based on data from security.archlinux.org collected by the awesome Arch Security Team. Installation

Andrea Scarpino 316 Nov 22, 2022
a grammar based feedback fuzzer

Nautilus NOTE: THIS IS AN OUTDATE REPOSITORY, THE CURRENT RELEASE IS AVAILABLE HERE. THIS REPO ONLY SERVES AS A REFERENCE FOR THE PAPER Nautilus is a

Chair for Sys­tems Se­cu­ri­ty 157 Oct 26, 2022
radare2-based decompiler and symbol executor

Radeco A radare2 based binary analysis framework consisting from the Radeco client, in ./radeco/ directory, ./radeco-lib/ - library where whole high-l

radare org 349 Dec 28, 2022
🥸P2P gossip network for update transparency, based on pgp 🥸

apt-swarm An attempt to make a secure public p2p protocol that gossips about signed InRelease files to implement an update transparency log. Running a

null 10 Mar 4, 2023
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ Looking for maintainer: https://github.com/rust-secure-code/cargo-geiger/issues/210 A program that lists statistics related to the usa

Rust Secure Code Working Group 1.1k Jan 4, 2023
An esoteric language/compiler written with Rust and Rust LLVM bindings

MeidoLang (メイドラング) A not so useful and esoteric language. The goal of this project was to contain some quirky or novel syntax in a stack-style program

null 0 Dec 24, 2021
Rust-verification-tools - RVT is a collection of tools/libraries to support both static and dynamic verification of Rust programs.

Rust verification tools This is a collection of tools/libraries to support both static and dynamic verification of Rust programs. We see static verifi

null 253 Dec 31, 2022
Rust bindings for libinjection

libinjection-rs Rust bindings for libinjection. How to use Add libinjection to dependencies of Cargo.toml: libinjection = "0.2" Import crate: extern c

ArvanCloud 35 Sep 24, 2022
A simple password manager written in Rust

ripasso A simple password manager written in Rust. The root crate ripasso is a library for accessing and decrypting passwords stored in pass format (G

Joakim Lundborg 548 Dec 26, 2022
tcp connection hijacker, rust rewrite of shijack

rshijack tcp connection hijacker, rust rewrite of shijack from 2001. This was written for TAMUctf 2018, brick house 100. The target was a telnet serve

null 377 Jan 1, 2023
A fast, simple, recursive content discovery tool written in Rust.

A simple, fast, recursive content discovery tool written in Rust ?? Releases ✨ Example Usage ✨ Contributing ✨ Documentation ?? ?? What the heck is a f

epi 3.6k Dec 30, 2022
link is a command and control framework written in rust

link link is a command and control framework written in rust. Currently in alpha. Table of Contents Introduction Features Feedback Build Process Ackno

null 427 Dec 24, 2022
CVEs for the Rust standard library

Rust CVE Preface This is a list of CVEs for unsound APIs in the Rust standard library. These bugs break Rust's memory safety guarantee and lead to sec

Yechan Bae 26 Dec 4, 2022