Closed Bug 1223838 Opened 9 years ago Closed 8 years ago

Enable perElementReferrer by default

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla50
Iteration:
49.3 - Jun 6
Tracking Status
firefox50 --- fixed

People

(Reporter: franziskus, Assigned: tnguyen)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete)

Attachments

(3 files, 4 obsolete files)

Per-element referrer-policies are currently disabled by default with preference perElementReferrer. When the renaming landed (bug 1187357) we could enable this considering that the spec is in a better shape now [1].

[1] https://github.com/w3c/webappsec-referrer-policy
Depends on: 1178337
Assignee: nobody → franziskuskiefer
This needs an intent to ship, right?
Blocks: 1168540
Blocks: 999754
No longer blocks: 1168540
Depends on: 1168540
Depends on: 1264165
Tried to run some tests and I found if I enable this preference, Bug 1101288 will appear.
I will take closer look.
Depends on: 1101288
No longer depends on: 1101288
The below case failed:
https://dxr.mozilla.org/mozilla-central/source/dom/base/test/test_bug704320_policyset.html#40
This line fails and full referrerLevel was sent (expect none).
Speculative loading image: In the case there's no referrer policy attribute, currently empty string will be added and considered as default referrer policy value.
RP_Unset should be used in this case.
Attached patch Update meta fileSplinter Review
Assignee: franziskuskiefer → tnguyen
Attachment #8751169 - Flags: review?(franziskuskiefer)
Attachment #8751135 - Flags: review?(franziskuskiefer)
Status: NEW → ASSIGNED
Comment on attachment 8751135 [details] [diff] [review]
Fix wrong policy associated with empty string

Review of attachment 8751135 [details] [diff] [review]:
-----------------------------------------------------------------

The code itself looks good to me for what it's doing.

I'm not really sure why it's necessary though. You set RP_Unset everywhere instead of an empty string, right? Maybe I'm missing something but couldn't you just check for an empty string _and_ PR_Unset where necessary instead of adding all this code?
Attachment #8751135 - Flags: review?(franziskuskiefer)
Attachment #8751169 - Flags: review?(franziskuskiefer) → review+
Thanks Franziskus for your suggestion.
You are right. I think I got confused between [1] and [2]
[1] https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token
[2] https://w3c.github.io/webappsec-referrer-policy/#terms

Removed unnecessary code.
Attachment #8754675 - Flags: review?(franziskuskiefer)
Attachment #8751135 - Attachment is obsolete: true
Comment on attachment 8754675 [details] [diff] [review]
Fix wrong policy associated with empty string

Review of attachment 8754675 [details] [diff] [review]:
-----------------------------------------------------------------

much better, thanks :)
Attachment #8754675 - Flags: review?(franziskuskiefer) → review+
Attachment #8694659 - Flags: review?(hsivonen)
Attachment #8754675 - Flags: review?(hsivonen)
Hi Henri,
Could you please review these patches?
These patches changes:
- Change network.http.enablePerElementReferrer preference default to true 
- Handle empty_string in referrerpolicy attribute of preloading image element correctly.(The empty string corresponds to no referrer policy, or RP_Unset). That fixed failures running on try.
Thanks
Comment on attachment 8754675 [details] [diff] [review]
Fix wrong policy associated with empty string

Review of attachment 8754675 [details] [diff] [review]:
-----------------------------------------------------------------

This patch doesn't change what AttributeReferrerPolicyFromString() does, and that method is incompliant.

The HTML Standard says "An additional state is given by the empty string (which is also a valid referrer policy). The attribute's invalid value default and missing value default are both the empty string state." Furthermore, the Referrer Policy spec specifies an empty-string policy but no policy named "default": https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-empty-string . Still, ReferrerPolicy.h a) distinguishes between default and unset and b) maps default to "default". (Additionally, ReferrerPolicy.h does a whole lot of repeated case folding. I suggest making as ASCII-lowercase copy of the specified string first and then doing case-sensitive comparisons.)
Attachment #8754675 - Flags: review?(hsivonen) → review-
Comment on attachment 8694659 [details] [diff] [review]
enable perElementReferrer by default

Review of attachment 8694659 [details] [diff] [review]:
-----------------------------------------------------------------

Please re-request review on this patch after the mechanics of going from an attribute value to a referrer policy enum (and the set of values that the enum can take) have been update to the spec.
Attachment #8694659 - Flags: review?(hsivonen)
Iteration: --- → 49.3 - Jun 6
Thanks Henri for looking at this.
I filed Bug 1275803  for fixing [1] is not compliant with specs [2]. It would be better to check and fix all usages of function ReferrerPolicyFromString [1] and update/add more test cases if necessary

In this bug, I'd like to update as your suggestion, but only for AttributeReferrerPolicyFromString which is related to referrer policy attribute in [3] to make it a good shape compliant to specs

[1] https://dxr.mozilla.org/mozilla-central/source/netwerk/base/ReferrerPolicy.h#54
[2] https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token
[3] https://dxr.mozilla.org/mozilla-central/source/netwerk/base/ReferrerPolicy.h#107
Attachment #8757163 - Flags: review?(hsivonen)
Attachment #8754675 - Attachment is obsolete: true
Attachment #8694659 - Flags: review?(hsivonen)
Comment on attachment 8757163 [details] [diff] [review]
Fix wrong policy associated with empty string

