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

Side by Side Diff: Source/core/html/parser/XSSAuditor.cpp

Issue 141143007: Revert of Revert "Moved text decoding to the parser thread" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 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 | « Source/core/html/parser/XSSAuditor.h ('k') | Source/core/html/track/vtt/VTTParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Adam Barth. All Rights Reserved. 2 * Copyright (C) 2011 Adam Barth. All Rights Reserved.
3 * Copyright (C) 2011 Daniel Bates (dbates@intudata.com). 3 * Copyright (C) 2011 Daniel Bates (dbates@intudata.com).
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/html/parser/XSSAuditor.h" 28 #include "core/html/parser/XSSAuditor.h"
29 29
30 #include "HTMLNames.h" 30 #include "HTMLNames.h"
31 #include "SVGNames.h" 31 #include "SVGNames.h"
32 #include "XLinkNames.h" 32 #include "XLinkNames.h"
33 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
34 #include "core/fetch/TextResourceDecoder.h"
35 #include "core/frame/ContentSecurityPolicy.h" 34 #include "core/frame/ContentSecurityPolicy.h"
36 #include "core/frame/Frame.h" 35 #include "core/frame/Frame.h"
37 #include "core/html/HTMLParamElement.h" 36 #include "core/html/HTMLParamElement.h"
38 #include "core/html/parser/HTMLDocumentParser.h" 37 #include "core/html/parser/HTMLDocumentParser.h"
39 #include "core/html/parser/HTMLParserIdioms.h" 38 #include "core/html/parser/HTMLParserIdioms.h"
39 #include "core/html/parser/TextResourceDecoder.h"
40 #include "core/html/parser/XSSAuditorDelegate.h" 40 #include "core/html/parser/XSSAuditorDelegate.h"
41 #include "core/loader/DocumentLoader.h" 41 #include "core/loader/DocumentLoader.h"
42 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
43 #include "platform/JSONValues.h" 43 #include "platform/JSONValues.h"
44 #include "platform/network/FormData.h" 44 #include "platform/network/FormData.h"
45 #include "platform/text/DecodeEscapeSequences.h" 45 #include "platform/text/DecodeEscapeSequences.h"
46 #include "wtf/MainThread.h" 46 #include "wtf/MainThread.h"
47 47
48 namespace { 48 namespace {
49 49
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ASSERT(isMainThread()); 220 ASSERT(isMainThread());
221 ASSERT(m_state == Uninitialized); 221 ASSERT(m_state == Uninitialized);
222 m_state = FilteringTokens; 222 m_state = FilteringTokens;
223 // When parsing a fragment, we don't enable the XSS auditor because it's 223 // When parsing a fragment, we don't enable the XSS auditor because it's
224 // too much overhead. 224 // too much overhead.
225 ASSERT(!m_isEnabled); 225 ASSERT(!m_isEnabled);
226 } 226 }
227 227
228 void XSSAuditor::init(Document* document, XSSAuditorDelegate* auditorDelegate) 228 void XSSAuditor::init(Document* document, XSSAuditorDelegate* auditorDelegate)
229 { 229 {
230 const size_t miniumLengthForSuffixTree = 512; // FIXME: Tune this parameter.
231 const int suffixTreeDepth = 5;
232
233 ASSERT(isMainThread()); 230 ASSERT(isMainThread());
234 if (m_state != Uninitialized) 231 if (m_state != Uninitialized)
235 return; 232 return;
236 m_state = FilteringTokens; 233 m_state = FilteringTokens;
237 234
238 if (Settings* settings = document->settings()) 235 if (Settings* settings = document->settings())
239 m_isEnabled = settings->xssAuditorEnabled(); 236 m_isEnabled = settings->xssAuditorEnabled();
240 237
241 if (!m_isEnabled) 238 if (!m_isEnabled)
242 return; 239 return;
(...skipping 14 matching lines...) Expand all
257 } 254 }
258 255
259 if (m_documentURL.protocolIsData()) { 256 if (m_documentURL.protocolIsData()) {
260 m_isEnabled = false; 257 m_isEnabled = false;
261 return; 258 return;
262 } 259 }
263 260
264 if (document->encoding().isValid()) 261 if (document->encoding().isValid())
265 m_encoding = document->encoding(); 262 m_encoding = document->encoding();
266 263
267 m_decodedURL = fullyDecodeString(m_documentURL.string(), m_encoding);
268 if (m_decodedURL.find(isRequiredForInjection) == kNotFound)
269 m_decodedURL = String();
270
271 String httpBodyAsString;
272 if (DocumentLoader* documentLoader = document->frame()->loader().documentLoa der()) { 264 if (DocumentLoader* documentLoader = document->frame()->loader().documentLoa der()) {
273 DEFINE_STATIC_LOCAL(const AtomicString, XSSProtectionHeader, ("X-XSS-Pro tection", AtomicString::ConstructFromLiteral)); 265 DEFINE_STATIC_LOCAL(const AtomicString, XSSProtectionHeader, ("X-XSS-Pro tection", AtomicString::ConstructFromLiteral));
274 const AtomicString& headerValue = documentLoader->response().httpHeaderF ield(XSSProtectionHeader); 266 const AtomicString& headerValue = documentLoader->response().httpHeaderF ield(XSSProtectionHeader);
275 String errorDetails; 267 String errorDetails;
276 unsigned errorPosition = 0; 268 unsigned errorPosition = 0;
277 String reportURL; 269 String reportURL;
278 KURL xssProtectionReportURL; 270 KURL xssProtectionReportURL;
279 271
280 // Process the X-XSS-Protection header, then mix in the CSP header's val ue. 272 // Process the X-XSS-Protection header, then mix in the CSP header's val ue.
281 ReflectedXSSDisposition xssProtectionHeader = parseXSSProtectionHeader(h eaderValue, errorDetails, errorPosition, reportURL); 273 ReflectedXSSDisposition xssProtectionHeader = parseXSSProtectionHeader(h eaderValue, errorDetails, errorPosition, reportURL);
282 m_didSendValidXSSProtectionHeader = xssProtectionHeader != ReflectedXSSU nset && xssProtectionHeader != ReflectedXSSInvalid; 274 m_didSendValidXSSProtectionHeader = xssProtectionHeader != ReflectedXSSU nset && xssProtectionHeader != ReflectedXSSInvalid;
283 if ((xssProtectionHeader == FilterReflectedXSS || xssProtectionHeader == BlockReflectedXSS) && !reportURL.isEmpty()) { 275 if ((xssProtectionHeader == FilterReflectedXSS || xssProtectionHeader == BlockReflectedXSS) && !reportURL.isEmpty()) {
284 xssProtectionReportURL = document->completeURL(reportURL); 276 xssProtectionReportURL = document->completeURL(reportURL);
285 if (MixedContentChecker::isMixedContent(document->securityOrigin(), xssProtectionReportURL)) { 277 if (MixedContentChecker::isMixedContent(document->securityOrigin(), xssProtectionReportURL)) {
286 errorDetails = "insecure reporting URL for secure page"; 278 errorDetails = "insecure reporting URL for secure page";
287 xssProtectionHeader = ReflectedXSSInvalid; 279 xssProtectionHeader = ReflectedXSSInvalid;
288 xssProtectionReportURL = KURL(); 280 xssProtectionReportURL = KURL();
289 } 281 }
290 } 282 }
291 if (xssProtectionHeader == ReflectedXSSInvalid) 283 if (xssProtectionHeader == ReflectedXSSInvalid)
292 document->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel , "Error parsing header X-XSS-Protection: " + headerValue + ": " + errorDetails + " at character position " + String::format("%u", errorPosition) + ". The defa ult protections will be applied."); 284 document->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel , "Error parsing header X-XSS-Protection: " + headerValue + ": " + errorDetails + " at character position " + String::format("%u", errorPosition) + ". The defa ult protections will be applied.");
293 285
294 ReflectedXSSDisposition cspHeader = document->contentSecurityPolicy()->r eflectedXSSDisposition(); 286 ReflectedXSSDisposition cspHeader = document->contentSecurityPolicy()->r eflectedXSSDisposition();
295 m_didSendValidCSPHeader = cspHeader != ReflectedXSSUnset && cspHeader != ReflectedXSSInvalid; 287 m_didSendValidCSPHeader = cspHeader != ReflectedXSSUnset && cspHeader != ReflectedXSSInvalid;
296 288
297 m_xssProtection = combineXSSProtectionHeaderAndCSP(xssProtectionHeader, cspHeader); 289 m_xssProtection = combineXSSProtectionHeaderAndCSP(xssProtectionHeader, cspHeader);
298 // FIXME: Combine the two report URLs in some reasonable way. 290 // FIXME: Combine the two report URLs in some reasonable way.
299 if (auditorDelegate) 291 if (auditorDelegate)
300 auditorDelegate->setReportURL(xssProtectionReportURL.copy()); 292 auditorDelegate->setReportURL(xssProtectionReportURL.copy());
293
301 FormData* httpBody = documentLoader->request().httpBody(); 294 FormData* httpBody = documentLoader->request().httpBody();
302 if (httpBody && !httpBody->isEmpty()) { 295 if (httpBody && !httpBody->isEmpty())
303 httpBodyAsString = httpBody->flattenToString(); 296 m_httpBodyAsString = httpBody->flattenToString();
304 if (!httpBodyAsString.isEmpty()) {
305 m_decodedHTTPBody = fullyDecodeString(httpBodyAsString, m_encodi ng);
306 if (m_decodedHTTPBody.find(isRequiredForInjection) == kNotFound)
307 m_decodedHTTPBody = String();
308 if (m_decodedHTTPBody.length() >= miniumLengthForSuffixTree)
309 m_decodedHTTPBodySuffixTree = adoptPtr(new SuffixTree<ASCIIC odebook>(m_decodedHTTPBody, suffixTreeDepth));
310 }
311 }
312 } 297 }
313 298
314 if (m_decodedURL.isEmpty() && m_decodedHTTPBody.isEmpty()) { 299 setEncoding(m_encoding);
300 }
301
302 void XSSAuditor::setEncoding(const WTF::TextEncoding& encoding)
303 {
304 const size_t miniumLengthForSuffixTree = 512; // FIXME: Tune this parameter.
305 const int suffixTreeDepth = 5;
306
307 if (!encoding.isValid())
308 return;
309
310 m_encoding = encoding;
311
312 m_decodedURL = fullyDecodeString(m_documentURL.string(), m_encoding);
313 if (m_decodedURL.find(isRequiredForInjection) == kNotFound)
314 m_decodedURL = String();
315
316 if (!m_httpBodyAsString.isEmpty()) {
317 m_decodedHTTPBody = fullyDecodeString(m_httpBodyAsString, m_encoding);
318 m_httpBodyAsString = String();
319 if (m_decodedHTTPBody.find(isRequiredForInjection) == kNotFound)
320 m_decodedHTTPBody = String();
321 if (m_decodedHTTPBody.length() >= miniumLengthForSuffixTree)
322 m_decodedHTTPBodySuffixTree = adoptPtr(new SuffixTree<ASCIICodeb ook>(m_decodedHTTPBody, suffixTreeDepth));
323 }
324
325 if (m_decodedURL.isEmpty() && m_decodedHTTPBody.isEmpty())
315 m_isEnabled = false; 326 m_isEnabled = false;
316 return;
317 }
318 } 327 }
319 328
320 PassOwnPtr<XSSInfo> XSSAuditor::filterToken(const FilterTokenRequest& request) 329 PassOwnPtr<XSSInfo> XSSAuditor::filterToken(const FilterTokenRequest& request)
321 { 330 {
322 ASSERT(m_state != Uninitialized); 331 ASSERT(m_state != Uninitialized);
323 if (!m_isEnabled || m_xssProtection == AllowReflectedXSS) 332 if (!m_isEnabled || m_xssProtection == AllowReflectedXSS)
324 return nullptr; 333 return nullptr;
325 334
326 bool didBlockScript = false; 335 bool didBlockScript = false;
327 if (request.token.type() == HTMLToken::StartTag) 336 if (request.token.type() == HTMLToken::StartTag)
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 return false; 734 return false;
726 735
727 KURL resourceURL(m_documentURL, url); 736 KURL resourceURL(m_documentURL, url);
728 return (m_documentURL.host() == resourceURL.host() && resourceURL.query().is Empty()); 737 return (m_documentURL.host() == resourceURL.host() && resourceURL.query().is Empty());
729 } 738 }
730 739
731 bool XSSAuditor::isSafeToSendToAnotherThread() const 740 bool XSSAuditor::isSafeToSendToAnotherThread() const
732 { 741 {
733 return m_documentURL.isSafeToSendToAnotherThread() 742 return m_documentURL.isSafeToSendToAnotherThread()
734 && m_decodedURL.isSafeToSendToAnotherThread() 743 && m_decodedURL.isSafeToSendToAnotherThread()
735 && m_decodedHTTPBody.isSafeToSendToAnotherThread(); 744 && m_decodedHTTPBody.isSafeToSendToAnotherThread()
745 && m_httpBodyAsString.isSafeToSendToAnotherThread();
736 } 746 }
737 747
738 } // namespace WebCore 748 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/parser/XSSAuditor.h ('k') | Source/core/html/track/vtt/VTTParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698