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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/FetchRespondWithObserver.cpp

Issue 2755643004: [ServiceWorker] Introduce the new security restriction of redirected response. (Closed)
Patch Set: change comment Created 3 years, 9 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/fetch-request-redirect-iframe.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "modules/serviceworkers/FetchRespondWithObserver.h" 5 #include "modules/serviceworkers/FetchRespondWithObserver.h"
6 6
7 #include <v8.h> 7 #include <v8.h>
8 #include "bindings/core/v8/ScriptValue.h" 8 #include "bindings/core/v8/ScriptValue.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/modules/v8/V8Response.h" 10 #include "bindings/modules/v8/V8Response.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 "redirect mode is not \"follow\"."; 92 "redirect mode is not \"follow\".";
93 break; 93 break;
94 case WebServiceWorkerResponseErrorUnknown: 94 case WebServiceWorkerResponseErrorUnknown:
95 default: 95 default:
96 errorMessage = errorMessage + "an unexpected error occurred."; 96 errorMessage = errorMessage + "an unexpected error occurred.";
97 break; 97 break;
98 } 98 }
99 return errorMessage; 99 return errorMessage;
100 } 100 }
101 101
102 const String getErrorMessageForRedirectedResponseForNavigationRequest(
103 const KURL& requestURL,
104 const Vector<KURL>& responseURLList) {
105 String errorMessage =
106 "In Chrome 59, the navigation to \"" + requestURL.getString() + "\" " +
107 "will result in a network error, because FetchEvent.respondWith() was " +
108 "called with a redirected response. See https://crbug.com/658249. The " +
109 "url list of the response was: [\"" + responseURLList[0].getString() +
110 "\"";
111 for (size_t i = 1; i < responseURLList.size(); ++i) {
112 errorMessage =
113 errorMessage + ", \"" + responseURLList[i].getString() + "\"";
114 }
115 return errorMessage + "]";
116 }
117
118 bool isNavigationRequest(WebURLRequest::FrameType frameType) { 102 bool isNavigationRequest(WebURLRequest::FrameType frameType) {
119 return frameType != WebURLRequest::FrameTypeNone; 103 return frameType != WebURLRequest::FrameTypeNone;
120 } 104 }
121 105
122 bool isClientRequest(WebURLRequest::FrameType frameType, 106 bool isClientRequest(WebURLRequest::FrameType frameType,
123 WebURLRequest::RequestContext requestContext) { 107 WebURLRequest::RequestContext requestContext) {
124 return isNavigationRequest(frameType) || 108 return isNavigationRequest(frameType) ||
125 requestContext == WebURLRequest::RequestContextSharedWorker || 109 requestContext == WebURLRequest::RequestContextSharedWorker ||
126 requestContext == WebURLRequest::RequestContextWorker; 110 requestContext == WebURLRequest::RequestContextWorker;
127 } 111 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return; 190 return;
207 } 191 }
208 } 192 }
209 if (m_redirectMode != WebURLRequest::FetchRedirectModeManual && 193 if (m_redirectMode != WebURLRequest::FetchRedirectModeManual &&
210 responseType == FetchResponseData::OpaqueRedirectType) { 194 responseType == FetchResponseData::OpaqueRedirectType) {
211 onResponseRejected(WebServiceWorkerResponseErrorResponseTypeOpaqueRedirect); 195 onResponseRejected(WebServiceWorkerResponseErrorResponseTypeOpaqueRedirect);
212 return; 196 return;
213 } 197 }
214 if (m_redirectMode != WebURLRequest::FetchRedirectModeFollow && 198 if (m_redirectMode != WebURLRequest::FetchRedirectModeFollow &&
215 response->redirected()) { 199 response->redirected()) {
216 if (!isNavigationRequest(m_frameType)) { 200 onResponseRejected(
217 onResponseRejected( 201 WebServiceWorkerResponseErrorRedirectedResponseForNotFollowRequest);
218 WebServiceWorkerResponseErrorRedirectedResponseForNotFollowRequest); 202 return;
219 return;
220 }
221 // TODO(horo): We should just reject even if the request was a navigation.
222 // Currently we measure the impact of the restriction with the use counter
223 // in DocumentLoader.
224 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(
225 JSMessageSource, ErrorMessageLevel,
226 getErrorMessageForRedirectedResponseForNavigationRequest(
227 m_requestURL, response->internalURLList())));
228 } 203 }
229 if (response->isBodyLocked()) { 204 if (response->isBodyLocked()) {
230 onResponseRejected(WebServiceWorkerResponseErrorBodyLocked); 205 onResponseRejected(WebServiceWorkerResponseErrorBodyLocked);
231 return; 206 return;
232 } 207 }
233 if (response->bodyUsed()) { 208 if (response->bodyUsed()) {
234 onResponseRejected(WebServiceWorkerResponseErrorBodyUsed); 209 onResponseRejected(WebServiceWorkerResponseErrorBodyUsed);
235 return; 210 return;
236 } 211 }
237 212
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 m_requestMode(requestMode), 248 m_requestMode(requestMode),
274 m_redirectMode(redirectMode), 249 m_redirectMode(redirectMode),
275 m_frameType(frameType), 250 m_frameType(frameType),
276 m_requestContext(requestContext) {} 251 m_requestContext(requestContext) {}
277 252
278 DEFINE_TRACE(FetchRespondWithObserver) { 253 DEFINE_TRACE(FetchRespondWithObserver) {
279 RespondWithObserver::trace(visitor); 254 RespondWithObserver::trace(visitor);
280 } 255 }
281 256
282 } // namespace blink 257 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/fetch-request-redirect-iframe.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698