| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "platform/weborigin/SecurityOrigin.h" | 44 #include "platform/weborigin/SecurityOrigin.h" |
| 45 #include "platform/wtf/text/StringBuilder.h" | 45 #include "platform/wtf/text/StringBuilder.h" |
| 46 #include "public/platform/WebAddressSpace.h" | 46 #include "public/platform/WebAddressSpace.h" |
| 47 #include "public/platform/WebInsecureRequestPolicy.h" | 47 #include "public/platform/WebInsecureRequestPolicy.h" |
| 48 #include "public/platform/WebMixedContent.h" | 48 #include "public/platform/WebMixedContent.h" |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 // When a frame is local, use its full URL to represent the main resource. When | 54 // This helper function is used to determine the URL to show for |mixed_frame| |
| 55 // the frame is remote, the full URL isn't accessible, so use the origin. This | 55 // in console messages about mixed content. |mixed_frame| is the frame with |
| 56 // function is used, for example, to determine the URL to show in console | 56 // respect to which content is mixed, and |frame| is the LocalFrame which is |
| 57 // messages about mixed content. | 57 // loading the resource that triggered mixed content. If the two frames are |
| 58 KURL MainResourceUrlForFrame(Frame* frame) { | 58 // different, use |mixed_frame|'s origin. This automatically handles the OOPIF |
| 59 if (frame->IsRemoteFrame()) { | 59 // cases where mixed_frame might be a RemoteFrame, and is done for consistency |
| 60 return KURL(KURL(), | 60 // even when |mixed_frame| is local. |
| 61 frame->GetSecurityContext()->GetSecurityOrigin()->ToString()); | 61 KURL MainResourceUrlForMixedFrame(Frame* mixed_frame, LocalFrame* frame) { |
| 62 if (mixed_frame != frame) { |
| 63 return KURL( |
| 64 KURL(), |
| 65 mixed_frame->GetSecurityContext()->GetSecurityOrigin()->ToString()); |
| 62 } | 66 } |
| 63 return ToLocalFrame(frame)->GetDocument()->Url(); | 67 return ToLocalFrame(mixed_frame)->GetDocument()->Url(); |
| 64 } | 68 } |
| 65 | 69 |
| 66 const char* RequestContextName(WebURLRequest::RequestContext context) { | 70 const char* RequestContextName(WebURLRequest::RequestContext context) { |
| 67 switch (context) { | 71 switch (context) { |
| 68 case WebURLRequest::kRequestContextAudio: | 72 case WebURLRequest::kRequestContextAudio: |
| 69 return "audio file"; | 73 return "audio file"; |
| 70 case WebURLRequest::kRequestContextBeacon: | 74 case WebURLRequest::kRequestContextBeacon: |
| 71 return "Beacon endpoint"; | 75 return "Beacon endpoint"; |
| 72 case WebURLRequest::kRequestContextCSPReport: | 76 case WebURLRequest::kRequestContextCSPReport: |
| 73 return "Content Security Policy reporting endpoint"; | 77 return "Content Security Policy reporting endpoint"; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 allowed = !strict_mode; | 405 allowed = !strict_mode; |
| 402 if (allowed) | 406 if (allowed) |
| 403 client->DidDisplayInsecureContent(); | 407 client->DidDisplayInsecureContent(); |
| 404 break; | 408 break; |
| 405 case WebMixedContentContextType::kNotMixedContent: | 409 case WebMixedContentContextType::kNotMixedContent: |
| 406 NOTREACHED(); | 410 NOTREACHED(); |
| 407 break; | 411 break; |
| 408 }; | 412 }; |
| 409 | 413 |
| 410 if (reporting_policy == SecurityViolationReportingPolicy::kReport) { | 414 if (reporting_policy == SecurityViolationReportingPolicy::kReport) { |
| 411 LogToConsoleAboutFetch(frame, MainResourceUrlForFrame(mixed_frame), url, | 415 LogToConsoleAboutFetch(frame, |
| 412 request_context, allowed, nullptr); | 416 MainResourceUrlForMixedFrame(mixed_frame, frame), |
| 417 url, request_context, allowed, nullptr); |
| 413 } | 418 } |
| 414 return !allowed; | 419 return !allowed; |
| 415 } | 420 } |
| 416 | 421 |
| 417 // static | 422 // static |
| 418 void MixedContentChecker::LogToConsoleAboutWebSocket( | 423 void MixedContentChecker::LogToConsoleAboutWebSocket( |
| 419 LocalFrame* frame, | 424 LocalFrame* frame, |
| 420 const KURL& main_resource_url, | 425 const KURL& main_resource_url, |
| 421 const KURL& url, | 426 const KURL& url, |
| 422 bool allowed) { | 427 bool allowed) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 bool allowed_per_settings = | 479 bool allowed_per_settings = |
| 475 settings && settings->GetAllowRunningOfInsecureContent(); | 480 settings && settings->GetAllowRunningOfInsecureContent(); |
| 476 allowed = content_settings_client->AllowRunningInsecureContent( | 481 allowed = content_settings_client->AllowRunningInsecureContent( |
| 477 allowed_per_settings, security_origin, url); | 482 allowed_per_settings, security_origin, url); |
| 478 } | 483 } |
| 479 | 484 |
| 480 if (allowed) | 485 if (allowed) |
| 481 client->DidRunInsecureContent(security_origin, url); | 486 client->DidRunInsecureContent(security_origin, url); |
| 482 | 487 |
| 483 if (reporting_policy == SecurityViolationReportingPolicy::kReport) { | 488 if (reporting_policy == SecurityViolationReportingPolicy::kReport) { |
| 484 LogToConsoleAboutWebSocket(frame, MainResourceUrlForFrame(mixed_frame), url, | 489 LogToConsoleAboutWebSocket( |
| 485 allowed); | 490 frame, MainResourceUrlForMixedFrame(mixed_frame, frame), url, allowed); |
| 486 } | 491 } |
| 487 return !allowed; | 492 return !allowed; |
| 488 } | 493 } |
| 489 | 494 |
| 490 bool MixedContentChecker::IsMixedFormAction( | 495 bool MixedContentChecker::IsMixedFormAction( |
| 491 LocalFrame* frame, | 496 LocalFrame* frame, |
| 492 const KURL& url, | 497 const KURL& url, |
| 493 SecurityViolationReportingPolicy reporting_policy) { | 498 SecurityViolationReportingPolicy reporting_policy) { |
| 494 // For whatever reason, some folks handle forms via JavaScript, and submit to | 499 // For whatever reason, some folks handle forms via JavaScript, and submit to |
| 495 // `javascript:void(0)` rather than calling `preventDefault()`. We | 500 // `javascript:void(0)` rather than calling `preventDefault()`. We |
| (...skipping 11 matching lines...) Expand all Loading... |
| 507 | 512 |
| 508 // Use the current local frame's client; the embedder doesn't distinguish | 513 // Use the current local frame's client; the embedder doesn't distinguish |
| 509 // mixed content signals from different frames on the same page. | 514 // mixed content signals from different frames on the same page. |
| 510 frame->Loader().Client()->DidContainInsecureFormAction(); | 515 frame->Loader().Client()->DidContainInsecureFormAction(); |
| 511 | 516 |
| 512 if (reporting_policy == SecurityViolationReportingPolicy::kReport) { | 517 if (reporting_policy == SecurityViolationReportingPolicy::kReport) { |
| 513 String message = String::Format( | 518 String message = String::Format( |
| 514 "Mixed Content: The page at '%s' was loaded over a secure connection, " | 519 "Mixed Content: The page at '%s' was loaded over a secure connection, " |
| 515 "but contains a form which targets an insecure endpoint '%s'. This " | 520 "but contains a form which targets an insecure endpoint '%s'. This " |
| 516 "endpoint should be made available over a secure connection.", | 521 "endpoint should be made available over a secure connection.", |
| 517 MainResourceUrlForFrame(mixed_frame).ElidedString().Utf8().data(), | 522 MainResourceUrlForMixedFrame(mixed_frame, frame) |
| 523 .ElidedString() |
| 524 .Utf8() |
| 525 .data(), |
| 518 url.ElidedString().Utf8().data()); | 526 url.ElidedString().Utf8().data()); |
| 519 frame->GetDocument()->AddConsoleMessage(ConsoleMessage::Create( | 527 frame->GetDocument()->AddConsoleMessage(ConsoleMessage::Create( |
| 520 kSecurityMessageSource, kWarningMessageLevel, message)); | 528 kSecurityMessageSource, kWarningMessageLevel, message)); |
| 521 } | 529 } |
| 522 | 530 |
| 523 return true; | 531 return true; |
| 524 } | 532 } |
| 525 | 533 |
| 526 void MixedContentChecker::CheckMixedPrivatePublic( | 534 void MixedContentChecker::CheckMixedPrivatePublic( |
| 527 LocalFrame* frame, | 535 LocalFrame* frame, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 } | 640 } |
| 633 | 641 |
| 634 bool strict_mixed_content_checking_for_plugin = | 642 bool strict_mixed_content_checking_for_plugin = |
| 635 mixed_frame->GetSettings() && | 643 mixed_frame->GetSettings() && |
| 636 mixed_frame->GetSettings()->GetStrictMixedContentCheckingForPlugin(); | 644 mixed_frame->GetSettings()->GetStrictMixedContentCheckingForPlugin(); |
| 637 return WebMixedContent::ContextTypeFromRequestContext( | 645 return WebMixedContent::ContextTypeFromRequestContext( |
| 638 request.GetRequestContext(), strict_mixed_content_checking_for_plugin); | 646 request.GetRequestContext(), strict_mixed_content_checking_for_plugin); |
| 639 } | 647 } |
| 640 | 648 |
| 641 } // namespace blink | 649 } // namespace blink |
| OLD | NEW |