Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Try to fix #3581, make Screenshots work with third party cookies disabled #3601

Merged
merged 1 commit into from
Oct 12, 2017

Conversation

ianb
Copy link
Contributor

@ianb ianb commented Oct 6, 2017

This adds a second attempt to login to wantsauth logins, one that runs in sitehelper.js, and tries to get the cookie set on a request that appears to come from the content page itself.

Note: this now works, but doesn't provide full protection from a screenshots.firefox.com page (that is under attack) from getting the authentication header.

@ianb
Copy link
Contributor Author

ianb commented Oct 10, 2017

@mixedpuppy pointed me to Bug 1295660, which has a patch to expose the XMLHttpRequest, in the way that this code gets that object but without confirming it's the browser's copy of XMLHttpRequest.

@ianb ianb force-pushed the third-party-cookie branch from ca01150 to 43765b2 Compare October 10, 2017 19:47
@ianb ianb changed the title [WIP] Try to fix #3581, make Screenshots work with third party cookies disabled Try to fix #3581, make Screenshots work with third party cookies disabled Oct 10, 2017
@ianb ianb requested a review from g-k October 10, 2017 19:48
@ianb ianb force-pushed the third-party-cookie branch from 43765b2 to 4b57cf9 Compare October 10, 2017 20:11
Copy link
Contributor

@g-k g-k left a comment

Choose a reason for hiding this comment

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

I wasn't able to trigger the set-login-cookie route after disabling third party cookies.

But modulo a couple nits it looks good to me. 👍

@mozfreddyb do you want to take a look?

Ideally, I think we'd get screenshots to only use cross origin requests for creating shots and maybe login. The approach here: #3581 (comment) looks good but it does sound painful. Instead I think we should keep an eye on https://bugzilla.mozilla.org/show_bug.cgi?id=1295660 since it should let us treat xhrs from content scripts as first party.

@@ -26,7 +26,8 @@ function isCsrfExemptPath(path) {
return isAuthPath(path)
|| path.startsWith("/data")
|| path === "/event"
|| path === "/error";
|| path === "/error"
|| path === "/api/set-login-cookie";
Copy link
Contributor

Choose a reason for hiding this comment

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

If the POST /api/set-login-cookie sends an origin header, we should validate its protocol/scheme is moz-extension:// in the csrf middleware.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears not to send any Origin header at all. I'm a bit surprised, I would have expected it to be the site origin. Or maybe it would only be set for CORS requests?

accountId: req.accountId,
userAbTests: req.abTests
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unit tests for this route or an issue to add them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added

Copy link
Member

@jaredhirsch jaredhirsch left a comment

Choose a reason for hiding this comment

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

works for me locally with third-party cookies disabled

This adds a second attempt to login to wantsauth logins, one that runs in sitehelper.js, and tries to get the cookie set on a request that appears to come from the content page itself.

Note this does not firmly protect from the content page overwriting window.XMLHttpRequest and having the add-on use that object.
@ianb
Copy link
Contributor Author

ianb commented Oct 11, 2017

I created a followup to make use of Bug 1295660 in #3626

@ianb ianb merged commit a4b6485 into master Oct 12, 2017
@jaredhirsch jaredhirsch deleted the third-party-cookie branch December 4, 2017 20:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants