1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-29 14:17:11 +02:00
Commit Graph

101 Commits

Author SHA1 Message Date
Raymond Hill
cf43be53a6
Fix overly wide source link button
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2735
2023-07-17 09:17:33 -04:00
Raymond Hill
194354cd5d
Add support for logical expressions to !#if directive
Reference:
https://adguard.com/kb/general/ad-filtering/create-own-filters/#conditions-directive

This commit should make uBO fully compatible with the `!#if`
directives found throughout AdGuard's filter lists.

Additionally, added the new `!#else` directive for convenience
to filter list authors:

    !#if cap_html_filtering
    example.com##^script:has-text(fakeAd)
    !#else
    example.com##+js(rmnt, script, fakeAd)
    !#endif
2023-06-29 14:50:42 -04:00
Raymond Hill
8b7a5264de
Fix syntax highlighter throwing with invalid patterns
The syntax highlighter could throw with some invalid static
network filter patterns. This was caused by the syntax
highlighter still drilling down the pattern parts after
having told codemirror to style the whole pattern as an
error, thus causing the codemirror stream position to go
backward.
2023-06-28 08:38:47 -04:00
Raymond Hill
d776edf06b
Fix linter incorrectly reporting header= option
Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/13thksi/filter_blocking_rule_based_on_post_methods_value/jlvhuoy/
2023-05-27 19:02:23 -04:00
Raymond Hill
f539f869b9
Fix counting of error deletion in linter
Related feedback:
- https://github.com/uBlockOrigin/uAssets/discussions/17538#discussioncomment-5628053
2023-04-16 08:23:49 -04:00
Raymond Hill
e15951dce5
Convert remaining vAPI.setTimeout to vAPI.defer
Related commit:
- 91f9795023
2023-04-14 10:26:45 -04:00
Raymond Hill
91f9795023
Wrap usage of setTimeout in helper for background + auxiliary pages
This commit centralizes usage of setTimeout()/clearTimeout() in the
source code at one single location.
2023-04-09 13:38:16 -04:00
Raymond Hill
bc21a1fe72
Use custom linter gutter as container for code-folding widgets
This allows to reduce the horizontal size of the gutter; more efficient
management of folding since we already need to parse each line for the
linter; and eventually this will also allows to detect unbalanced
!#if-!#endif directives and report such cases as errors.

Additionally, keep incrementally improving error reporting details
in the linter.
2023-04-06 13:14:42 -04:00
Raymond Hill
028eee456f
Ensure error count is decrease when an error is fixed 2023-04-04 16:55:47 -04:00
Raymond Hill
09265ef57c
Simplify linter error counting by using line events 2023-04-04 09:24:18 -04:00
Raymond Hill
95bd52d01f
Fine tuning new linter code 2023-04-02 10:40:44 -04:00
Raymond Hill
cda39709b1
Properly fail on bad network filter pattern
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1146
2023-04-02 10:05:42 -04:00
Raymond Hill
46e90b21e9
Code review of new linter code
As per CodeMirror's documentation, eachLine() iterator is
faster, so use this. Also no need to keep track or marked
lines, we can just find them on demand, this makes the code
simpler.
2023-04-02 09:19:32 -04:00
Raymond Hill
50afd5ae38
Add infrastructure for static filter syntax linter
Sort of related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134
2023-04-01 16:42:41 -04:00
Raymond Hill
fd9bb02aab
Fix search widget when swapping document in new code viewer 2023-03-16 12:36:02 -04:00
Raymond Hill
890aabaae9
Make parser take into account filterOnHeaders setting
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134#issuecomment-1460638431
2023-03-08 13:49:21 -05:00
Raymond Hill
bbd9470a98
Convert resource URLs into clickable links in code viewer 2023-03-08 12:31:39 -05:00
Raymond Hill
8ea3b0f64c
Rewrite static filtering parser
This commit is a rewrite of the static filtering parser into a
tree-based data structure, for easier maintenance and better
abstraction of parsed filters.

This simplifies greatly syntax coloring of filters and also
simplify extending filter syntax.

