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

Side by Side Diff: net/url_request/sdch_dictionary_fetcher.cc

Issue 1880283002: Disallow redirects in SDCH dictionary fetches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge to p388233. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/url_request/sdch_dictionary_fetcher.h" 5 #include "net/url_request/sdch_dictionary_fetcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 10
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
18 #include "net/base/sdch_net_log_params.h" 18 #include "net/base/sdch_net_log_params.h"
19 #include "net/http/http_response_headers.h" 19 #include "net/http/http_response_headers.h"
20 #include "net/log/net_log.h" 20 #include "net/log/net_log.h"
21 #include "net/url_request/redirect_info.h"
21 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
23 #include "net/url_request/url_request_throttler_manager.h" 24 #include "net/url_request/url_request_throttler_manager.h"
24 25
25 namespace net { 26 namespace net {
26 27
27 namespace { 28 namespace {
28 29
29 const int kBufferSize = 4096; 30 const int kBufferSize = 4096;
30 31
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 void SdchDictionaryFetcher::Cancel() { 138 void SdchDictionaryFetcher::Cancel() {
138 DCHECK(CalledOnValidThread()); 139 DCHECK(CalledOnValidThread());
139 140
140 ResetRequest(); 141 ResetRequest();
141 next_state_ = STATE_NONE; 142 next_state_ = STATE_NONE;
142 143
143 fetch_queue_->Clear(); 144 fetch_queue_->Clear();
144 } 145 }
145 146
147 void SdchDictionaryFetcher::OnReceivedRedirect(
148 URLRequest* request,
149 const RedirectInfo& redirect_info,
150 bool* defer_redirect) {
151 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING);
152
153 next_state_ = STATE_RECEIVED_REDIRECT;
154
155 DoLoop(OK);
156 }
157
146 void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request) { 158 void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request) {
147 DCHECK(CalledOnValidThread()); 159 DCHECK(CalledOnValidThread());
148 DCHECK_EQ(request, current_request_.get()); 160 DCHECK_EQ(request, current_request_.get());
149 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); 161 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING);
150 DCHECK(!in_loop_); 162 DCHECK(!in_loop_);
151 163
152 // Confirm that the response isn't a stale read from the cache (as 164 // Confirm that the response isn't a stale read from the cache (as
153 // may happen in the reload case). If the response was not retrieved over 165 // may happen in the reload case). If the response was not retrieved over
154 // HTTP, it is presumed to be fresh. 166 // HTTP, it is presumed to be fresh.
155 HttpResponseHeaders* response_headers = request->response_headers(); 167 HttpResponseHeaders* response_headers = request->response_headers();
156 int result = request->status().error(); 168 int result = request->status().error();
157 if (result == OK && response_headers) { 169 if (result == OK && response_headers) {
158 ValidationType validation_type = response_headers->RequiresValidation( 170 ValidationType validation_type = response_headers->RequiresValidation(
159 request->response_info().request_time, 171 request->response_info().request_time,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 DCHECK(!in_loop_); 233 DCHECK(!in_loop_);
222 base::AutoReset<bool> auto_reset_in_loop(&in_loop_, true); 234 base::AutoReset<bool> auto_reset_in_loop(&in_loop_, true);
223 235
224 do { 236 do {
225 State state = next_state_; 237 State state = next_state_;
226 next_state_ = STATE_NONE; 238 next_state_ = STATE_NONE;
227 switch (state) { 239 switch (state) {
228 case STATE_SEND_REQUEST: 240 case STATE_SEND_REQUEST:
229 rv = DoSendRequest(rv); 241 rv = DoSendRequest(rv);
230 break; 242 break;
231 case STATE_SEND_REQUEST_COMPLETE: 243 case STATE_RECEIVED_REDIRECT:
232 rv = DoSendRequestComplete(rv); 244 rv = DoReceivedRedirect(rv);
245 break;
246 case STATE_SEND_REQUEST_PENDING:
247 rv = DoSendRequestPending(rv);
233 break; 248 break;
234 case STATE_READ_BODY: 249 case STATE_READ_BODY:
235 rv = DoReadBody(rv); 250 rv = DoReadBody(rv);
236 break; 251 break;
237 case STATE_READ_BODY_COMPLETE: 252 case STATE_READ_BODY_COMPLETE:
238 rv = DoReadBodyComplete(rv); 253 rv = DoReadBodyComplete(rv);
239 break; 254 break;
240 case STATE_REQUEST_COMPLETE: 255 case STATE_REQUEST_COMPLETE:
241 rv = DoCompleteRequest(rv); 256 rv = DoCompleteRequest(rv);
242 break; 257 break;
243 case STATE_NONE: 258 case STATE_NONE:
244 NOTREACHED(); 259 NOTREACHED();
245 } 260 }
246 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 261 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
247 262
248 return rv; 263 return rv;
249 } 264 }
250 265
251 int SdchDictionaryFetcher::DoSendRequest(int rv) { 266 int SdchDictionaryFetcher::DoSendRequest(int rv) {
252 DCHECK(CalledOnValidThread()); 267 DCHECK(CalledOnValidThread());
253 268
254 // |rv| is ignored, as the result from the previous request doesn't 269 // |rv| is ignored, as the result from the previous request doesn't
255 // affect the next request. 270 // affect the next request.
256 271
257 if (fetch_queue_->IsEmpty() || current_request_.get()) { 272 if (fetch_queue_->IsEmpty() || current_request_.get()) {
258 next_state_ = STATE_NONE; 273 next_state_ = STATE_NONE;
259 return OK; 274 return OK;
260 } 275 }
261 276
262 next_state_ = STATE_SEND_REQUEST_COMPLETE; 277 next_state_ = STATE_SEND_REQUEST_PENDING;
263 278
264 FetchInfo info; 279 FetchInfo info;
265 bool success = fetch_queue_->Pop(&info); 280 bool success = fetch_queue_->Pop(&info);
266 DCHECK(success); 281 DCHECK(success);
267 current_request_ = context_->CreateRequest(info.url, IDLE, this); 282 current_request_ = context_->CreateRequest(info.url, IDLE, this);
268 int load_flags = LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; 283 int load_flags = LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES;
269 if (info.cache_only) 284 if (info.cache_only)
270 load_flags |= LOAD_ONLY_FROM_CACHE; 285 load_flags |= LOAD_ONLY_FROM_CACHE;
271 current_request_->SetLoadFlags(load_flags); 286 current_request_->SetLoadFlags(load_flags);
272 287
273 buffer_ = new IOBuffer(kBufferSize); 288 buffer_ = new IOBuffer(kBufferSize);
274 current_callback_ = info.callback; 289 current_callback_ = info.callback;
275 290
276 current_request_->Start(); 291 current_request_->Start();
277 current_request_->net_log().AddEvent(NetLog::TYPE_SDCH_DICTIONARY_FETCH); 292 current_request_->net_log().AddEvent(NetLog::TYPE_SDCH_DICTIONARY_FETCH);
278 293
279 return ERR_IO_PENDING; 294 return ERR_IO_PENDING;
280 } 295 }
281 296
282 int SdchDictionaryFetcher::DoSendRequestComplete(int rv) { 297 int SdchDictionaryFetcher::DoReceivedRedirect(int rv) {
298 // Fetching SDCH through a redirect is forbidden; it raises possible
299 // security issues cross-origin, and isn't obviously useful within
300 // an origin.
301 ResetRequest();
302 next_state_ = STATE_SEND_REQUEST;
303 return ERR_UNSAFE_REDIRECT;
304 }
305
306 int SdchDictionaryFetcher::DoSendRequestPending(int rv) {
283 DCHECK(CalledOnValidThread()); 307 DCHECK(CalledOnValidThread());
284 308
285 // If there's been an error, abort the current request. 309 // If there's been an error, abort the current request.
286 if (rv != OK) { 310 if (rv != OK) {
287 current_request_.reset(); 311 current_request_.reset();
288 buffer_ = NULL; 312 buffer_ = NULL;
289 next_state_ = STATE_SEND_REQUEST; 313 next_state_ = STATE_SEND_REQUEST;
290 314
291 return OK; 315 return OK;
292 } 316 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 current_request_->net_log(), 372 current_request_->net_log(),
349 current_request_->was_cached()); 373 current_request_->was_cached());
350 } 374 }
351 375
352 ResetRequest(); 376 ResetRequest();
353 next_state_ = STATE_SEND_REQUEST; 377 next_state_ = STATE_SEND_REQUEST;
354 return OK; 378 return OK;
355 } 379 }
356 380
357 } // namespace net 381 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/sdch_dictionary_fetcher.h ('k') | net/url_request/sdch_dictionary_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698