Page MenuHomePhabricator

Bug 2045811: Add a site policy to disable service workers. r=#dom-worker-reviewers!,mkaply!
ClosedPublic

Authored by mossop on Aug 6 2026, 12:18 PM.
Referenced Files
Unknown Object (File)
Wed, Oct 21, 9:51 AM
Unknown Object (File)
Tue, Oct 20, 5:15 AM
Unknown Object (File)
Fri, Oct 16, 12:01 PM
Unknown Object (File)
Thu, Oct 15, 9:36 AM
Unknown Object (File)
Oct 13 2026, 1:02 AM
Unknown Object (File)
Oct 9 2026, 12:46 PM
Unknown Object (File)
Oct 2 2026, 2:42 AM
Unknown Object (File)
Sep 28 2026, 6:55 AM

Diff Detail

Event Timeline

phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.

Code analysis found 1 defect in diff 1341073:

  • 1 defect found by eslint (Mozlint)
IMPORTANT: Found 1 defect (error level) that must be fixed before landing.

You can run this analysis locally with:

  • ./mach lint --warnings --outgoing

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1341073.

r=me on the policy part.

edenchuang requested changes to this revision.EditedAug 10 2026, 2:06 PM
edenchuang added a subscriber: edenchuang.

I am confused about the word "disable."

"Disable" would make me think the ServiceWorker registration/unregistration is also disabled since ServiceWorker doesn't only intercept fetch.

In fact, the patch just introduces a new mechanism for skipping the ServiceWorker interception by the document's EnterprisePolicies.
Maybe we can have a better name than "Disable."

And considering we already have an interception-skipping mechanism there, which is by setting nsLoadFlags with nsIChannel::LOAD_BYPASS_SERVICE_WORKER.
I am thinking we could reuse the original one instead of introducing a new one.

This revision now requires changes to proceed.Aug 10 2026, 2:06 PM

I am confused about the word "disable."

"Disable" would make me think the ServiceWorker registration/unregistration is also disabled since ServiceWorker doesn't only intercept fetch.

Disabling is what we want, it is intended that registration/unregistration is also disabled for matching sites and I believe that the patch implements this.

In fact, the patch just introduces a new mechanism for skipping the ServiceWorker interception by the document's EnterprisePolicies.
Maybe we can have a better name than "Disable."

By patching the ServiceWorkersEnabled function it also disables access to the JS APIs exposed on the window object. Are there other things we should be disabling?

And considering we already have an interception-skipping mechanism there, which is by setting nsLoadFlags with nsIChannel::LOAD_BYPASS_SERVICE_WORKER.
I am thinking we could reuse the original one instead of introducing a new one.

Thanks, I hadn't spotted that, I will try to update the patch to use it.

mossop updated this revision to Diff 1345771.

Code analysis found 2 defects in diff 1345771:

  • 2 build errors found by clang-tidy
IMPORTANT: Found 2 defects (error level) that must be fixed before landing.

You can run this analysis locally with:

  • ./mach static-analysis check --outgoing (C/C++)

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1345771.

mossop updated this revision to Diff 1345893.

Code analysis found 2 defects in diff 1345893:

  • 2 build errors found by clang-tidy
IMPORTANT: Found 2 defects (error level) that must be fixed before landing.

You can run this analysis locally with:

  • ./mach static-analysis check --outgoing (C/C++)

If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1345893.

I am confused about the word "disable."

"Disable" would make me think the ServiceWorker registration/unregistration is also disabled since ServiceWorker doesn't only intercept fetch.

Disabling is what we want, it is intended that registration/unregistration is also disabled for matching sites and I believe that the patch implements this.

In fact, the patch just introduces a new mechanism for skipping the ServiceWorker interception by the document's EnterprisePolicies.
Maybe we can have a better name than "Disable."

By patching the ServiceWorkersEnabled function it also disables access to the JS APIs exposed on the window object. Are there other things we should be disabling?

Aha, my fault; I did not see that patched part in ServiceWorkerEnabled(). So it is really disabled ServiceWorker according to the policy.
Thank you for clarifying this.

And considering we already have an interception-skipping mechanism there, which is by setting nsLoadFlags with nsIChannel::LOAD_BYPASS_SERVICE_WORKER.
I am thinking we could reuse the original one instead of introducing a new one.

Thanks, I hadn't spotted that, I will try to update the patch to use it.

And thank you for adapting the implementation to nsIChannel::LOAD_BYPASS_SERVICE_WORKER.

This revision is now accepted and ready to land.Aug 13 2026, 2:24 PM

This revision requires a Testing Policy Project Tag to be set before landing. Please apply one of testing-approved, testing-exception-unchanged, testing-exception-ui, testing-exception-elsewhere, testing-exception-other. Tip: this Firefox add-on makes it easy!

Can one of you set a testing-policy flag?

This revision was not accepted when it landed; it landed in state Needs Review.Aug 17 2026, 1:10 PM
This revision was automatically updated to reflect the committed changes.