Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement referrer policy delivery via noreferrer link relation #12493

Merged
merged 2 commits into from Sep 21, 2016

Conversation

@TheKK
Copy link
Contributor

TheKK commented Jul 18, 2016

According to https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-delivery, there's <a>, <link> and <area> could apply this delivery method. This PR contains changes for <a> and <link> but not <area>, since HTMLAreaElement is barely implemented.

We should file another issue for it.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #11862
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Jul 18, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @KiChjang (or someone else) soon.

@highfive
Copy link

highfive commented Jul 18, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/htmlanchorelement.rs, components/script/dom/htmlmediaelement.rs, components/script/dom/htmlscriptelement.rs, components/script/dom/document.rs, components/script/dom/window.rs, components/script/dom/htmllinkelement.rs, components/script/dom/location.rs, components/script/document_loader.rs
@TheKK TheKK force-pushed the TheKK:referrer_policy_dliver_via_rel branch 3 times, most recently from c379af1 to 930cb0f Jul 18, 2016
@jdm
Copy link
Member

jdm commented Jul 18, 2016

I don't believe the fallback should occur in that method, since it doesn't match https://w3c.github.io/webappsec-referrer-policy/#determine-policy-for-token .

@TheKK TheKK force-pushed the TheKK:referrer_policy_dliver_via_rel branch from 930cb0f to 80f9acd Jul 18, 2016
@TheKK
Copy link
Contributor Author

TheKK commented Jul 18, 2016

Oops. I misunderstand this with the empty string referrer policy. fixed.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 18, 2016

