Skip to content

Commit

Permalink
add support of referrerpolicy modifier for validation in compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed Nov 1, 2023
1 parent a1234dc commit 23a50d1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/tsurlfilter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- e.g. [1.0.77]: https://github.com/AdguardTeam/tsurlfilter/compare/tsurlfilter-v1.0.76...tsurlfilter-v1.0.77 -->


## [2.2.3] - 2023-11-02

### Added

- Support of `$referrerpolicy` modifier for compiler validation


## [2.2.2] - 2023-10-17

### Fixed
Expand Down
1 change: 1 addition & 0 deletions packages/tsurlfilter/src/rules/network-rule-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const NETWORK_RULE_OPTIONS = {
REMOVEHEADER: 'removeheader',
JSONPRUNE: 'jsonprune',
HLS: 'hls',
REFERRERPOLICY: 'referrerpolicy',
APP: 'app',
NETWORK: 'network',
EXTENSION: 'extension',
Expand Down
11 changes: 11 additions & 0 deletions packages/tsurlfilter/src/rules/network-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,17 @@ export class NetworkRule implements rule.IRule {
// TODO: should be properly implemented later
// https://github.com/AdguardTeam/tsurlfilter/issues/72
break;
// $referrerpolicy
// simple validation of referrerpolicy rules for compiler
// https://github.com/AdguardTeam/FiltersCompiler/issues/191
case OPTIONS.REFERRERPOLICY:
if (isCompatibleWith(CompatibilityTypes.Extension)) {
throw new SyntaxError('Extension does not support $referrerpolicy modifier');
}
// do nothing as $referrerpolicy is supported by CoreLibs-based apps only.
// it is needed for proper rule conversion performed by FiltersCompiler
// so rules with $referrerpolicy modifier is not marked as invalid
break;
// Dns modifiers
// $client
case OPTIONS.CLIENT:
Expand Down
6 changes: 6 additions & 0 deletions packages/tsurlfilter/test/rules/rule-converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ describe('Options', () => {
// converted rule should be the same as original
checkConversionResult(rule, rule);
});

it('converts referrerpolicy option properly', () => {
const rule = '||example.com^$referrerpolicy=origin';
// converted rule should be the same as original
checkConversionResult(rule, rule);
});
});

describe('Scriptlets', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/tsurlfilter/test/rules/rule-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ describe('RuleValidator', () => {
expect(RuleValidator.validate(ruleText).valid).toBeTruthy();
});

it('validates referrerpolicy modifier', () => {
// $referrerpolicy is not supported by the extension
setConfiguration({ compatibility: CompatibilityTypes.CoreLibs });
const ruleText = '||example.com^$referrerpolicy=origin';
expect(RuleValidator.validate(ruleText).valid).toBeTruthy();
});

it('invalidates rules $webrtc modifier', () => {
const ruleText = '$webrtc,domain=browserleaks.com';
expect(RuleValidator.validate(ruleText).valid).toBeFalsy();
Expand Down

0 comments on commit 23a50d1

Please sign in to comment.