The minimum version of Chromium-based browsers has been raised
to version 73 because of usage of String.matchAll().
2023-01-23 16:53:18 -05:00
Raymond Hill
24273d2c94
Escape attribute values
Related issues:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2284#issuecomment-1265417399
2022-10-04 08:11:31 -04:00
Raymond Hill
4ee8a5948d
Work toward bringing dark theme closer to a stable release
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/401
2022-01-30 18:35:26 -05:00
Raymond Hill
e4a7df3fd9
Improve auto-completion in _"My filters"_ editor 2021-12-19 08:17:06 -05:00
Raymond Hill
2ab39aee23
Fix not highlighting cases of invalid syntax
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1791

The following case of invalid syntax was not reported as
invalid by the syntax highlighter:

    ... example.com image ...

With dynamic filtering, there can't be a specific
hostname when a specific type is used, or a
specific type when a specific hostname is used, one
or the other must be `*`.
2021-10-31 13:18:31 -04:00
Raymond Hill
c136c7b454
Auto-escape commas in removeparam's regexes
Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-951146371

This is a quick fix, some refactoring necessary for a more
comprehensive fix to all such issues.
2021-10-26 08:51:55 -04:00
Raymond Hill
9dece3bd30
Add new procedural cosmetic operator: :matches-path(...)
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1690

New procedural operator: `:matches-path(...)`

Description: this is a all-or-nothing passthrough operator, which
on/off behavior is dictated by whether the argument match the
path of the current location. The argument can be either plain
text to be found at any position in the path, or a literal regex
against which the path is tested.

Whereas cosmetic filters can be made specific to whole domain,
the new `:matches-path()` operator allows to further narrow
the specificity according to the path of the current document
lcoation.

Typically this procedural operator is used as first operator in
a procedural cosmetic filter, so as to ensure that no further
matching work is performed should there be no match against the
current path of the current document location.

Example of usage:

    example.com##:matches-path(/shop) p

Will hide all `p` elements when visiting `https://example.com/shop/stuff`,
but not when visiting `https://example.com/` or any other page
on `example.com` which has no instance of `/shop` in the path part
of the URL.
2021-08-21 09:41:48 -04:00
Raymond Hill
89c5653bc6
Export the rule-based filtering engines to the nodejs package
The code exported to nodejs package was revised to use modern
JavaScript syntax. A few issues were fixed at the same time.

The exported classes are:
- DynamicHostRuleFiltering
- DynamicURLRuleFiltering
- DynamicSwitchRuleFiltering

These related to the content the of "My rules" pane in the
uBlock Origin extension.
2021-08-03 12:19:25 -04:00
Raymond Hill
22022f636f
Modularize codebase with export/import
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1664

The changes are enough to fulfill the related issue.

A new platform has been added in order to allow for building
a NodeJS package. From the root of the project:

    ./tools/make-nodejs

This will create new uBlock0.nodejs directory in the
./dist/build directory, which is a valid NodeJS package.

From the root of the package, you can try:

    node test

This will instantiate a static network filtering engine,
populated by easylist and easyprivacy, which can be used
to match network requests by filling the appropriate
filtering context object.

The test.js file contains code which is typical example
of usage of the package.

Limitations: the NodeJS package can't execute the WASM
versions of the code since the WASM module requires the
use of fetch(), which is not available in NodeJS.

This is a first pass at modularizing the codebase, and
while at it a number of opportunistic small rewrites
have also been made.

This commit requires the minimum supported version for
Chromium and Firefox be raised to 61 and 60 respectively.
2021-07-27 17:26:04 -04:00
Raymond Hill
f876b68171
Add support for removal of response headers
The syntax to remove response header is a special case
of HTML filtering, whereas the response headers are
targeted, rather than the response body:

  example.com##^responseheader(header-name)

Where `header-name` is the name of the header to
remove, and must always be lowercase.

The removal of response headers can only be applied to
document resources, i.e. main- or sub-frames.

Only a limited set of headers can be targeted for
removal:

  location
  refresh
  report-to
  set-cookie

This limitation is to ensure that uBO never lowers the
security profile of web pages, i.e. we wouldn't want to
remove `content-security-policy`.

