Page MenuHomePhabricator

Bug 1960904 - Add IntegrityPolicy as a content-policy r=tschuster
AcceptedPublic

Authored by fkilic on Thu, May 8, 2:53 PM.

Details

Reviewers
tschuster
zombie
Group Reviewers
extension-reviewers
Bugzilla Bug ID
1960904

Diff Detail

Repository
rFIREFOXAUTOLAND firefox-autoland
Branch
HEAD
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
dom/security/IntegrityPolicy.cpp
375

changed it as you suggested, matching more with the spec

Very close now, thanks!

dom/security/IntegrityPolicy.h
29

This should not be required.

dom/security/IntegrityPolicyService.cpp
62

Please change this whole method to the above like I said before.

154

We need to file a spec for bug this.

layout/build/components.conf
126

Do we need this?

This revision now requires changes to proceed.Tue, May 27, 2:50 PM
dom/security/IntegrityPolicy.h
29

Sorry, actually, I guess like the components.conf change this might be for the next patch?

fkilic updated this revision to Diff 1047393.
fkilic marked 4 inline comments as done.
dom/security/IntegrityPolicy.h
29

yeah i think so. i just tried and I get component not registered error when i try to serialize/deserialize.

dom/security/IntegrityPolicyService.cpp
62

Ah I misunderstood the last time. Changed it fully now.

tschuster added inline comments.
dom/security/IntegrityPolicyService.cpp
169

I forgot about this, sorry, but even though we don't support the Reporting API, will should still log something in the console.

You probably want use nsContentUtils::ReportToConsoleByWindowID and have an error message for the blocking case, and a warning for the report-only case.

This revision is now accepted and ready to land.Wed, May 28, 1:45 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!

fkilic added inline comments.
dom/security/IntegrityPolicyService.cpp
169

added reporting (to console only for now)

fkilic marked an inline comment as done.
fkilic requested review of this revision.Mon, Jun 2, 8:02 PM
fkilic added inline comments.
dom/security/IntegrityPolicyService.cpp
79–86

I added this part, so I'm re-requesting review.

dom/locales/en-US/chrome/security/security.properties
172

Is this correct? Other strings use the format blockedwould block, also not sure about the colon.

tschuster added inline comments.
dom/locales/en-US/chrome/security/security.properties
172

Thanks flod! Yes, we should make this error message more verbose and probably more similar to the existing CSP messages.

https://searchfox.org/mozilla-central/source/dom/locales/en-US/chrome/security/csp.properties#100-106

Maybe something like:

The page’s settings blocked a script at %S from being executed because it missing integrity metadata.

And

(Report-Only policy) The page’s settings would block a script ...

dom/security/IntegrityPolicyService.cpp
79–86

We would need a test for this. And I am wondering if we shouldn't use something like BasePrincipal::OverridesCSP here, which is used by LoadInfo::GetCsp. For now this probably ok.

81

aLoadInfo->TriggerPrincipal() as it can never be null.

This revision now requires changes to proceed.Tue, Jun 3, 8:24 AM
dom/security/IntegrityPolicyService.cpp
79–86

I recently wrote a test for something a bit similar in D246753.

fkilic requested review of this revision.Tue, Jun 3, 2:57 PM
fkilic updated this revision to Diff 1051887.
fkilic added inline comments.
dom/locales/en-US/chrome/security/security.properties
172

updated it

dom/security/IntegrityPolicyService.cpp
79–86

added the test

81

changed it

zombie added 1 blocking reviewer(s): tschuster.
zombie added a subscriber: zombie.
zombie added inline comments.
toolkit/components/extensions/test/xpcshell/test_ext_contentscript_integritypolicy.js
9

Is the expectation that the page itself couldn't load a script tag? If so, probably worth confirming that in the same test, as a sanity check.

37–38

I think you can use test.sendMessage directly from here.

57–59

you can just do = await extension.awaitMessage()

toolkit/components/extensions/test/xpcshell/test_ext_contentscript_integritypolicy.js
57–59

result = await extension.awaitMessage("script-loaded")

fkilic marked an inline comment as done.
toolkit/components/extensions/test/xpcshell/test_ext_contentscript_integritypolicy.js
9

oh you are right added it

37–38

huh I couldn't make it work last time but it works now, wonder what I did last time. changed it, thanks!

57–59

ah I only did result = extension.awaitMessage("script-loaded") (without await) and thought it didn't work. changed it, thank you!

Thanks for adding the extension test.

dom/locales/en-US/chrome/security/security.properties
172

Sorry, I made a typo. it is missing

dom/security/IntegrityPolicyService.cpp
187

Let's just make this void. We can't really use the return value anyway.

toolkit/components/extensions/test/xpcshell/test_ext_contentscript_integritypolicy.js
30

Uber nit: Can you just call this content_script.js?

toolkit/components/extensions/test/xpcshell/test_ext_contentscript_integritypolicy.js
20

We probably want

registerCleanupFunction(() => {
  Services.prefs.clearUserPref("security.integrity_policy.enabled");
});
tschuster added inline comments.
dom/security/IntegrityPolicyService.cpp
83

LoadingPrincipal does need a null check.

This revision now requires changes to proceed.Wed, Jun 4, 9:03 AM
fkilic requested review of this revision.Wed, Jun 4, 1:29 PM
fkilic updated this revision to Diff 1052683.
fkilic marked an inline comment as done.
This revision is now accepted and ready to land.Wed, Jun 4, 1:34 PM
fkilic marked 11 inline comments as done.Wed, Jun 4, 1:37 PM

Thank you for reviewing!

dom/locales/en-US/chrome/security/security.properties
172

oh right, i should have noticed too, updated it

dom/security/IntegrityPolicyService.cpp
83

yep i noted it above

154
187

changed it

toolkit/components/extensions/test/xpcshell/test_ext_contentscript_integritypolicy.js
20

added it thank you

30

sure

fkilic added inline comments.
dom/security/IntegrityPolicyService.cpp
83

oh i guess this was an old comment, sorry.