The latest upstream changes (presumably #11727) made this pull request unmergeable. Please resolve the merge conflicts.

@TheKK TheKK force-pushed the TheKK:referrer_policy_dliver_via_rel branch from f355721 to 22294db Jul 18, 2016
@TheKK
Copy link
Contributor Author

TheKK commented Jul 19, 2016

Hmm. Seems like 1a242d8 change the default referrer policy of Document and change part of my test expectations. I understand it's safer to set default as no-referrer for now, but it makes some of my test expectations from pass to failed and vice versa.

That's quite subtle since those passed tests are actually wrong. What do you think about this?

@jdm
Copy link
Member

jdm commented Jul 19, 2016

I think now that we implement multiple ways of delivering referrer policies (meta, HTTP header, and attributes) we can switch the default to no-referrer-when-downgrade without concern.

@TheKK TheKK force-pushed the TheKK:referrer_policy_dliver_via_rel branch from f835a06 to a4234f8 Jul 20, 2016
@KiChjang
Copy link
Member

KiChjang commented Jul 21, 2016

r? @jdm

@highfive highfive assigned jdm and unassigned KiChjang Jul 21, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Jul 21, 2016

The latest upstream changes (presumably #12468) made this pull request unmergeable. Please resolve the merge conflicts.

@TheKK TheKK force-pushed the TheKK:referrer_policy_dliver_via_rel branch from a4234f8 to 956acf7 Jul 21, 2016

if (referrer_policy) {
for (var attr in referrer_policy) {
// TODO crashed when you assigned value to rel attribute

This comment has been minimized.

@jdm

jdm Jul 28, 2016

Member

File an issue about this, please :)

This comment has been minimized.

@TheKK

TheKK Jul 29, 2016

Author Contributor

I found this problem does not exist anymore, so it's fine now.

@jdm
Copy link
Member

jdm commented Jul 28, 2016

I tried to use reviewable, but either it or Firefox choked. I'll leave a comment when I'm done reviewing the diffs on github.

var iframe = appendIframeToBody(url_with_params);
iframe.addEventListener("load", function listener() {
if ((iframe.contentWindow !== null) &&
(iframe.contentWindow.location.toString() === url_with_params)) {

This comment has been minimized.

@jdm

jdm Jul 28, 2016

Member

Let's add a return here and remove the else.

This comment has been minimized.

@TheKK

TheKK Jul 29, 2016

Author Contributor

fixed!

var xhr = new XMLHttpRequest();
xhr.open('GET', '/_mozilla/mozilla/referrer-policy/generic/subresource/stash.py?id=' + id, false);
xhr.onreadystatechange = function(e) {
if (this.readyState == 4 && this.status == 200) {

This comment has been minimized.

@jdm

jdm Jul 28, 2016

Member

If we use onload instead, we don't need these checks.

This comment has been minimized.

@TheKK

TheKK Jul 29, 2016

Author Contributor

fixed! So did the others in common.js

};
xhr.send();

clearTimeout(timeout_func);

This comment has been minimized.

@jdm

jdm Jul 28, 2016

Member

No need to clear the timeout after it's fired.

This comment has been minimized.

@TheKK

TheKK Jul 29, 2016

Author Contributor

Won't it cause problem if it fired more than once?

This comment has been minimized.

@jdm

jdm Aug 3, 2016

Member

I think you're thinking of setInterval?

var xhr = new XMLHttpRequest();
xhr.open('GET', '/_mozilla/mozilla/referrer-policy/generic/subresource/stash.py?id=' + id, false);
xhr.onreadystatechange = function(e) {
if (this.readyState == 4 && this.status == 200) {

This comment has been minimized.

@jdm

jdm Jul 28, 2016

Member

Let's use onload instead.

This comment has been minimized.

@TheKK

TheKK Jul 29, 2016

Author Contributor

fixed!

@TheKK
Copy link
Contributor Author

TheKK commented Sep 20, 2016

Added!

@jdm
Copy link
Member

jdm commented Sep 20, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 20, 2016

📌 Commit a7639d9 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Sep 20, 2016

Testing commit a7639d9 with merge 2945449...

bors-servo added a commit that referenced this pull request Sep 20, 2016
Implement referrer policy delivery via noreferrer link relation

According to https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-delivery, there's `<a>`, `<link>` and `<area>` could apply this delivery method. This PR contains changes for `<a>` and `<link>` **but** not `<area>`, since HTMLAreaElement is barely implemented.

We should file another issue for it.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #11862
- [X] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12493)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 20, 2016

💔 Test failed - mac-rel-wpt

@highfive
Copy link

highfive commented Sep 20, 2016

  ▶ TIMEOUT [expected OK] /webgl/conformance-1.0.3/conformance/textures/origin-clean-conformance.html
@jdm
Copy link
Member

jdm commented Sep 20, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 20, 2016

Testing commit a7639d9 with merge 8a78e75...

bors-servo added a commit that referenced this pull request Sep 20, 2016
Implement referrer policy delivery via noreferrer link relation

According to https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-delivery, there's `<a>`, `<link>` and `<area>` could apply this delivery method. This PR contains changes for `<a>` and `<link>` **but** not `<area>`, since HTMLAreaElement is barely implemented.

We should file another issue for it.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #11862
- [X] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12493)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 21, 2016

@bors-servo bors-servo merged commit a7639d9 into servo:master Sep 21, 2016
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@jdm
Copy link
Member

jdm commented Sep 21, 2016

Woooo! Thanks for sticking with this, @TheKK!

@TheKK TheKK deleted the TheKK:referrer_policy_dliver_via_rel branch Sep 21, 2016
@TheKK TheKK restored the TheKK:referrer_policy_dliver_via_rel branch Sep 21, 2016
@TheKK TheKK deleted the TheKK:referrer_policy_dliver_via_rel branch Sep 22, 2016
bors-servo added a commit that referenced this pull request Mar 31, 2017
Fix referrer policy tests for a-tag

This RP tries to fix referrer policy test for <a> which was introduced in #12493 (sorry for my silly mistake). But the fact that Servo lakes of some functionalities make these tests a little tricky to do.

The desired solution for tests for <a> is to:
1. create a document which is running test harness
2. append an `<iframe>` to its parent document and give it a name
3. append and `<a>` to its parent document and set its `target` as `<iframe>`'s name
4. each referrer policy attribute (eg. HTTP header, <meta>) would contribute to `<a>` directly
5. we call `click()` on `<a>` and when the test was done, we call `postMessage()` inside `<iframe>` to notify its parent document

And target feature for `<a>` and cross origin `postMessage()` is still on its way. My solution is:
1. create a document which is running test harness
2. append an `<iframe>` to its parent document
3. append and `<a>` into `<iframe>`
4. we call `click()` on `<a>` and `<iframe>` navigate to `<a>`'s href

Current solution does not work for some cases:
- HTTP header, it only apply to test harness html document but `<a>` inside `<iframe>`
- cross origin detection, we navigate `<iframe>` rather than its parent document, which make test expectation wrong

One workaround in my mind is to load our test harness html document **inside** `<iframe>` under sandbox, so the test won't run again and we get `<meta>` and HTTP header as we expect. But this would break some consistency in `common.js` and make thing more complex.

---

Sorry for the long description. But I'd like to hear more thought before I actually make things dirty, and find the most proper solution for this.

<!-- Reviewable:start -->

---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13713)

<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Mar 31, 2017
Fix referrer policy tests for a-tag

This RP tries to fix referrer policy test for <a> which was introduced in #12493 (sorry for my silly mistake). But the fact that Servo lakes of some functionalities make these tests a little tricky to do.

The desired solution for tests for <a> is to:
1. create a document which is running test harness
2. append an `<iframe>` to its parent document and give it a name
3. append and `<a>` to its parent document and set its `target` as `<iframe>`'s name
4. each referrer policy attribute (eg. HTTP header, <meta>) would contribute to `<a>` directly
5. we call `click()` on `<a>` and when the test was done, we call `postMessage()` inside `<iframe>` to notify its parent document

And target feature for `<a>` and cross origin `postMessage()` is still on its way. My solution is:
1. create a document which is running test harness
2. append an `<iframe>` to its parent document
3. append and `<a>` into `<iframe>`
4. we call `click()` on `<a>` and `<iframe>` navigate to `<a>`'s href

Current solution does not work for some cases:
- HTTP header, it only apply to test harness html document but `<a>` inside `<iframe>`
- cross origin detection, we navigate `<iframe>` rather than its parent document, which make test expectation wrong

One workaround in my mind is to load our test harness html document **inside** `<iframe>` under sandbox, so the test won't run again and we get `<meta>` and HTTP header as we expect. But this would break some consistency in `common.js` and make thing more complex.

---

Sorry for the long description. But I'd like to hear more thought before I actually make things dirty, and find the most proper solution for this.

<!-- Reviewable:start -->

---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13713)

<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Mar 31, 2017
Fix referrer policy tests for a-tag

This RP tries to fix referrer policy test for <a> which was introduced in #12493 (sorry for my silly mistake). But the fact that Servo lakes of some functionalities make these tests a little tricky to do.

The desired solution for tests for <a> is to:
1. create a document which is running test harness
2. append an `<iframe>` to its parent document and give it a name
3. append and `<a>` to its parent document and set its `target` as `<iframe>`'s name
4. each referrer policy attribute (eg. HTTP header, <meta>) would contribute to `<a>` directly
5. we call `click()` on `<a>` and when the test was done, we call `postMessage()` inside `<iframe>` to notify its parent document

And target feature for `<a>` and cross origin `postMessage()` is still on its way. My solution is:
1. create a document which is running test harness
2. append an `<iframe>` to its parent document
3. append and `<a>` into `<iframe>`
4. we call `click()` on `<a>` and `<iframe>` navigate to `<a>`'s href

Current solution does not work for some cases:
- HTTP header, it only apply to test harness html document but `<a>` inside `<iframe>`
- cross origin detection, we navigate `<iframe>` rather than its parent document, which make test expectation wrong

One workaround in my mind is to load our test harness html document **inside** `<iframe>` under sandbox, so the test won't run again and we get `<meta>` and HTTP header as we expect. But this would break some consistency in `common.js` and make thing more complex.

---

Sorry for the long description. But I'd like to hear more thought before I actually make things dirty, and find the most proper solution for this.

<!-- Reviewable:start -->

---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13713)

<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.