Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Issue 2917133002: Perform redirect checks before OnReceivedRedirect in //net. (Closed)

Created:
3 years, 6 months ago by davidben
Modified:
3 years, 6 months ago
Reviewers:
mmenke1, mmenke, nasko, horo
CC:
chromium-reviews, yhirano
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Perform redirect checks before OnReceivedRedirect in //net. Right now, if URLRequest sees a redirect, it first signals OnReceivedRedirect, gives the caller a chance to reject the redirect and, if okay, it carries on to URLRequest::Redirect. URLRequest::Redirect then performs additional checks and potentially rejects the redirect. This ordering has two quirks: First, new_url.is_valid() is checked very late, but most consumers' checks presumably are going to check the URLs. This means that we reject invalid redirect URLs based not on //net code, but whatever consumer logic happens to notice. In //content, this is ChildProcessSecurityPolicyImpl, which interprets the renderer as trying to fetch somewhere questionable and just cancels the request. This results in an aborted request and no visible error, which is confusing, particularly for navigations. Second, URLRequest::Delegate gets called in an odd order. If we don't think request->url() should be allowed to redirect to new_url, whatever error we surface should be associated with request->url(), not new_url. That is, new_url did not misbehave necessarily. request->url() did for daring to utter such an obviously invalid URL. In particular, this is relevant for browser navigation logic, which needs to associate the error page with the right URL. If the error page is associate with new_url, reloading will skip the check, which is problematic. We do actually handle this properly. request->url() is not updated until later, but since Chrome is a complex multi-threaded multi-process IPC monster, the URLRequest is not immediate accessible. Instead, code likes to update the working URL when it receives OnReceivedRedirect. //net's current behavior is incompatible with this. In a normal redirect situation, we might signal: OnReceivedRedirect(new_url) // url() => old_url OnResponseStarted(net_error) // url() => new_url. But in this situation, we'll signal: OnReceivedRedirect(new_url) // url() => old_url OnResponseStarted(net_error) // url() => old_url! This is weird. This CL fixes this so it looks like: OnResponseStarted(net_error) // url() => old_url This means redirects to unparseable URLs simply fail with ERR_INVALID_REDIRECT (previously //net used ERR_INVALID_URL, but since the error page will commit at the old URL, ERR_INVALID_REDIRECT seems clearer). It also means that code which receives OnReceivedRedirect can eagerly update the URL, provided, of course, it orders it correctly with its own redirect checks. But the accept/reject signal may be propagated on-path, whereas a two-phase check (first consumer, then //net) requires potentially two round-trips. Unfortunately, this change does as a result require checking in newly failing test expectations for the redirect to data URL variant of issue #707185. Before this CL, whether we produced an opaque-redirect filtered response for an invalid redirect depended on whether the check happened in //net or outside. This now makes them treated similarly. Later, we can see about fixing both cases. (One thought is to teach //net about manual redirect mode, but this is subtle because //net persists info in the cache based on what it believes is and isn't a redirect. Another is to check the response object in OnResponseStarted and, if it's redirect-shaped, produce a filtered response wrapping an error response. This probably will involve adding a boolean to ResourceRequestCompletionStatus.) BUG=462272, 723796, 707185 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation Review-Url: https://codereview.chromium.org/2917133002 Cr-Commit-Position: refs/heads/master@{#477371} Committed: https://chromium.googlesource.com/chromium/src/+/d894710be3b56a15871376c5979615053dddcd70

Patch Set 1 #

Patch Set 2 : . #

Patch Set 3 : add an extra assertion #

Patch Set 4 : fix tests #

Patch Set 5 : fix test #

Patch Set 6 : test expectations #

Patch Set 7 : rebase #

Total comments: 5

Patch Set 8 : mmenke comments #

Total comments: 4

