Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. |
| 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 ASSERT(element); | 326 ASSERT(element); |
| 327 return isHTMLScriptElement(*element); | 327 return isHTMLScriptElement(*element); |
| 328 } | 328 } |
| 329 | 329 |
| 330 bool isSVGScriptLoader(Element* element) | 330 bool isSVGScriptLoader(Element* element) |
| 331 { | 331 { |
| 332 ASSERT(element); | 332 ASSERT(element); |
| 333 return isSVGScriptElement(*element); | 333 return isSVGScriptElement(*element); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void ScriptLoader::logScriptMimetype(ScriptResource* resource, LocalFrame* frame , String mimetype) | |
| 337 { | |
| 338 bool text = mimetype.lower().startsWith("text/"); | |
| 339 bool application = mimetype.lower().startsWith("application/"); | |
| 340 bool expectedJs = MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimetype) || (text && isLegacySupportedJavaScriptLanguage(mimetype.substring(5))); | |
| 341 bool sameOrigin = m_element->document().securityOrigin()->canRequest(m_resou rce->url()); | |
| 342 if (!expectedJs) { | |
|
Nate Chapin
2015/12/03 17:53:32
Early exit is probably more readable than the rema
Dan Ehrenberg
2015/12/04 19:28:53
Done
| |
| 343 UseCounter::Feature feature = sameOrigin ? (text ? UseCounter::SameOrigi nTextScript : application ? UseCounter::SameOriginApplicationScript : UseCounter ::SameOriginOtherScript) : (text ? UseCounter::CrossOriginTextScript : applicati on ? UseCounter::CrossOriginApplicationScript : UseCounter::CrossOriginOtherScri pt); | |
|
Nate Chapin
2015/12/03 17:53:32
This is a bit much for 1 line, even by WebKit-styl
Dan Ehrenberg
2015/12/04 19:28:53
Well, I'd love to, but this is what git cl format
| |
| 344 UseCounter::count(frame, feature); | |
| 345 } | |
| 346 } | |
| 347 | |
| 336 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com pilationFinishTime) | 348 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com pilationFinishTime) |
| 337 { | 349 { |
| 338 ASSERT(m_alreadyStarted); | 350 ASSERT(m_alreadyStarted); |
| 339 | 351 |
| 340 if (sourceCode.isEmpty()) | 352 if (sourceCode.isEmpty()) |
| 341 return true; | 353 return true; |
| 342 | 354 |
| 343 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document()); | 355 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document()); |
| 344 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum ent().get(); | 356 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum ent().get(); |
| 345 if (!contextDocument) | 357 if (!contextDocument) |
| 346 return true; | 358 return true; |
| 347 | 359 |
| 348 LocalFrame* frame = contextDocument->frame(); | 360 LocalFrame* frame = contextDocument->frame(); |
| 349 | 361 |
| 350 const ContentSecurityPolicy* csp = elementDocument->contentSecurityPolicy(); | 362 const ContentSecurityPolicy* csp = elementDocument->contentSecurityPolicy(); |
| 351 bool shouldBypassMainWorldCSP = (frame && frame->script().shouldBypassMainWo rldCSP()) | 363 bool shouldBypassMainWorldCSP = (frame && frame->script().shouldBypassMainWo rldCSP()) |
| 352 || csp->allowScriptWithNonce(m_element->fastGetAttribute(HTMLNames::nonc eAttr)) | 364 || csp->allowScriptWithNonce(m_element->fastGetAttribute(HTMLNames::nonc eAttr)) |
| 353 || csp->allowScriptWithHash(sourceCode.source()); | 365 || csp->allowScriptWithHash(sourceCode.source()); |
| 354 | 366 |
| 355 if (!m_isExternalScript && (!shouldBypassMainWorldCSP && !csp->allowInlineSc ript(elementDocument->url(), m_startLineNumber, sourceCode.source()))) { | 367 if (!m_isExternalScript && (!shouldBypassMainWorldCSP && !csp->allowInlineSc ript(elementDocument->url(), m_startLineNumber, sourceCode.source()))) { |
| 356 return false; | 368 return false; |
| 357 } | 369 } |
| 358 | 370 |
| 359 if (m_isExternalScript) { | 371 if (m_isExternalScript) { |
| 360 ScriptResource* resource = m_resource ? m_resource.get() : sourceCode.re source(); | 372 ScriptResource* resource = m_resource ? m_resource.get() : sourceCode.re source(); |
| 361 if (resource && !resource->mimeTypeAllowedByNosniff()) { | 373 if (resource) { |
| 362 contextDocument->addConsoleMessage(ConsoleMessage::create(SecurityMe ssageSource, ErrorMessageLevel, "Refused to execute script from '" + resource->u rl().elidedString() + "' because its MIME type ('" + resource->mimeType() + "') is not executable, and strict MIME type checking is enabled.")); | 374 if (!resource->mimeTypeAllowedByNosniff()) { |
| 363 return false; | 375 contextDocument->addConsoleMessage(ConsoleMessage::create(Securi tyMessageSource, ErrorMessageLevel, "Refused to execute script from '" + resourc e->url().elidedString() + "' because its MIME type ('" + resource->mimeType() + "') is not executable, and strict MIME type checking is enabled.")); |
| 364 } | 376 return false; |
| 377 } | |
| 365 | 378 |
| 366 if (resource && resource->mimeType().lower().startsWith("image/")) { | 379 String mimetype = resource->mimeType(); |
| 367 contextDocument->addConsoleMessage(ConsoleMessage::create(SecurityMe ssageSource, ErrorMessageLevel, "Refused to execute script from '" + resource->u rl().elidedString() + "' because its MIME type ('" + resource->mimeType() + "') is not executable.")); | 380 if (mimetype.lower().startsWith("image/")) { |
| 368 UseCounter::count(frame, UseCounter::BlockedSniffingImageToScript); | 381 contextDocument->addConsoleMessage(ConsoleMessage::create(Securi tyMessageSource, ErrorMessageLevel, "Refused to execute script from '" + resourc e->url().elidedString() + "' because its MIME type ('" + resource->mimeType() + "') is not executable.")); |
| 369 return false; | 382 UseCounter::count(frame, UseCounter::BlockedSniffingImageToScrip t); |
| 383 return false; | |
| 384 } | |
| 385 | |
| 386 logScriptMimetype(resource, frame, mimetype); | |
| 370 } | 387 } |
| 371 } | 388 } |
| 372 | 389 |
| 373 // FIXME: Can this be moved earlier in the function? | 390 // FIXME: Can this be moved earlier in the function? |
| 374 // Why are we ever attempting to execute scripts without a frame? | 391 // Why are we ever attempting to execute scripts without a frame? |
| 375 if (!frame) | 392 if (!frame) |
| 376 return true; | 393 return true; |
| 377 | 394 |
| 378 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; | 395 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; |
| 379 if (!m_isExternalScript) { | 396 if (!m_isExternalScript) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 if (isHTMLScriptLoader(element)) | 517 if (isHTMLScriptLoader(element)) |
| 501 return toHTMLScriptElement(element)->loader(); | 518 return toHTMLScriptElement(element)->loader(); |
| 502 | 519 |
| 503 if (isSVGScriptLoader(element)) | 520 if (isSVGScriptLoader(element)) |
| 504 return toSVGScriptElement(element)->loader(); | 521 return toSVGScriptElement(element)->loader(); |
| 505 | 522 |
| 506 return 0; | 523 return 0; |
| 507 } | 524 } |
| 508 | 525 |
| 509 } // namespace blink | 526 } // namespace blink |
| OLD | NEW |