Given that the header removal occurs at onHeaderReceived
time, this new ability works for all browsers.

The motivation for this new filtering ability is instance
of website using a `refresh` header to redirect a visitor
to an undesirable destination after a few seconds.
2021-03-13 08:53:34 -05:00
Raymond Hill
6d3ad553b4
Fix word-based selection in filter list editor/viewer
This commit fixes mouse double-click-and-drag operations,
which was broken due to the implementation of a custom
word selection in the filter list editor/viewer.
2020-12-27 09:32:50 -05:00
Raymond Hill
426395aa03
Improve extraction of tokens from regex-based filters
Regex-based static network filters are those most likely to
cause performance degradation, and as such the best guard
against undue performance degradation caused by regex-based
filters is the ability to extract valid and good tokens
from regex patterns.

This commit introduces a complete regex parser so that the
static network filtering engine can now safely extract
tokens regardless of the complexity of the regex pattern.

The regex parser is a library imported from:
https://github.com/foo123/RegexAnalyzer

The syntax highlighter adds an underline to regex-based
filters as a visual aid to filter authors so as to avoid
mistakenly creating regex-based filters. This commit
further colors the underline as a warning when a regex-based
filter is found to be untokenizable.

Filter list authors are invited to spot these untokenizable
regex-based filters in their lists to verify that no
mistake were made for those filters, causing them to be
untokenizabke. For example, what appears to be a mistake:

    /^https?:\/\/.*\/sw.js?.[a-zA-Z0-9%]{50,}/

Though the mistake is minor, the regex-based filter above
is untokenizable as a result, and become tokenizable when
the `.` is properly escaped:

    /^https?:\/\/.*\/sw\.js?.[a-zA-Z0-9%]{50,}/

Filter list authors can use this search expression in the
asset viewer to find instances of regex-based filters:

    /^(@@)?\/[^\n]+\/(\$|$)/
2020-12-26 08:52:42 -05:00
Raymond Hill
596f085fa5
Allow default word selection when not using better selection
Double-click in editor will just fall back to default word
selection when NOT using enhanced word selection.
2020-12-24 08:34:45 -05:00
Raymond Hill
e28c2cc3c6
Auto-complete of origin pattern for ||-based patterns
Related commit:
- daf464b3c3
2020-12-15 08:27:59 -05:00
Raymond Hill
0b5f53923f
Add basic compatibility with ABP's rewrite option
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/857

The recognized resources are:
- abp-resource:blank-mp3
- abp-resource:blank-js

ABP's tokens are excluded from auto-complete so as to not
get in the way of uBO's filter list maintainers.
2020-12-09 08:16:28 -05:00
Raymond Hill
1de8349045
Fix hint helper in element picker's text editor
Regression from:
- 262a1a044f
2020-12-03 07:34:50 -05:00
Raymond Hill
262a1a044f
Improve auto-complete of hostname values in "My filters"
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134

Related commit:
- daf464b3c3
2020-12-02 09:09:28 -05:00
Raymond Hill
26dc7a1490
Minor review of redirect-related code
Notably, I finally settled for implicit priority of
0, but now negative priority values are allowed.
2020-12-02 08:18:55 -05:00
Raymond Hill
cf2c638d8e
Improve reporting of matching redirect= rules in logger
All matching `redirect-rule` directives will now be reported
in the logger, instead of just the effective one.

The highest-ranked redirect directive will be the one
effectively used for redirection. This way filter list
authors can see whether a lower priority redirect is
being overriden by a higher priority one.

The default priority has been changed to 10, so as to allow
more leeway to create lower ranked redirect directives.

Additonally, rendering of redirect directives with explicit
priority has been fixed in the logger, they will no longer
be rendered as unknown redirect tokens.
2020-12-01 09:29:40 -05:00
Raymond Hill
60d5b85e41
Rename 1P/3P tp strict1p/strict3p as suggested
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1362
2020-11-26 05:09:46 -05:00
Raymond Hill
bde3164eb4
Add support for 1P, 3P, header= filter options and other changes
New filter options
==================

Strict partyness: `1P`, `3P`
----------------------------