Patch Set 9 : nasko comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+182 lines, -42 lines) Patch
M chrome/browser/net/errorpage_browsertest.cc View 1 2 1 chunk +14 lines, -0 lines 0 comments Download
M components/error_page/common/localized_error.cc View 1 2 3 4 5 6 1 chunk +6 lines, -0 lines 0 comments Download
M content/browser/browser_side_navigation_browsertest.cc View 1 2 3 4 5 6 7 8 1 chunk +5 lines, -2 lines 0 comments Download
M content/browser/frame_host/data_url_navigation_browsertest.cc View 1 2 3 4 5 6 7 8 4 chunks +16 lines, -3 lines 0 comments Download
M content/browser/frame_host/navigation_controller_impl_browsertest.cc View 1 2 3 4 5 6 7 8 2 chunks +7 lines, -4 lines 0 comments Download
M content/browser/frame_host/navigation_handle_impl_browsertest.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M content/browser/service_worker/service_worker_browsertest.cc View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M net/base/net_error_list.h View 1 chunk +3 lines, -0 lines 0 comments Download
M net/url_request/url_request.h View 1 2 3 4 5 6 1 chunk +2 lines, -3 lines 0 comments Download
M net/url_request/url_request.cc View 1 2 3 4 5 6 3 chunks +6 lines, -16 lines 0 comments Download
M net/url_request/url_request_job.h View 1 2 3 4 5 6 7 2 chunks +6 lines, -1 line 0 comments Download
M net/url_request/url_request_job.cc View 1 2 3 4 5 6 7 3 chunks +31 lines, -10 lines 0 comments Download
M net/url_request/url_request_unittest.cc View 1 2 3 4 5 6 4 chunks +17 lines, -1 line 0 comments Download
A third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-location-expected.txt View 1 2 3 4 5 1 chunk +33 lines, -0 lines 0 comments Download
A third_party/WebKit/LayoutTests/external/wpt/fetch/api/redirect/redirect-location-worker-expected.txt View 1 2 3 4 5 1 chunk +33 lines, -0 lines 0 comments Download
M tools/metrics/histograms/enums.xml View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 52 (37 generated)
davidben
mmenke: For whether this is sound from a //net perspective. Directories to sign off on: ...
3 years, 6 months ago (2017-06-05 19:08:21 UTC) #26
davidben
On 2017/06/05 19:08:21, davidben wrote: > horo: For Fetch since I am sadly regressing the ...
3 years, 6 months ago (2017-06-05 19:10:03 UTC) #27
mmenke
https://codereview.chromium.org/2917133002/diff/120001/net/url_request/url_request_job.cc File net/url_request/url_request_job.cc (right): https://codereview.chromium.org/2917133002/diff/120001/net/url_request/url_request_job.cc#newcode468 net/url_request/url_request_job.cc:468: URLRequestStatus::FromError(redirect_valid)); Why not use OnDone()? https://codereview.chromium.org/2917133002/diff/120001/net/url_request/url_request_job.cc#newcode744 net/url_request/url_request_job.cc:744: if (!IsSafeRedirect(new_url)) ...
3 years, 6 months ago (2017-06-05 19:25:15 UTC) #28
davidben
https://codereview.chromium.org/2917133002/diff/120001/net/url_request/url_request_job.cc File net/url_request/url_request_job.cc (right): https://codereview.chromium.org/2917133002/diff/120001/net/url_request/url_request_job.cc#newcode468 net/url_request/url_request_job.cc:468: URLRequestStatus::FromError(redirect_valid)); On 2017/06/05 19:25:15, mmenke wrote: > Why not ...
3 years, 6 months ago (2017-06-05 19:44:17 UTC) #29
mmenke
Want to think about this a bit more tomorrow, but it seems fine. https://codereview.chromium.org/2917133002/diff/120001/net/url_request/url_request_job.cc File ...
3 years, 6 months ago (2017-06-05 19:52:01 UTC) #32
davidben
On 2017/06/05 19:52:01, mmenke wrote: > Want to think about this a bit more tomorrow, ...
3 years, 6 months ago (2017-06-05 19:54:21 UTC) #33
nasko
content/ LGTM. Thanks for getting this done! https://codereview.chromium.org/2917133002/diff/140001/content/browser/browser_side_navigation_browsertest.cc File content/browser/browser_side_navigation_browsertest.cc (right): https://codereview.chromium.org/2917133002/diff/140001/content/browser/browser_side_navigation_browsertest.cc#newcode425 content/browser/browser_side_navigation_browsertest.cc:425: // navigation ...
3 years, 6 months ago (2017-06-06 00:27:38 UTC) #36
horo
+CC: yhirano@ lgtm
3 years, 6 months ago (2017-06-06 06:49:50 UTC) #37
mmenke
On 2017/06/05 19:54:21, davidben wrote: > On 2017/06/05 19:52:01, mmenke wrote: > > Want to ...
3 years, 6 months ago (2017-06-06 15:59:18 UTC) #38
davidben
On 2017/06/06 15:59:18, mmenke wrote: > On 2017/06/05 19:54:21, davidben wrote: > > On 2017/06/05 ...
3 years, 6 months ago (2017-06-06 17:05:57 UTC) #39
davidben
https://codereview.chromium.org/2917133002/diff/140001/content/browser/browser_side_navigation_browsertest.cc File content/browser/browser_side_navigation_browsertest.cc (right): https://codereview.chromium.org/2917133002/diff/140001/content/browser/browser_side_navigation_browsertest.cc#newcode425 content/browser/browser_side_navigation_browsertest.cc:425: // navigation logic is no longer needed. On 2017/06/06 ...
3 years, 6 months ago (2017-06-06 17:31:09 UTC) #41
mmenke1
I'm good, either way. LGTM!
3 years, 6 months ago (2017-06-06 17:34:35 UTC) #43
mmenke
On 2017/06/06 17:34:35, mmenke_google.com wrote: > I'm good, either way. LGTM! LGTM from the right ...
3 years, 6 months ago (2017-06-06 17:45:03 UTC) #44
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2917133002/160001
3 years, 6 months ago (2017-06-06 17:51:26 UTC) #48
commit-bot: I haz the power
3 years, 6 months ago (2017-06-06 19:28:54 UTC) #52
Message was sent while issue was closed.
Committed patchset #9 (id:160001) as
https://chromium.googlesource.com/chromium/src/+/d894710be3b56a15871376c59796...

Powered by Google App Engine
This is Rietveld 408576698