brave / adblock-resources

Custom resources and scriptlets used for Brave's adblocker
Mozilla Public License 2.0
71 stars 23 forks source link

adblock-resources

Contains resources and scriptlets designed for use with Brave's adblock-rust library.

Custom resources should be added to the resources directory, and a corresponding entry should be added to the metadata.json file.

Using

This package can be imported as a library, exposing the function readResources which will produce the correctly formatted list of resources for use with adblock-rust.

Alternatively, npm run build will write all resources to dist/resources.json for future use.

To generate metadata.json automatically from files in resources/, run npm run generateMetadata.

Use npm run test after modifying the resources or metadata file to ensure the format can be accepted by adblock-rust.

Metadata format

metadata.json is a list of elements of the following format:

{
    "name": "name-of-my-resource",
    "aliases": ["an-alias-for-my-resource"],
    "kind": {"mime":"application/javascript"},
    "resourcePath": "pathRelativeToResources.js"
}

In general, this format corresponds to the Resource struct from adblock-rust, but the base64-encoded content field is replaced by a path to a file for better maintainability. This library will translate the resourcePath field back to a base64-encoded content field when ready for use.

Filter list description format

The filter_lists/*.json files are lists of elements, each describing a filter list. The format for each element is:

{
    "title": "New Filter Rules",
    "desc": "Removes new elements"
    "langs": [],
    "component_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "base64_public_key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs...IDAQAB",
    "list_text_component": {
        "component_id": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
        "base64_public_key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs...IDAQAB",
    },
    "sources": [
        {
            "url": "https://raw.githubusercontent.com/brave/adblock-lists/master/brave-lists/new-list.txt",
            "title": "Brave New List",
            "format": "Standard",
            "support_url": "https://github.com/brave/adblock-lists",
        }
    ]
}

Optional fields

The following 4 fields are all optional and default to false or 0 if omitted.

Adding a new list

The generate_component.sh script can be used to help create a new filter list component. It will generate:

The script should be run with no arguments. The resulting PEM file will be named ad-block-updater-<component_id>.pem. This new PEM file has to be uploaded to 1Password. See instructions here.

We will need to run this script a second time to get values for the top-level base64_public_key and component_id fields. These will be different from the values for list_text_component.base64_public_key and list_text_component.component_id fields. This is necessary for iOS, see tracking issue.