Skip to content

DNR block rules with lower priority override redirect rules with a higher priority #2

Open
@lenacohen

Description

@lenacohen

A lower-priority DNR block rule that matches a request is being applied before a higher-priority DNR redirect rule that matches the same request, preventing the redirect from occurring. The only way to get the high-priority redirect rule to occur is to remove the DNR block rule.

Steps to reproduce:

  • Create/install a web extension on Safari with the declarativeNetRequest and declarativeNetRequestWithHostAccess permissions
  • Open the Web Extension Background Content console and add a redirect rule with a high priority number. For example:
await chrome.declarativeNetRequest.updateDynamicRules({addRules: [
    {id: 5000, condition: {urlFilter: "||www.google-analytics.com*/ga.js", resourceTypes: ["script"], domainType: "thirdParty"}, priority: 80, action: {type: "redirect", redirect: {url: “http://www.apple.com/”}}}
]})
  • Add a block rule of lower priority for the same urlFilter:
await chrome.declarativeNetRequest.updateDynamicRules({addRules: [
    {id: 5001, condition: {urlFilter: "||www.google-analytics.com^", domainType: "thirdParty"}, priority: 1, action: {type: "block"}}
]})

Demo Xcode extension: https://github.com/lenacohen/Safari-Test-Extensions/tree/main/dnr-redirect-block-priority

Apple Feedback Assistant Bug Report: FB16535579
Apple Developer Forum Post
Safari version 18.3
MacOS Sequoia 15.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    DNRIssue with Safari's Declarative Net Request API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions