Skip to content

Commit

Permalink
AG-35393 fix restricted domains logic for subdocument requests
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-35393 to master

Squashed commit of the following:

commit 8330418
Author: Slava Leleka <[email protected]>
Date:   Fri Aug 30 18:01:48 2024 +0300

    packages/tsurlfilter/CHANGELOG.md edited online with Bitbucket

commit b1d371d
Author: Maxim Topciu <[email protected]>
Date:   Fri Aug 30 17:55:24 2024 +0300

    AG-35393 update changelog

commit 345f72e
Author: Maxim Topciu <[email protected]>
Date:   Fri Aug 30 17:47:41 2024 +0300

    AG-35393 fix restricted domains logic for subdocument requests
  • Loading branch information
maximtop committed Aug 30, 2024
1 parent a51657e commit b2d3490
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
8 changes: 8 additions & 0 deletions packages/tsurlfilter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- TODO: manually add compare links for version changes -->
<!-- e.g. [1.0.77]: https://github.com/AdguardTeam/tsurlfilter/compare/tsurlfilter-v1.0.76...tsurlfilter-v1.0.77 -->

## Unreleased

### Fixed

- The exception `$domain=~` filter rule is not working properly [AdguardBrowserExtension#2912].

[AdguardBrowserExtension#2912]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2912

## [3.0.2] - 2024-08-29

### Changed
Expand Down
5 changes: 2 additions & 3 deletions packages/tsurlfilter/src/rules/network-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ export class NetworkRule implements rule.IRule {
* In some cases the $domain modifier can match not only the referrer domain, but also the target domain.
* This happens when the following is true (1 AND ((2 AND 3) OR 4):
*
* 1) The request has document type
* 1) The request has $document request type (not subdocument)
* 2) The rule's pattern doesn't match any particular domain(s)
* 3) The rule's pattern doesn't contain regular expressions
* 4) The $domain modifier contains only excluded domains (e.g., $domain=~example.org|~example.com)
Expand All @@ -771,8 +771,7 @@ export class NetworkRule implements rule.IRule {

const { domainModifier } = this;

const isDocumentType = request.requestType === RequestType.Document
|| request.requestType === RequestType.SubDocument;
const isDocumentType = request.requestType === RequestType.Document;

const hasOnlyExcludedDomains = !domainModifier.hasPermittedDomains()
&& domainModifier.hasRestrictedDomains();
Expand Down
12 changes: 0 additions & 12 deletions packages/tsurlfilter/test/engine/network-engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,6 @@ describe('Test $domain modifier semantics', () => {
);
});

it('will match request url host - subdocument', () => {
const request = new Request('http://check.com/path', 'http://test.com/', RequestType.SubDocument);
const result = engine.match(request);

expect(result).toBeTruthy();
expect(
getRuleSourceIndex(result!.getIndex(), processed.sourceMap),
).toBe(
getRawRuleIndex(processed.rawFilterList, rule),
);
});

it('checks request type Document is required', () => {
const request = new Request('http://check.com/path', 'http://test.com/', RequestType.Image);
const result = engine.match(request);
Expand Down
5 changes: 0 additions & 5 deletions packages/tsurlfilter/test/rules/network-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,11 +967,6 @@ describe('NetworkRule.match', () => {
request = new Request('https://example.org/', 'https://example.com/', RequestType.Document);
expect(rule.match(request)).toEqual(true);

// Match request url host
rule = createNetworkRule('$domain=example.org', 0);
request = new Request('https://example.org/', 'https://example.com/', RequestType.SubDocument);
expect(rule.match(request)).toEqual(true);

// Document or Subdocument only
rule = createNetworkRule('$domain=example.org', 0);
request = new Request('https://example.org/', 'https://example.com/', RequestType.Image);
Expand Down

0 comments on commit b2d3490

Please sign in to comment.