Skip to content

Parse AdGuard #$# CSS injection as style/remove actions#685

Closed
ryanbr wants to merge 1 commit into
brave:masterfrom
ryanbr:adguard-css-injection
Closed

Parse AdGuard #$# CSS injection as style/remove actions#685
ryanbr wants to merge 1 commit into
brave:masterfrom
ryanbr:adguard-css-injection

Conversation

@ryanbr

@ryanbr ryanbr commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

AdGuard's #$# CSS-injection syntax (e.g. businesshemden.com#$#.mnd-cookie-modal { display: none !important; }) was rejected outright as UnsupportedSyntax. This routes it through the same brace-body parser added in #678 for the uBO/ABP ##selector { ... } form, producing a Style (or remove:Remove) action.

businesshemden.com#$#.mnd-cookie-modal { display: none !important; }
  →  Style(".mnd-cookie-modal" => "display: none !important;")

Details

  • The between_sharps.starts_with('$') branch now consumes the $ and sets a flag instead of erroring. The existing ? and leading-@ handlers then cover the extended #$?# and exception #@$# forms with no extra code.
  • A post-parse guard rejects any #$# rule that produced no action. This is the key safety check: ABP snippet injection also uses #$# but has no { ... } body (e.g. example.com#$#abort-on-property-read alert), and must stay unsupported rather than being misparsed as a plain CSS selector.
  • #%# / #@%# (AdGuard JS/scriptlet) remain unsupported — scope is limited to the CSS style/remove form.

Behavior change

Two existing assertions in tests/unit/lists.rs that expected #$# / #@$# to be UnsupportedSyntax are updated to expect successful parsing — this is the intended contract change.

Tests

cargo fmt --check clean; full lib suite passes under both default and css-validation features. Adds adguard_css_injection (style, multi-class selector, remove:, ABP-snippet rejection, generic rejection) and adguard_css_injection_extended (#$?#).

`#$#selector { ... }` (AdGuard CSS injection) was rejected outright as
unsupported syntax. Route it through the same brace-body parser used for
the uBO/ABP `##selector { ... }` form added in brave#678, producing a `Style`
or `remove:` action.

Only the style/remove form is handled — it always carries a `{ ... }`
body. ABP snippet injection also uses `#$#` but has no braces; those
produce no action and remain rejected. The extended `#$?#` and exception
`#@$#` forms fall out naturally via the existing `?`/`@` handlers.
@ryanbr

ryanbr commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #686, opened from an internal branch so the Performance CI step can post its results comment. The failure here was a fork-PR token permission issue (pull_requests=write not granted to fork PRs), not a regression — all benchmark ratios were ≤ 1.00.

@ryanbr ryanbr closed this Jun 27, 2026
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.

1 participant