Skip to content

initial version of a command line invocation #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pes10k
Copy link
Collaborator

@pes10k pes10k commented Apr 29, 2025

> node ./js/check.js --help

usage: check.js [-h] [-v] [--requests REQUESTS] [--url URL] [--context CONTEXT]
                [--type {Attribution resource,Audio,CSS resource,CSS stylesheet,Dictionary,Document,Fetch,Font,Icon,Image,Internal resource,Link element resource,Link prefetch resource,Manifest,Mock,Other resource,Processing instruction,SVG Use element resource,SVG document,Script,SpeculationRule,Text track,Track,User Agent CSS resource,Video,XML resource,XMLHttpRequest,XSL stylesheet,beacon,csp_report,document,font,image,media,object,other,ping,script,speculative,stylesheet,sub_frame,web_manifest,websocket,xbl,xhr,xml_dtd,xslt}]
                [--rules [RULES ...]] [--verbose]

Check whether a URL would be blocked by given filter list rules

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --requests REQUESTS   Path to a file of requests to check filter list rules against (or, by default, STDIN). This input should be lines of JSON documents, one document per line. This JSON text must have the
                        following keys: "url", "context", and "type", which corresponds to the --url, --context, and --type arguments.
  --url URL             The full URL to check against the provided filter lists.
  --context CONTEXT     The security context the request occurred in, as a full URL
  --type {Attribution resource,Audio,CSS resource,CSS stylesheet,Dictionary,Document,Fetch,Font,Icon,Image,Internal resource,Link element resource,Link prefetch resource,Manifest,Mock,Other resource,Processing instruction,SVG Use element resource,SVG document,Script,SpeculationRule,Text track,Track,User Agent CSS resource,Video,XML resource,XMLHttpRequest,XSL stylesheet,beacon,csp_report,document,font,image,media,object,other,ping,script,speculative,stylesheet,sub_frame,web_manifest,websocket,xbl,xhr,xml_dtd,xslt}
                        The type of the request, using either i. the types defined by filter list projects (which are all in lowercase, e.g., "xhr" or "stylesheet"), or ii. the types defined in the Chromium source
                        (which start with an uppercase character, e.g., "XMLHttpRequest" or "CSS stylesheet")
  --rules [RULES ...]   One or more paths to files of filter list rules to check the request against. By default uses bundled old-and-outdated versions of easylist and easyprivacy
  --verbose             Print information about what rule(s) the request matched.

Copy link

The security team is monitoring all repositories for certain keywords. This PR includes the word(s) "csp" and so security team members have been added as reviewers to take a look.

No need to request a full security review at this stage, the security team will take a look shortly and either clear the label or request more information/changes.

Notifications have already been sent, but if this is blocking your merge feel free to reach out directly to the security team on Slack so that we can expedite this check.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: ed80629 Previous: d56be21 Ratio
rule-match-browserlike/brave-list 1725948533 ns/iter (± 10769030) 1727033355 ns/iter (± 11920489) 1.00
rule-match-first-request/brave-list 1000965 ns/iter (± 13182) 1005963 ns/iter (± 12764) 1.00
blocker_new/brave-list 231942641 ns/iter (± 3467835) 220140757 ns/iter (± 5159081) 1.05
memory-usage/brave-list-initial 41408849 ns/iter (± 3) 41408849 ns/iter (± 3) 1
memory-usage/brave-list-after-1000-requests 44004875 ns/iter (± 3) 44004875 ns/iter (± 3) 1

This comment was automatically generated by workflow using github-action-benchmark.

@pes10k
Copy link
Collaborator Author

pes10k commented Apr 29, 2025

You can invoke like this:

npm run check -- \
  --url <REQUEST URL> \
  --type <REQUEST TYPE> \
  --context-url <SECURITY CONTEXT URL> \
  --rule-files <PATH> <PATH> ...;

@pes10k pes10k force-pushed the add-command-line-option branch from 29f016e to fb9d1fb Compare April 29, 2025 23:44
@pes10k
Copy link
Collaborator Author

pes10k commented Apr 29, 2025

The security team is monitoring all repositories for certain keywords. This PR includes the word(s) "csp" and so security team members have been added as reviewers to take a look. No need to request a full security review at this stage, the security team will take a look shortly and either clear the label or request more information/changes. Notifications have already been sent, but if this is blocking your merge feel free to reach out directly to the security team on Slack so that we can expedite this check.

FWIW, the "csp" reference added here is just because its a request type that filter list rules can target (or exclude)

@pes10k pes10k force-pushed the add-command-line-option branch from fb9d1fb to 0c30f8c Compare April 29, 2025 23:58
@pes10k pes10k force-pushed the add-command-line-option branch from 0c30f8c to 6808ba0 Compare April 30, 2025 00:41
@pes10k
Copy link
Collaborator Author

pes10k commented May 12, 2025

i also added a batch option, where you can pass a file of JSON texts each describing a request that should be checked, so you can check a large number of requests without having to reparse easylist.

➜ ~/Code/adblock-rust: (add-command-line-option) echo '{"url": "https://site.example/test-ad-sidebar.png", "type": "Image", "context": "https://site.example"}' | npm run check -- --verbose

> [email protected] check
> node ./js/check.js --verbose

{"matched":true,"important":false,"redirect":null,"rewritten_url":null,"exception":null,"filter":"-ad-sidebar.$image <+> /sidebar_ad.jpg$image <+> /sidebar_ad.png$image"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants