Skip to content

Conversation

@fresh3nough
Copy link

Summary

Fixes #582

This PR adds support for wildcard (*) syntax in cosmetic filters, particularly for scriptlet injection rules like *##+js(filter). This brings adblock-rust's behavior in line with uBlock Origin and enables filter list authors to apply scriptlets globally across all domains.

Problem

Previously, filters using the wildcard syntax *##+js(scriptlet) would parse successfully but fail to match any domains. The parser treated * as a literal hostname rather than recognizing it as a wildcard meaning "all domains". This caused the filter to have hostname constraints that would never match.

Solution

The fix is minimal and elegant - we simply skip the * wildcard during domain parsing in the locations_before_sharp() function

Cody added 2 commits January 18, 2026 09:33
Fixes brave#582

This change allows the use of wildcard (*) in cosmetic filters,
including scriptlet injection rules like *##+js(filter).

The wildcard is now properly treated as matching all domains by
skipping it during domain parsing, making it equivalent to a generic
filter but without triggering the GenericScriptInject error.

Changes:
- Modified locations_before_sharp() to skip wildcard (*) domains
- Added comprehensive tests for wildcard support including:
  - Scriptlet injection with wildcards
  - Regular cosmetic filters with wildcards
  - Wildcards combined with specific domains
The hash changed because wildcards now correctly have no hostname
constraints, changing the serialized format. This is the expected
behavior after the wildcard support fix.
@fresh3nough fresh3nough requested a review from a team as a code owner January 18, 2026 14:45
Copy link
Collaborator

@antonok-edm antonok-edm left a comment

Choose a reason for hiding this comment

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

Hi, thanks for your contribution.

The only thing ignoring the wildcard token will do is save a tiny bit of runtime memory by not storing the hashed * character associated with the relevant rules.

For this to actually work, it will need to be put into a structure that can be queried at runtime.

The tests you added only test parsing, not matching behavior.

Also fwiw, *,example.com doesn't make any sense as part of a rule - why call out example.com specifically if the wildcard is already there?

@fresh3nough
Copy link
Author

Fixed all the issues:

  1. Moved the validation logic to properly reject wildcard script injections - they now correctly fail since generic script injections aren't allowed
  2. Removed the nonsensical *,example.com test case
  3. Added runtime matching tests that verify wildcards actually work at runtime, not just during parsing

The wildcard filters now work as generic rules - *##selector applies to all domains just like ##selector does.

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.

Support for wildcards in Custom filters

2 participants