Skip to content

Commit

Permalink
AG-26073 check trusted urls by hostnames
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-26073 to master

Squashed commit of the following:

commit 5ad3c8b
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Fri Sep 22 13:54:28 2023 +0300

    AG-26073 add changelog

commit cf3ee38
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Fri Sep 22 13:52:28 2023 +0300

    AG-26073 check trusted urls by hostnames
  • Loading branch information
maximtop committed Sep 22, 2023
1 parent c368a3d commit d589290
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/tswebextension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- TODO: manually add compare links for version to the end of the file -->
<!-- e.g. [0.1.2]: https://github.com/AdguardTeam/tsurlfilter/compare/tswebextension-v0.1.1...tswebextension-v0.1.2 -->

## Unreleased

### Fixed
- Proceed anyway is not working for more than two level domains [#2497](https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2497).

## [0.3.20] - 2023-09-19

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import browser, { type WebRequest } from 'webextension-polyfill';
import { getDomain } from 'tldts';
import { getHostname } from 'tldts';
import type { NetworkRule } from '@adguard/tsurlfilter';

import { defaultFilteringLog, FilteringEventType } from '../../../common/filtering-log';
Expand Down Expand Up @@ -128,7 +128,7 @@ export class DocumentBlockingService {
* @returns True, if request url domain is trusted, else false.
*/
private isTrustedDomain(url: string): boolean {
const domain = getDomain(url);
const domain = getHostname(url);

if (domain) {
return this.trustedDomains.includes(domain);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { DocumentBlockingService } from '@lib/mv2/background/services/document-blocking-service';
import { NetworkRule } from '@adguard/tsurlfilter';
import { ConfigurationMV2 } from '@lib/mv2';
import { getConfigurationMv2Fixture } from '../fixtures/configuration';

describe('DocumentBlockingService', () => {
let documentBlockingService: DocumentBlockingService;

beforeEach(() => {
documentBlockingService = new DocumentBlockingService();
});

afterEach(() => {
jest.clearAllMocks();
});

it('should not block URLs from trusted domains', () => {
const trustedUrl = 'https://opulent-space-telegram-g4wx56pwp9q2vp5j.github.dev/blabla';
const trustedDomain = 'opulent-space-telegram-g4wx56pwp9q2vp5j.github.dev';
const mockNetworkRule = new NetworkRule('example.org', 0);

const mockConfig: ConfigurationMV2 = {
...getConfigurationMv2Fixture(),
...{
trustedDomains: [trustedDomain],
},
};

documentBlockingService.configure(mockConfig);

const result = documentBlockingService.getDocumentBlockingResponse({
tabId: 1,
eventId: 'someEvent',
rule: mockNetworkRule,
referrerUrl: 'someReferrer',
requestUrl: trustedUrl,
});

expect(result).toBeUndefined();
});
});

0 comments on commit d589290

Please sign in to comment.