Skip to content

Commit

Permalink
Added trusted flag to the filters registry (#562)
Browse files Browse the repository at this point in the history
* Added trusted flag to the filters registry

* Update hostlists-builder/index.js

Co-authored-by: Slava <[email protected]>

---------

Co-authored-by: Slava <[email protected]>
  • Loading branch information
ameshkov and slavaleleka authored Nov 21, 2024
1 parent dd718c6 commit 427887e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
"program": "${workspaceFolder}/scripts/compose.js"
},
{
"type": "pwa-node",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The files `/assets/filters.json` and `/assets/filters-dev.json` must not be edit
- `environment` - either `dev` or `prod`. Only `prod` lists are available in AdGuard DNS.
- `disabled` - if set to `true`, the blocklist won't be updated.
- `tags` — a list of [tags](#tags)
- `trusted` - a flag that allows using `$dnsrewrite` rules for this filter. If the filter is not trusted, `$dnsrewrite` rules will be removed from the compiled filter.

<details>
<summary>Metadata example</summary>
Expand All @@ -86,7 +87,8 @@ The files `/assets/filters.json` and `/assets/filters-dev.json` must not be edit
"expires": "4 days",
"displayNumber": 3,
"environment": "prod",
"tags": []
"tags": [],
"trusted": true
}
```

Expand Down
3 changes: 2 additions & 1 deletion filters/general/filter_1_DnsFilter/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"environment": "prod",
"tags": [
"purpose:general"
]
],
"trusted": true
}
3 changes: 2 additions & 1 deletion filters/general/filter_59_DnsPopupsFilter/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"environment": "prod",
"tags": [
"purpose:general"
]
],
"trusted": true
}
9 changes: 8 additions & 1 deletion hostlists-builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,18 @@ async function build(filtersDir, tagsDir, localesDir, assetsDir, groupsDir) {
revision.setVersionCandidate();
revision.setTimeUpdatedCandidate();

const hostlistCompiled = await hostlistCompiler({
let hostlistCompiled = await hostlistCompiler({
...hostlistConfiguration,
version: revision.getVersionCandidate(),
});

if (!metadata.trusted) {
// Remove $dnsrewrite rules if the filter is not trusted.
hostlistCompiled = hostlistCompiled.filter((line) => {
return !line.includes('dnsrewrite=');
});
}

const hash = calculateRevisionHash(hostlistCompiled);

// Rewrites the filter if it's actually changed.
Expand Down

0 comments on commit 427887e

Please sign in to comment.