Review of attachment 8757163 [details] [diff] [review]:
-----------------------------------------------------------------

(In reply to Thomas Nguyen[:tnguyen] from comment #15)
> Thanks Henri for looking at this.
> I filed Bug 1275803  for fixing [1] is not compliant with specs [2]. It
> would be better to check and fix all usages of function
> ReferrerPolicyFromString [1] and update/add more test cases if necessary

The non-attribute cases are:
CSP, <meta>, HTTP header(?) and LoadImageXPCOM(). It seems bad not to sync them with the attribute right here. Why shouldn't they be synced with the attribute right here?

> In this bug, I'd like to update as your suggestion, but only for
> AttributeReferrerPolicyFromString which is related to referrer policy
> attribute in [3] to make it a good shape compliant to specs

Maybe CSP, <meta>, HTTP header(?) and LoadImageXPCOM() can be allowed to be out of sync with the attribute and be handled in the other bug (though it worries me), but to handle the attribute consistently, this patch should also use AttributeReferrerPolicyFromString instead of ReferrerPolicyFromString at
https://mxr.mozilla.org/mozilla-central/source/dom/html/HTMLImageElement.cpp#558

r- because the patch didn't change that, too.

Also, I'd be much happier about r+ing a patch that synced the non-attribute sources of policy with the spec at the same time.
Attachment #8757163 - Flags: review?(hsivonen) → review-
(In reply to Henri Sivonen (:hsivonen) from comment #17)

> Maybe CSP, <meta>, HTTP header(?) and LoadImageXPCOM() can be allowed to be
> out of sync with the attribute and be handled in the other bug (though it
> worries me), but to handle the attribute consistently, this patch should
> also use AttributeReferrerPolicyFromString instead of
> ReferrerPolicyFromString at
> https://mxr.mozilla.org/mozilla-central/source/dom/html/HTMLImageElement.
> cpp#558
> 

:) Thanks for promptly review this. 


> (In reply to Thomas Nguyen[:tnguyen] from comment #15)
> > Thanks Henri for looking at this.
> > I filed Bug 1275803  for fixing [1] is not compliant with specs [2]. It
> > would be better to check and fix all usages of function
> > ReferrerPolicyFromString [1] and update/add more test cases if necessary
> 
> The non-attribute cases are:
> CSP, <meta>, HTTP header(?) and LoadImageXPCOM(). It seems bad not to sync
> them with the attribute right here. Why shouldn't they be synced with the
> attribute right here?

Probably, it's necessary to add more test cases for non-attribute fixing (because our current implementation for non-attribute is quite different from specs, return No_referrer vs Return Unset).
I just would like to make clearer to move non-attribute cases to another bug. This bug only fixes referrer attribute of element - as title.
Updated, will add test cases about this
Attachment #8757163 - Attachment is obsolete: true
Attachment #8757245 - Attachment is obsolete: true
Attachment #8757781 - Flags: review?(hsivonen)
Comment on attachment 8757781 [details] [diff] [review]
ReferrerPolicy from string is not compliant with specs

Review of attachment 8757781 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/html/HTMLImageElement.cpp
@@ +568,5 @@
>        aNameSpaceID == kNameSpaceID_None &&
>        aNotify) {
> +    ReferrerPolicy referrerPolicy = AttributeReferrerPolicyFromString(aValue);
> +    if (!InResponsiveMode() &&
> +        referrerPolicy != RP_Unset &&

Why is RP_Unset special-cased here?
(In reply to Henri Sivonen (:hsivonen) from comment #21)
> Comment on attachment 8757781 [details] [diff] [review]
> ReferrerPolicy from string is not compliant with specs
> 
> Review of attachment 8757781 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: dom/html/HTMLImageElement.cpp
> @@ +568,5 @@
> >        aNameSpaceID == kNameSpaceID_None &&
> >        aNotify) {
> > +    ReferrerPolicy referrerPolicy = AttributeReferrerPolicyFromString(aValue);
> > +    if (!InResponsiveMode() &&
> > +        referrerPolicy != RP_Unset &&
> 
> Why is RP_Unset special-cased here?
Thanks for looking at this.
Logically, if we put an invalid value into referrerPolicy attribute (then is parsed as RP_Unset) --> the old policy is overruled unexpectedly as new one (RP_Unset).
I added a test case for that in the patch
Attachment #8694659 - Flags: review?(hsivonen) → review+
Attachment #8757781 - Flags: review?(hsivonen) → review+
Nice! Thanks Henri for looking at this bug.
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/5e9e1c46cf0a
enable perElementReferrer by default. r=hsivonen
https://hg.mozilla.org/integration/mozilla-inbound/rev/b02a42d1be7c
Update web platform test meta file. r=franziskuskiefer
https://hg.mozilla.org/integration/mozilla-inbound/rev/471079c11bee
Fix wrong policy associated with empty string. r=fkiefer,hsivonen
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/5e9e1c46cf0a
https://hg.mozilla.org/mozilla-central/rev/b02a42d1be7c
https://hg.mozilla.org/mozilla-central/rev/471079c11bee
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: