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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2196983002: Allow doc.written scripts with a matching domain and registry to execute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 4 years, 4 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "core/loader/ProgressTracker.h" 57 #include "core/loader/ProgressTracker.h"
58 #include "core/loader/appcache/ApplicationCacheHost.h" 58 #include "core/loader/appcache/ApplicationCacheHost.h"
59 #include "core/page/NetworkStateNotifier.h" 59 #include "core/page/NetworkStateNotifier.h"
60 #include "core/page/Page.h" 60 #include "core/page/Page.h"
61 #include "core/svg/graphics/SVGImageChromeClient.h" 61 #include "core/svg/graphics/SVGImageChromeClient.h"
62 #include "core/timing/DOMWindowPerformance.h" 62 #include "core/timing/DOMWindowPerformance.h"
63 #include "core/timing/Performance.h" 63 #include "core/timing/Performance.h"
64 #include "platform/Logging.h" 64 #include "platform/Logging.h"
65 #include "platform/TracedValue.h" 65 #include "platform/TracedValue.h"
66 #include "platform/mhtml/MHTMLArchive.h" 66 #include "platform/mhtml/MHTMLArchive.h"
67 #include "platform/network/NetworkUtils.h"
67 #include "platform/network/ResourceLoadPriority.h" 68 #include "platform/network/ResourceLoadPriority.h"
68 #include "platform/network/ResourceTimingInfo.h" 69 #include "platform/network/ResourceTimingInfo.h"
69 #include "platform/weborigin/SchemeRegistry.h" 70 #include "platform/weborigin/SchemeRegistry.h"
70 #include "platform/weborigin/SecurityPolicy.h" 71 #include "platform/weborigin/SecurityPolicy.h"
71 #include "public/platform/WebCachePolicy.h" 72 #include "public/platform/WebCachePolicy.h"
72 #include "public/platform/WebDocumentSubresourceFilter.h" 73 #include "public/platform/WebDocumentSubresourceFilter.h"
73 #include "public/platform/WebFrameScheduler.h" 74 #include "public/platform/WebFrameScheduler.h"
74 #include "public/platform/WebInsecureRequestPolicy.h" 75 #include "public/platform/WebInsecureRequestPolicy.h"
75 #include "public/platform/WebViewScheduler.h" 76 #include "public/platform/WebViewScheduler.h"
76 #include <algorithm> 77 #include <algorithm>
(...skipping 26 matching lines...) Expand all
103 // Only block synchronously loaded (parser blocking) scripts. 104 // Only block synchronously loaded (parser blocking) scripts.
104 if (defer != FetchRequest::NoDefer) 105 if (defer != FetchRequest::NoDefer)
105 return false; 106 return false;
106 107
107 if (!request.url().protocolIsInHTTPFamily()) 108 if (!request.url().protocolIsInHTTPFamily())
108 return false; 109 return false;
109 110
110 // Avoid blocking same origin scripts, as they may be used to render main 111 // Avoid blocking same origin scripts, as they may be used to render main
111 // page content, whereas cross-origin scripts inserted via document.write 112 // page content, whereas cross-origin scripts inserted via document.write
112 // are likely to be third party content. 113 // are likely to be third party content.
113 if (request.url().host() == document.getSecurityOrigin()->domain()) 114 String requestHost = request.url().host();
115 String documentHost = document.getSecurityOrigin()->domain();
116 if (requestHost == documentHost)
117 return false;
118
119 // If the hosts didn't match, then see if the domains match. For example, if
120 // a script is served from static.example.com for a document served from
121 // www.example.com, we consider that a first party script and allow it.
122 String requestDomain = NetworkUtils::getDomainAndRegistry(requestHost, true) ;
123 String documentDomain = NetworkUtils::getDomainAndRegistry(documentHost, tru e);
124 if (!requestDomain.isEmpty() && !documentDomain.isEmpty() && requestDomain = = documentDomain)
Nate Chapin 2016/08/03 21:44:09 Nit: we don't need to call isEmpty() for both stri
Bryan McQuade 2016/08/03 22:05:45 Ah, getDomainAndRegistry can return empty string i
114 return false; 125 return false;
115 126
116 emitWarningForDocWriteScripts(request.url().getString(), document); 127 emitWarningForDocWriteScripts(request.url().getString(), document);
117 128
118 // Do not block scripts if it is a page reload. This is to enable pages to 129 // Do not block scripts if it is a page reload. This is to enable pages to
119 // recover if blocking of a script is leading to a page break and the user 130 // recover if blocking of a script is leading to a page break and the user
120 // reloads the page. 131 // reloads the page.
121 const FrameLoadType loadType = document.frame()->loader().loadType(); 132 const FrameLoadType loadType = document.frame()->loader().loadType();
122 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource; 133 const bool isReload = loadType == FrameLoadTypeReload || loadType == FrameLo adTypeReloadBypassingCache || loadType == FrameLoadTypeReloadMainResource;
123 if (isReload) { 134 if (isReload) {
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 } 823 }
813 824
814 DEFINE_TRACE(FrameFetchContext) 825 DEFINE_TRACE(FrameFetchContext)
815 { 826 {
816 visitor->trace(m_document); 827 visitor->trace(m_document);
817 visitor->trace(m_documentLoader); 828 visitor->trace(m_documentLoader);
818 FetchContext::trace(visitor); 829 FetchContext::trace(visitor);
819 } 830 }
820 831
821 } // namespace blink 832 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698