From b2d349019e69675eb060e5564f8e181624557fad Mon Sep 17 00:00:00 2001 From: Maxim Topciu Date: Fri, 30 Aug 2024 19:07:07 +0300 Subject: [PATCH] AG-35393 fix restricted domains logic for subdocument requests Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-35393 to master Squashed commit of the following: commit 8330418a9cb5c15f2bad99b5e82a4a9ce749a8a2 Author: Slava Leleka Date: Fri Aug 30 18:01:48 2024 +0300 packages/tsurlfilter/CHANGELOG.md edited online with Bitbucket commit b1d371df3a302c95ace321bd341c65563ac68489 Author: Maxim Topciu Date: Fri Aug 30 17:55:24 2024 +0300 AG-35393 update changelog commit 345f72e3ae1d251045c3b51c62715df2d17af439 Author: Maxim Topciu Date: Fri Aug 30 17:47:41 2024 +0300 AG-35393 fix restricted domains logic for subdocument requests --- packages/tsurlfilter/CHANGELOG.md | 8 ++++++++ packages/tsurlfilter/src/rules/network-rule.ts | 5 ++--- .../tsurlfilter/test/engine/network-engine.test.ts | 12 ------------ packages/tsurlfilter/test/rules/network-rule.test.ts | 5 ----- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/tsurlfilter/CHANGELOG.md b/packages/tsurlfilter/CHANGELOG.md index 8b0da38bb..011426579 100644 --- a/packages/tsurlfilter/CHANGELOG.md +++ b/packages/tsurlfilter/CHANGELOG.md @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## 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 diff --git a/packages/tsurlfilter/src/rules/network-rule.ts b/packages/tsurlfilter/src/rules/network-rule.ts index 6ae46d3fd..724d1cf6e 100644 --- a/packages/tsurlfilter/src/rules/network-rule.ts +++ b/packages/tsurlfilter/src/rules/network-rule.ts @@ -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) @@ -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(); diff --git a/packages/tsurlfilter/test/engine/network-engine.test.ts b/packages/tsurlfilter/test/engine/network-engine.test.ts index f6aae891e..167c9fc75 100644 --- a/packages/tsurlfilter/test/engine/network-engine.test.ts +++ b/packages/tsurlfilter/test/engine/network-engine.test.ts @@ -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); diff --git a/packages/tsurlfilter/test/rules/network-rule.test.ts b/packages/tsurlfilter/test/rules/network-rule.test.ts index a066b4cb9..908d658ea 100644 --- a/packages/tsurlfilter/test/rules/network-rule.test.ts +++ b/packages/tsurlfilter/test/rules/network-rule.test.ts @@ -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);