The current options 1p/3p are meant to "weakly" match partyness, i.e. a
network request is considered 1st-party to its context as long as both the
context and the request share the same base domain.

The new partyness options are meant to check for strict partyness, i.e. a
network request will be considered 1st-party if and only if both the context
and the request share the same hostname.

For examples:

- context: `www.example.org`
- request: `www.example.org`
- `1p`: yes, `1P`: yes
- `3p`: no,  `3P`: no

- context: `www.example.org`
- request: `subdomain.example.org`
- `1p`: yes, `1P`: no
- `3p`: no,  `3P`: yes

- context: `www.example.org`
- request: `www.example.com`
- `1p`: no, `1P`: no
- `3p`: yes,  `3P`: yes

The strict partyness options will be visually emphasized in the editor so as
to prevent mistakenly using `1P` or `3P` where weak partyness is meant to be
used.

Filter on response headers: `header=`
-------------------------------------

Currently experimental and under evaluation. Disabled by default, enable by
toggling `filterOnHeaders` to `true` in advanced settings.

Ability to filter network requests according to whether a specific response
header is present and whether it matches or does not match a specific value.

For example:

    *$1p,3P,script,header=via:1\.1\s+google

The above filter is meant to block network requests which fullfill all the
following conditions:

- is weakly 1st-party to the context
- is not strictly 1st-party to the context
- is of type `script`
- has a response HTTP header named `via`, which value matches the regular
  expression `1\.1\s+google`.

The matches are always performed in a case-insensitive manner.

The header value is assumed to be a literal regular expression, except for
the following special characters:

- to anchor to start of string, use leading `|`, not `^`
- to anchor to end of string, use trailing `|`, not `$`
- to invert the test, use a leading `!`

To block a network request if it merely contains a specific HTTP header is
just a matter of specifying the header name without a header value:

    *$1p,3P,script,header=via

Generic exception filters can be used to disable specific block `header=`
filters, i.e. `@@*$1p,3P,script,header` will override the block `header=`
filters given as example above.

Dynamic filtering's `allow` rules override block `headers=` filters.

Important: It is key that filter authors use as many narrowing filter options
as possible when using the `header=` option, and the `header=` option should
be used ONLY when other filter options are not sufficient.

More documentation justifying the purpose of `header=` option will be
provided eventually if ever it is decided to move it from experimental to
stable status.

To be decided: to restrict usage of this filter option to only uBO's own
filter lists or "My filters".

Changes
=======

Fine tuning `queryprune=`
-------------------------

The following changes have been implemented:

The special value `*` (i.e. `queryprune=*`) means "remove all query
parameters".

If the `queryprune=` value is made only of alphanumeric characters
(including `_`), the value will be internally converted to regex  equivalent
`^value=`. This ensures a better future compatibility with AdGuard's
`removeparam=`.

If the `queryprune=` value starts with `!`, the test will be inverted. This
can be used to remove all query parameters EXCEPT those who match the
specified value.

Other
-----

The legacy code to test for spurious CSP reports has been removed. This
is no longer an issue ever since uBO redirects to local resources through
web accessible resources.

Notes
=====

The following new and recently added filter options are not compatible with
Chromium's manifest v3 changes:

- `queryprune=`
- `1P`
- `3P`
- `header=`
2020-11-23 08:22:43 -05:00
Raymond Hill
daf464b3c3
Add support to auto-complete values of domain lists
The auto-complete feature in the _"My filters"_ pane will
use hostname/domain from the set of opened tabs to assist
in entering values for `domain=` option. This also works
for the implict `domain=` option ṗrepending static extended
filters.
2020-11-21 09:57:54 -05:00
Raymond Hill
ab98cd46b1
Bring back action/state highlighting in _"My rules"_ 2020-11-20 05:34:56 -05:00
Raymond Hill
b1c55b3de9
Emphasize entity portion of hostnames in _"My rules"_ 2020-11-19 11:33:09 -05:00
Raymond Hill
2cfeaddbed
Fine tune various static filtering code
Notably, make `queryprune` option available only
to filter list authors, until there are guards
against bad filters in some future and until the
option syntax and behavior is fully settled.

Instances of `queryprune` in filter lists will be
compiled, however instances of `queryprune` in
_"My filters"_ will be ignored unless users
indicated they are a filter list author.
2020-11-13 09:23:25 -05:00
Raymond Hill
1e2eb037e5
Add new filter option queryprune=
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/760

The purpose of this new network filter option is to remove
query parameters form the URL of network requests.

The name `queryprune` has been picked over `querystrip`
since the purpose of the option is to remove some
parameters from the URL rather than all parameters.

`queryprune` is a modifier option (like `csp`) in that it
does not cause a network request to be blocked but rather
modified before being emitted.

`queryprune` must be assigned a value, which value will
determine which parameters from a query string will be
removed. The syntax for the value is that of regular
expression *except* for the following rules:

- do not wrap the regex directive between `/`
- do not use regex special values `^` and `$`
- do not use literal comma character in the value,
  though you can use hex-encoded version, `\x2c`
- to match the start of a query parameter, prepend `|`
- to match the end of a query parameter, append `|`

`queryprune` regex-like values will be tested against each
key-value parameter pair as `[key]=[value]` string. This
way you can prune according to either the key, the value,
or both.

This commit introduces the concept of modifier filter
options, which as of now are:

- `csp=`
- `queryprune=`

They both work in similar way when used with `important`
option or when used in exception filters. Modifier
options can apply to any network requests, hence the
logger reports the type of the network requests, and no
longer use the modifier as the type, i.e. `csp` filters
are no longer reported as requests of type `csp`.

Though modifier options can apply to any network requests,
for the time being the `csp=` modifier option still apply
only to top or embedded (frame) documents, just as before.
In some future we may want to apply `csp=` directives to
network requests of type script, to control the behavior
of service workers for example.

A new built-in filter expression has been added to the
logger: "modified", which allow to see all the network
requests which were modified before being emitted. The
translation work for this new option will be available
in a future commit.
2020-10-31 10:42:53 -04:00
Raymond Hill
32b08dc732
Mind whitespaces when double-clicking to select filter option value 2020-10-16 17:13:55 -04:00
Raymond Hill
38e1bbbe68
Better word selection for static network filters
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134

Double-clicking on...

... a filter option will cause the option to be
wholly selected, including `=[value]` if present;

... a value assigned to a filter option will cause
the value to be wholly selected, except when the
value is a hostname/entity, in which case all the
labels from the cursor position to the right-most
label will be selected.
2020-10-16 10:06:00 -04:00
Raymond Hill
a095b83250
Use a CodeMirror editor instance in element picker
This allows to bring in all the benefits of
syntax highlighting and enhanced editing
features in the element picker, like auto-
completion, etc.

This is also a necessary step to possibly solve
the following issue:

- https://github.com/gorhill/uBlock/issues/2035

Additionally, incrementally improved the behavior
of uBO's custom CodeMirror static filtering syntax
mode when double-clicking somewhere in a static
extended filter:

- on a class/id string will cause the whole
  class/id string to be   selected, including the
  prepending `.`/`#`.

- somewhere in a hostname/entity will cause all
  the labels from the cursor position to the
  right-most label to be selected (subject to
  change/fine-tune as per feedback of filter
  list maintainers).

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134#issuecomment-679421316
2020-10-14 10:21:30 -04:00
Raymond Hill
1727585faa
Hightlight to warn about unknown redirect tokens
Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134
2020-10-11 08:59:44 -04:00
Raymond Hill
6ff72af4aa
Only URLs in comments can be selected through double-click 2020-10-11 07:45:58 -04:00
Raymond Hill
fef375a594
Minor improvements to syntax highlight of static filters
Double-cliking on a URL will cause the whole URL to be
selected, thus making it easier to navigate to this
URL (through your browser "Open in new tab" entry in
contextual menu).

Unrecognized scriptlet names will be highlighted so as
to warn that the filter is not going to be effective.
2020-09-30 10:01:10 -04:00
Raymond Hill
5df51d63d1
Do not syntax-highlight ... in "My rules" pane 2020-09-23 11:14:09 -04:00