RESOLVED FIXED Bug 199261
Align with Origin header changes
https://bugs.webkit.org/show_bug.cgi?id=199261
Summary Align with Origin header changes
Anne van Kesteren
Reported 2019-06-27 01:16:32 PDT
https://github.com/whatwg/fetch/pull/908 clarifies how the Origin header interacts with Referrer Policy. https://github.com/web-platform-tests/wpt/pull/14260 adds a number of tests around that.
Attachments
Patch (22.28 KB, patch)
2020-01-25 09:18 PST, Rob Buis
no flags
Patch (25.58 KB, patch)
2020-01-25 09:59 PST, Rob Buis
no flags
Patch (10.52 KB, patch)
2020-03-03 03:18 PST, Rob Buis
no flags
Patch (23.77 KB, patch)
2020-03-04 02:47 PST, Rob Buis
no flags
Patch (23.89 KB, patch)
2020-03-09 10:27 PDT, Rob Buis
no flags
Patch (24.39 KB, patch)
2020-03-09 13:04 PDT, Rob Buis
no flags
Patch (24.44 KB, patch)
2020-03-09 14:27 PDT, Rob Buis
no flags
Rob Buis
Comment 1 2020-01-25 09:18:31 PST
Rob Buis
Comment 2 2020-01-25 09:59:53 PST
Rob Buis
Comment 3 2020-03-03 03:18:55 PST
Rob Buis
Comment 4 2020-03-04 02:47:53 PST
youenn fablet
Comment 5 2020-03-09 03:22:13 PDT
Comment on attachment 392400 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=392400&action=review > Source/WebCore/loader/FrameLoader.cpp:504 > + submission->setOrigin(SecurityPolicy::generateOriginHeader(m_frame.document()->referrerPolicy(), submission->requestURL(), SecurityOrigin::createFromString(outgoingOrigin()))); Let's change SecurityOrigin::createFromString(outgoingOrigin()) into m_frame.document()->securityOrigin() > Source/WebCore/loader/cache/CachedResourceRequest.cpp:233 > + outgoingOrigin = SecurityPolicy::generateOriginHeader(m_options.referrerPolicy, m_resourceRequest.url(), SecurityOrigin::createFromString(outgoingReferrer)); If the resource request has a referrer, we will create a SecurityOrigin from the outgoingReferrer twice. Can we update the code to only do that once if needed? Also, it is not clear to me why we have to check the mode here. The spec does not say anything about that.
Rob Buis
Comment 6 2020-03-09 10:27:26 PDT
youenn fablet
Comment 7 2020-03-09 10:38:11 PDT
Comment on attachment 393050 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393050&action=review > Source/WebCore/loader/cache/CachedResourceRequest.cpp:230 > } Remove { } > Source/WebCore/loader/cache/CachedResourceRequest.cpp:231 > + if (m_options.mode == FetchOptions::Mode::Cors) If mode is CORS, we probably already set the origin header, right? So FrameLoader::addHTTPOriginIfNeeded will be a no-op. It might be better to do all this processing if the request does not have any origin. Either using if (!m_resourceRequest.httpOrigin().isEmpty()) return; Or by introducing something like FrameLoader::addHTTPOriginIfiNeeded(Request, const Function<String()>& computeOriginValue)
Rob Buis
Comment 8 2020-03-09 13:04:39 PDT
Rob Buis
Comment 9 2020-03-09 13:55:14 PDT
Comment on attachment 392400 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=392400&action=review >> Source/WebCore/loader/FrameLoader.cpp:504 >> + submission->setOrigin(SecurityPolicy::generateOriginHeader(m_frame.document()->referrerPolicy(), submission->requestURL(), SecurityOrigin::createFromString(outgoingOrigin()))); > > Let's change SecurityOrigin::createFromString(outgoingOrigin()) into m_frame.document()->securityOrigin() Done. >> Source/WebCore/loader/cache/CachedResourceRequest.cpp:233 >> + outgoingOrigin = SecurityPolicy::generateOriginHeader(m_options.referrerPolicy, m_resourceRequest.url(), SecurityOrigin::createFromString(outgoingReferrer)); > > If the resource request has a referrer, we will create a SecurityOrigin from the outgoingReferrer twice. > Can we update the code to only do that once if needed? > > Also, it is not clear to me why we have to check the mode here. > The spec does not say anything about that. Done. The spec does not say anything about mode but does mention tainting, step 2 in https://fetch.spec.whatwg.org/#append-a-request-origin-header. I am not sure if I can test the tainting here though.
Darin Adler
Comment 10 2020-03-09 13:57:01 PDT
Comment on attachment 393063 [details] Patch EWS is showing origin-related test failures. Please don’t land without resolving those
Rob Buis
Comment 11 2020-03-09 14:00:25 PDT
Yes I was trying to verify Youenn's question "If mode is CORS, we probably already set the origin header, right?". Since the ASSERT_NOT_REACHED is reached, we know the answer is no. But anyway I want Youenn to approve the patch before landing, so hopefully some time tomorrow.
Rob Buis
Comment 12 2020-03-09 14:27:01 PDT
Rob Buis
Comment 13 2020-03-10 02:29:00 PDT
Comment on attachment 393050 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393050&action=review >> Source/WebCore/loader/cache/CachedResourceRequest.cpp:230 >> } > > Remove { } Done. >> Source/WebCore/loader/cache/CachedResourceRequest.cpp:231 >> + if (m_options.mode == FetchOptions::Mode::Cors) > > If mode is CORS, we probably already set the origin header, right? > So FrameLoader::addHTTPOriginIfNeeded will be a no-op. > > It might be better to do all this processing if the request does not have any origin. > Either using > if (!m_resourceRequest.httpOrigin().isEmpty()) > return; > > Or by introducing something like FrameLoader::addHTTPOriginIfiNeeded(Request, const Function<String()>& computeOriginValue) So for CORS we do not set the origin header (I added an ASSERT_NOT_REACHED and it was hit a lot as you can see in the previous upload). I would really like to centralize the places to where the origin header is set, ideally to one, so here, but I know it is needed in a few other places like sync loading. I made an attempt to return early if the Origin is already set to make things a bit more effiicient.
youenn fablet
Comment 14 2020-03-10 03:23:43 PDT
Comment on attachment 393073 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393073&action=review > Source/WebCore/loader/cache/CachedResourceRequest.cpp:236 > + outgoingOrigin = SecurityOrigin::createFromString(outgoingReferrer)->toString(); The append Origin algorithm is making use of response tainting == cors, which is different from the mode. Probably we have some slight behavioural differences, or maybe we already set the origin header in the cases that matter. Would be worth investigating. It would also be nice to add a routine that implements the whole https://fetch.spec.whatwg.org/#append-a-request-origin-header algorithm. We have some bits here and there which makes it hard to know whether we are doing the right thing. For instance HEAD/GET check is done in FrameLoader::addHTTPOriginIfNeeded, not here. All of this might best be done as follow-ups though, let's go with this patch.
Rob Buis
Comment 15 2020-03-10 03:37:18 PDT
Comment on attachment 393073 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393073&action=review >> Source/WebCore/loader/cache/CachedResourceRequest.cpp:236 >> + outgoingOrigin = SecurityOrigin::createFromString(outgoingReferrer)->toString(); > > The append Origin algorithm is making use of response tainting == cors, which is different from the mode. > Probably we have some slight behavioural differences, or maybe we already set the origin header in the cases that matter. > Would be worth investigating. > > It would also be nice to add a routine that implements the whole https://fetch.spec.whatwg.org/#append-a-request-origin-header algorithm. > We have some bits here and there which makes it hard to know whether we are doing the right thing. > For instance HEAD/GET check is done in FrameLoader::addHTTPOriginIfNeeded, not here. > > All of this might best be done as follow-ups though, let's go with this patch. Yes, it is possible that cors taint vs mode has a slight behavior difference, will keep it in mind. I also agree that a central place for https://fetch.spec.whatwg.org/#append-a-request-origin-header is needed, addHTTPOriginIfNeeded seems the best candidate and I will keep working on it. Thanks for the reviews!
WebKit Commit Bot
Comment 16 2020-03-10 04:27:20 PDT
Comment on attachment 393073 [details] Patch Clearing flags on attachment: 393073 Committed r258194: <https://trac.webkit.org/changeset/258194>
WebKit Commit Bot
Comment 17 2020-03-10 04:27:22 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 18 2020-03-10 04:28:13 PDT
Note You need to log in before you can comment on or make changes to this bug.