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

Fixes #3135, fix opt-out form on Safari browsers by opening new window that sets the cookie. #7754

Closed
wants to merge 26 commits into from

Conversation

diosmosis
Copy link
Member

As title.

This PR allows us to set 3rd party cookies in the opt-out form for Piwik. It works by opening a new window on form submission, reloading the new window, and setting the cookie on this reload. It is necessary to reload the window, because the session cookie isn't set, so the nonce won't be detected & so, the ignore cookie won't be set.

It works whether JavaScript is enabled or not, and other browsers still get the better UX.

I tried two alternative solutions to provide better UX, but neither worked on the latest version of Safari (Safari 8):

  1. I first tried to do the form POST as an AJAX request and set the cookies manually via JavaScript. This failed when trying to read the cookies sent by the POST; Safari would not allow reading the Set-Cookie response.

  2. I also tried the triple redirect solution described here: http://measurablewins.gregjxn.com/2014/02/safari-setting-third-party-iframe.html?m=1

    This failed due to the same origin policy. The iframe cannot access the top frame unless they both come from the same domain. It might be possible for the website hosting the iframe to allow this, but Piwik can't control whether the website does this.

Tested on Safari in a Mac and on an iPhone.

TODO:

  • add a UI test testing normal opt-out behavior + safari opt-out behavior (maybe not possible since a new window is created)
  • test on versions of IE in case it's necessary + test on chrome + opera to make sure normal behavior still works for them
  • add issue for putting opt-out form in tracker too; using first-party cookies for this seems like it would be desirable to some people.

Refs #3135

@diosmosis diosmosis added Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. Needs Review PRs that need a code review labels Apr 23, 2015
@diosmosis diosmosis added this to the Piwik 2.14.0 milestone Apr 23, 2015
@@ -320,21 +320,34 @@ public function trackingCodeGenerator()
*/
public function optOut()
{
$reref = Common::getRequestVar('reref', false);
if (!empty($reref)) {
Url::redirectToUrl($reref);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is a security vulnerability, "Open redirect": https://www.owasp.org/index.php/Open_redirect
could it be avoided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually that's dead code from one of the other attempts at fixing the problem. It can be removed, thanks for catching it!

@diosmosis diosmosis removed the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Apr 26, 2015
diosmosis added 2 commits April 26, 2015 17:03
@mattab
Copy link
Member

mattab commented Apr 27, 2015

created new FAQ https://piwik.org/faq/general/faq_20000/

@mattab
Copy link
Member

mattab commented Apr 27, 2015

Can you smash commits into one and then +1 to merge

@diosmosis
Copy link
Member Author

Merged in 7cc3bfc

@diosmosis diosmosis closed this Apr 27, 2015
@diosmosis diosmosis deleted the safari_cookies_optout2 branch April 27, 2015 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants