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

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

Issue 2896833002: Added validation of the policy specified in the 'csp' attribute (Closed)
Patch Set: Fixed incomplete validation. Added more tests inspired by existing source parsing tests. Created 3 years, 6 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) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
10 * Copyright (C) 2011 Google Inc. All rights reserved. 10 * Copyright (C) 2011 Google Inc. All rights reserved.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/events/KeyboardEvent.h" 48 #include "core/events/KeyboardEvent.h"
49 #include "core/events/MouseEvent.h" 49 #include "core/events/MouseEvent.h"
50 #include "core/events/PageTransitionEvent.h" 50 #include "core/events/PageTransitionEvent.h"
51 #include "core/frame/ContentSettingsClient.h" 51 #include "core/frame/ContentSettingsClient.h"
52 #include "core/frame/LocalDOMWindow.h" 52 #include "core/frame/LocalDOMWindow.h"
53 #include "core/frame/LocalFrame.h" 53 #include "core/frame/LocalFrame.h"
54 #include "core/frame/LocalFrameClient.h" 54 #include "core/frame/LocalFrameClient.h"
55 #include "core/frame/LocalFrameView.h" 55 #include "core/frame/LocalFrameView.h"
56 #include "core/frame/Settings.h" 56 #include "core/frame/Settings.h"
57 #include "core/frame/VisualViewport.h" 57 #include "core/frame/VisualViewport.h"
58 #include "core/frame/csp/CSPDirectiveList.h"
58 #include "core/frame/csp/ContentSecurityPolicy.h" 59 #include "core/frame/csp/ContentSecurityPolicy.h"
59 #include "core/html/HTMLFormElement.h" 60 #include "core/html/HTMLFormElement.h"
60 #include "core/html/HTMLFrameOwnerElement.h" 61 #include "core/html/HTMLFrameOwnerElement.h"
61 #include "core/input/EventHandler.h" 62 #include "core/input/EventHandler.h"
62 #include "core/inspector/ConsoleMessage.h" 63 #include "core/inspector/ConsoleMessage.h"
63 #include "core/loader/DocumentLoadTiming.h" 64 #include "core/loader/DocumentLoadTiming.h"
64 #include "core/loader/DocumentLoader.h" 65 #include "core/loader/DocumentLoader.h"
65 #include "core/loader/FormSubmission.h" 66 #include "core/loader/FormSubmission.h"
66 #include "core/loader/FrameLoadRequest.h" 67 #include "core/loader/FrameLoadRequest.h"
67 #include "core/loader/LinkLoader.h" 68 #include "core/loader/LinkLoader.h"
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 DCHECK(ToLocalFrame(parent_frame)->GetDocument()); 1565 DCHECK(ToLocalFrame(parent_frame)->GetDocument());
1565 return ToLocalFrame(parent_frame) 1566 return ToLocalFrame(parent_frame)
1566 ->GetDocument() 1567 ->GetDocument()
1567 ->InsecureNavigationsToUpgrade(); 1568 ->InsecureNavigationsToUpgrade();
1568 } 1569 }
1569 1570
1570 void FrameLoader::ModifyRequestForCSP(ResourceRequest& resource_request, 1571 void FrameLoader::ModifyRequestForCSP(ResourceRequest& resource_request,
1571 Document* document) const { 1572 Document* document) const {
1572 if (RuntimeEnabledFeatures::embedderCSPEnforcementEnabled() && 1573 if (RuntimeEnabledFeatures::embedderCSPEnforcementEnabled() &&
1573 !RequiredCSP().IsEmpty()) { 1574 !RequiredCSP().IsEmpty()) {
1574 // TODO(amalika): Strengthen this DCHECK that requiredCSP has proper format 1575 DCHECK(
1575 DCHECK(RequiredCSP().GetString().ContainsOnlyASCII()); 1576 CSPDirectiveList::IsValid(RequiredCSP().GetString(),
1577 ContentSecurityPolicyHeaderType::
1578 kContentSecurityPolicyHeaderTypeEnforce,
1579 ContentSecurityPolicyHeaderSource::
1580 kContentSecurityPolicyHeaderSourceHTTP));
1576 resource_request.SetHTTPHeaderField(HTTPNames::Required_CSP, RequiredCSP()); 1581 resource_request.SetHTTPHeaderField(HTTPNames::Required_CSP, RequiredCSP());
1577 } 1582 }
1578 1583
1579 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational 1584 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational
1580 // requests, as described in 1585 // requests, as described in
1581 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect 1586 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect
1582 if (resource_request.GetFrameType() != WebURLRequest::kFrameTypeNone) { 1587 if (resource_request.GetFrameType() != WebURLRequest::kFrameTypeNone) {
1583 // Early return if the request has already been upgraded. 1588 // Early return if the request has already been upgraded.
1584 if (!resource_request.HttpHeaderField(HTTPNames::Upgrade_Insecure_Requests) 1589 if (!resource_request.HttpHeaderField(HTTPNames::Upgrade_Insecure_Requests)
1585 .IsNull()) { 1590 .IsNull()) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 // TODO(japhet): This is needed because the browser process DCHECKs if the 1683 // TODO(japhet): This is needed because the browser process DCHECKs if the
1679 // first entry we commit in a new frame has replacement set. It's unclear 1684 // first entry we commit in a new frame has replacement set. It's unclear
1680 // whether the DCHECK is right, investigate removing this special case. 1685 // whether the DCHECK is right, investigate removing this special case.
1681 bool replace_current_item = load_type == kFrameLoadTypeReplaceCurrentItem && 1686 bool replace_current_item = load_type == kFrameLoadTypeReplaceCurrentItem &&
1682 (!Opener() || !request.Url().IsEmpty()); 1687 (!Opener() || !request.Url().IsEmpty());
1683 loader->SetReplacesCurrentHistoryItem(replace_current_item); 1688 loader->SetReplacesCurrentHistoryItem(replace_current_item);
1684 return loader; 1689 return loader;
1685 } 1690 }
1686 1691
1687 } // namespace blink 1692 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698