Source/WebCore/ChangeLog

 12012-07-19 Mike West <mkwst@chromium.org>
 2
 3 CSP 1.1: Implement the Content Security Policy script interface.
 4 https://bugs.webkit.org/show_bug.cgi?id=91707
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 The CSP 1.1 editor's draft defines a script interface that gives
 9 developers the ability to query a document regarding the restrictions
 10 set by it's currently active content security policy[1]. This patch
 11 exposes that API in terms of a new DOMSecurityPolicy object.
 12
 13 Data for the API is gathered from the existing ContentSecurityPolicy
 14 object on the containing document. CSP's various methods have been
 15 extended with a `reportingStatus` parameter which, unsurprisingly,
 16 determines whether a violation report should be sent for blocked
 17 resources. This allows us to reuse the same codepaths by simply using
 18 ContentSecurityPolicy::SuppressReport when querying on behalf of the
 19 API, and ContentSecurityPolicy::SendReport when checking resources a
 20 page wants to load.
 21
 22 This feature is gated on the CSP_NEXT flag, which is currently disabled
 23 for all ports other than Chromium.
 24
 25 [1]: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces--experimental
 26
 27 Tests: http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html
 28 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html
 29 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html
 30 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html
 31 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html
 32 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html
 33 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html
 34 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html
 35 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html
 36 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html
 37 http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html
 38
 39 * CMakeLists.txt:
 40 * DerivedSources.cpp:
 41 * DerivedSources.make:
 42 * DerivedSources.pri:
 43 * GNUmakefile.list.am:
 44 * WebCore.gypi:
 45 * bindings/gobject/GNUmakefile.am:
 46 * WebCore.xcodeproj/project.pbxproj:
 47 We added a new object, so let's tell _everyone!_
 48 * dom/Document.cpp:
 49 (WebCore::Document::securityPolicy):
 50 Expose the SecurityPolicy object via Document, gated on CSP_NEXT.
 51 (WebCore):
 52 * dom/Document.h:
 53 (WebCore):
 54 (Document):
 55 * dom/Document.idl:
 56 Adding the SecurityPolicy object to the document, gated on CSP_NEXT.
 57 * page/ContentSecurityPolicy.cpp:
 58 (CSPDirectiveList):
 59 (WebCore::CSPDirectiveList::checkInline):
 60 (WebCore::CSPDirectiveList::checkNonce):
 61 (WebCore::CSPDirectiveList::checkSource):
 62 Extracting the core checks out into separate methods.
 63 (WebCore::CSPDirectiveList::checkEvalAndReportViolation):
 64 Use checkEval.
 65 (WebCore::CSPDirectiveList::checkNonceAndReportViolation):
 66 Use checkNonce.
 67 (WebCore::CSPDirectiveList::checkInlineAndReportViolation):
 68 Use checkInline.
 69 (WebCore::CSPDirectiveList::checkSourceAndReportViolation):
 70 Use checkSource.
 71 (WebCore::CSPDirectiveList::allowJavaScriptURLs):
 72 (WebCore::CSPDirectiveList::allowInlineEventHandlers):
 73 (WebCore::CSPDirectiveList::allowInlineScript):
 74 (WebCore::CSPDirectiveList::allowInlineStyle):
 75 (WebCore::CSPDirectiveList::allowEval):
 76 (WebCore::CSPDirectiveList::allowScriptFromSource):
 77 (WebCore::CSPDirectiveList::allowObjectFromSource):
 78 (WebCore::CSPDirectiveList::allowChildFrameFromSource):
 79 (WebCore::CSPDirectiveList::allowImageFromSource):
 80 (WebCore::CSPDirectiveList::allowStyleFromSource):
 81 (WebCore::CSPDirectiveList::allowFontFromSource):
 82 (WebCore::CSPDirectiveList::allowMediaFromSource):
 83 (WebCore::CSPDirectiveList::allowConnectToSource):
 84 These methods now branch on `reportingStatus`: if `SendReoport`,
 85 they call `checkXAndReportViolation`, otherwise, they call `checkX`.
 86 (WebCore::CSPDirectiveList::gatherReportURIs):
 87 New method that gathers the violation report URIs into a DOMStringList.
 88 (WebCore::isAllowedByAllWithCallStack):
 89 (WebCore::isAllowedByAllWithContext):
 90 (WebCore::isAllowedByAllWithURL):
 91 These now pass reportingStatus through to the various `allowX` methods.
 92 (WebCore::ContentSecurityPolicy::allowJavaScriptURLs):
 93 (WebCore::ContentSecurityPolicy::allowInlineEventHandlers):
 94 (WebCore::ContentSecurityPolicy::allowInlineScript):
 95 (WebCore::ContentSecurityPolicy::allowInlineStyle):
 96 (WebCore::ContentSecurityPolicy::allowEval):
 97 (WebCore::ContentSecurityPolicy::allowScriptFromSource):
 98 (WebCore::ContentSecurityPolicy::allowObjectFromSource):
 99 (WebCore::ContentSecurityPolicy::allowChildFrameFromSource):
 100 (WebCore::ContentSecurityPolicy::allowImageFromSource):
 101 (WebCore::ContentSecurityPolicy::allowStyleFromSource):
 102 (WebCore::ContentSecurityPolicy::allowFontFromSource):
 103 (WebCore::ContentSecurityPolicy::allowMediaFromSource):
 104 (WebCore::ContentSecurityPolicy::allowConnectToSource):
 105 These accept a new `reportingStatus` parameter, which is passed through
 106 to the CSPDirectiveList methods.
 107 (WebCore::ContentSecurityPolicy::isActive):
 108 New method that returns `true` if policy is active.
 109 (WebCore::ContentSecurityPolicy::gatherReportURIs):
 110 New method that returns a DOMStringList of violation report URIs.
 111 * page/ContentSecurityPolicy.h:
 112 (WebCore):
 113 * page/DOMSecurityPolicy.cpp: Added.
 114 (WebCore::DOMSecurityPolicy::DOMSecurityPolicy):
 115 (WebCore):
 116 (WebCore::DOMSecurityPolicy::~DOMSecurityPolicy):
 117 (WebCore::DOMSecurityPolicy::isActive):
 118 (WebCore::DOMSecurityPolicy::reportURIs):
 119 (WebCore::DOMSecurityPolicy::allowsInlineScript):
 120 (WebCore::DOMSecurityPolicy::allowsInlineStyle):
 121 (WebCore::DOMSecurityPolicy::allowsEval):
 122 (WebCore::DOMSecurityPolicy::allowsConnectionTo):
 123 (WebCore::DOMSecurityPolicy::allowsFontFrom):
 124 (WebCore::DOMSecurityPolicy::allowsFrameFrom):
 125 (WebCore::DOMSecurityPolicy::allowsImageFrom):
 126 (WebCore::DOMSecurityPolicy::allowsMediaFrom):
 127 (WebCore::DOMSecurityPolicy::allowsObjectFrom):
 128 (WebCore::DOMSecurityPolicy::allowsScriptFrom):
 129 (WebCore::DOMSecurityPolicy::allowsStyleFrom):
 130 * page/DOMSecurityPolicy.h: Added.
 131 (WebCore):
 132 (DOMSecurityPolicy):
 133 (WebCore::DOMSecurityPolicy::create):
 134 * page/DOMSecurityPolicy.idl: Added.
 135
11362012-07-19 Andrey Kosyakov <caseq@chromium.org>
2137
3138 Web Inspector: minimize number of properties on WebInspector.TimelinePresentationModel.Record

Source/WebCore/CMakeLists.txt

@@SET(WebCore_IDL_FILES
530530 page/Console.idl
531531 page/Coordinates.idl
532532 page/Crypto.idl
 533 page/DOMSecurityPolicy.idl
533534 page/DOMSelection.idl
534535 page/DOMWindow.idl
535536 page/EventSource.idl

@@SET(WebCore_SOURCES
16201621 page/ContentSecurityPolicy.cpp
16211622 page/ContextMenuController.cpp
16221623 page/Crypto.cpp
 1624 page/DOMSecurityPolicy.cpp
16231625 page/DOMSelection.cpp
16241626 page/DOMTimer.cpp
16251627 page/DOMWindow.cpp

Source/WebCore/DerivedSources.cpp

9494#include "JSDOMParser.cpp"
9595#include "JSDOMPlugin.cpp"
9696#include "JSDOMPluginArray.cpp"
 97#include "JSDOMSecurityPolicy.cpp"
9798#include "JSDOMSelection.cpp"
9899#include "JSDOMSettableTokenList.cpp"
99100#include "JSDOMStringList.cpp"

Source/WebCore/DerivedSources.make

@@BINDING_IDLS = \
405405 $(WebCore)/page/Console.idl \
406406 $(WebCore)/page/Coordinates.idl \
407407 $(WebCore)/page/Crypto.idl \
 408 $(WebCore)/page/DOMSecurityPolicy.idl \
408409 $(WebCore)/page/DOMSelection.idl \
409410 $(WebCore)/page/DOMWindow.idl \
410411 $(WebCore)/page/EventSource.idl \

Source/WebCore/DerivedSources.pri

@@IDL_BINDINGS += \
413413 $$PWD/page/Console.idl \
414414 $$PWD/page/Coordinates.idl \
415415 $$PWD/page/Crypto.idl \
 416 $$PWD/page/DOMSecurityPolicy.idl \
416417 $$PWD/page/DOMSelection.idl \
417418 $$PWD/page/DOMWindow.idl \
418419 $$PWD/page/EventSource.idl \

Source/WebCore/GNUmakefile.list.am

@@webcore_built_sources += \
142142 DerivedSources/WebCore/JSDOMPluginArray.h \
143143 DerivedSources/WebCore/JSDOMPlugin.cpp \
144144 DerivedSources/WebCore/JSDOMPlugin.h \
 145 DerivedSources/WebCore/JSDOMSecurityPolicy.cpp \
 146 DerivedSources/WebCore/JSDOMSecurityPolicy.h \
145147 DerivedSources/WebCore/JSDOMSelection.cpp \
146148 DerivedSources/WebCore/JSDOMSelection.h \
147149 DerivedSources/WebCore/JSDOMSettableTokenList.cpp \

@@dom_binding_idls += \
957959 $(WebCore)/page/Console.idl \
958960 $(WebCore)/page/Coordinates.idl \
959961 $(WebCore)/page/Crypto.idl \
 962 $(WebCore)/page/DOMSecurityPolicy.idl \
960963 $(WebCore)/page/DOMSelection.idl \
961964 $(WebCore)/page/DOMWindow.idl \
962965 $(WebCore)/page/EventSource.idl \

@@webcore_sources += \
30083011 Source/WebCore/page/Coordinates.h \
30093012 Source/WebCore/page/Crypto.cpp \
30103013 Source/WebCore/page/Crypto.h \
 3014 Source/WebCore/page/DOMSecurityPolicy.cpp \
 3015 Source/WebCore/page/DOMSecurityPolicy.h \
30113016 Source/WebCore/page/DOMSelection.cpp \
30123017 Source/WebCore/page/DOMSelection.h \
30133018 Source/WebCore/page/DOMTimer.cpp \

Source/WebCore/WebCore.gypi

223223 'page/ContextMenuClient.h',
224224 'page/ContextMenuController.h',
225225 'page/Coordinates.h',
 226 'page/DOMSecurityPolicy.h',
226227 'page/DOMWindow.h',
227228 'page/DOMWindowExtension.h',
228229 'page/DragActions.h',

11591160 'page/Console.idl',
11601161 'page/Coordinates.idl',
11611162 'page/Crypto.idl',
 1163 'page/DOMSecurityPolicy.idl',
11621164 'page/DOMSelection.idl',
11631165 'page/DOMWindow.idl',
11641166 'page/DOMWindowPagePopup.idl',

30303032 'page/ContextMenuProvider.h',
30313033 'page/Crypto.cpp',
30323034 'page/Crypto.h',
 3035 'page/DOMSecurityPolicy.cpp',
30333036 'page/DOMSelection.cpp',
30343037 'page/DOMSelection.h',
30353038 'page/DOMTimer.cpp',

72637266 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMPlugin.h',
72647267 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMPluginArray.cpp',
72657268 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMPluginArray.h',
 7269 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSecurityPolicy.cpp',
 7270 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSecurityPolicy.h',
72667271 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSelection.cpp',
72677272 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSelection.h',
72687273 '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSettableTokenList.cpp',

Source/WebCore/WebCore.xcodeproj/project.pbxproj

775775 2D8FEBDD143E3EF70072502B /* CSSCrossfadeValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8FEBDB143E3EF70072502B /* CSSCrossfadeValue.h */; };
776776 2D9066060BE141D400956998 /* LayoutState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D9066040BE141D400956998 /* LayoutState.cpp */; };
777777 2D9066070BE141D400956998 /* LayoutState.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9066050BE141D400956998 /* LayoutState.h */; settings = {ATTRIBUTES = (Private, ); }; };
 778 2D9A246E15B9BD0000D34527 /* DOMSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9A246B15B9BBDD00D34527 /* DOMSecurityPolicy.h */; };
 779 2D9A246F15B9BD2F00D34527 /* DOMSecurityPolicy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */; };
 780 2D9A247315B9C2D100D34527 /* DOMDOMSecurityPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A247215B9C2C700D34527 /* DOMDOMSecurityPolicy.mm */; };
 781 2D9A247415B9C2E300D34527 /* DOMDOMSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */; };
 782 2D9A247515B9C2E300D34527 /* DOMDOMSecurityPolicyInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9A247115B9C29500D34527 /* DOMDOMSecurityPolicyInternal.h */; };
 783 2D9A247615B9C2F400D34527 /* DOMDOMSecurityPolicy.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */; };
778784 2D9F0E1314FF1CBF00BA0FF7 /* linearSRGB.icc in Resources */ = {isa = PBXBuildFile; fileRef = 2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */; };
779785 2E0888D41148848A00AF4265 /* JSDOMFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */; };
780786 2E0888D51148848A00AF4265 /* JSDOMFormData.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E0888D31148848A00AF4265 /* JSDOMFormData.h */; };

65476553 dstSubfolderSpec = 1;
65486554 files = (
65496555 5DF7F5C20F01F92A00526B4B /* CSSPropertyNames.h in Copy Generated Headers */,
 6556 2D9A247615B9C2F400D34527 /* DOMDOMSecurityPolicy.h in Copy Generated Headers */,
65506557 8538F0300AD71CDB006A81D1 /* DOMAbstractView.h in Copy Generated Headers */,
65516558 1C11CCBC0AA6093700DADB20 /* DOMAttr.h in Copy Generated Headers */,
65526559 2E2D99EB10E2BD3900496337 /* DOMBlob.h in Copy Generated Headers */,

77997806 2D9066050BE141D400956998 /* LayoutState.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LayoutState.h; sourceTree = "<group>"; };
78007807 2D90660B0665D937006B6F1A /* ClipboardMac.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = ClipboardMac.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
78017808 2D90660C0665D937006B6F1A /* ClipboardMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ClipboardMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 7809 2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMSecurityPolicy.cpp; sourceTree = "<group>"; };
 7810 2D9A246B15B9BBDD00D34527 /* DOMSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMSecurityPolicy.h; sourceTree = "<group>"; };
 7811 2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDOMSecurityPolicy.h; sourceTree = "<group>"; };
 7812 2D9A247115B9C29500D34527 /* DOMDOMSecurityPolicyInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDOMSecurityPolicyInternal.h; sourceTree = "<group>"; };
 7813 2D9A247215B9C2C700D34527 /* DOMDOMSecurityPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMDOMSecurityPolicy.mm; sourceTree = "<group>"; };
78027814 2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */ = {isa = PBXFileReference; lastKnownFileType = file; path = linearSRGB.icc; sourceTree = "<group>"; };
78037815 2E0888C3114883A900AF4265 /* DOMFormData.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMFormData.idl; sourceTree = "<group>"; };
78047816 2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMFormData.cpp; sourceTree = "<group>"; };

1558015592 65BF02180974806300C43196 /* page */ = {
1558115593 isa = PBXGroup;
1558215594 children = (
 15595 2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */,
 15596 2D9A246B15B9BBDD00D34527 /* DOMSecurityPolicy.h */,
1558315597 316FE1060E6E1D8400BF6088 /* animation */,
1558415598 93C09A820B064F05005ABD4D /* mac */,
1558515599 1AF62EE114DA22A70041556C /* scrolling */,

1585315867 85967D9F0AA8BB59005FEDEE /* Core */ = {
1585415868 isa = PBXGroup;
1585515869 children = (
 15870 2D9A247215B9C2C700D34527 /* DOMDOMSecurityPolicy.mm */,
 15871 2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */,
 15872 2D9A247115B9C29500D34527 /* DOMDOMSecurityPolicyInternal.h */,
1585615873 85D389B00A991A7F00282145 /* DOMAttr.h */,
1585715874 85D389B10A991A7F00282145 /* DOMAttr.mm */,
1585815875 85089CCF0A98C42700A275AA /* DOMCDATASection.h */,

2278222799 8502AB5A0AD438C000378540 /* DOMSVGFEImageElement.h in Headers */,
2278322800 8502AB9B0AD4394E00378540 /* DOMSVGFEImageElementInternal.h in Headers */,
2278422801 8502AB5C0AD438C000378540 /* DOMSVGFEMergeElement.h in Headers */,
 22802 2D9A247415B9C2E300D34527 /* DOMDOMSecurityPolicy.h in Headers */,
 22803 2D9A247515B9C2E300D34527 /* DOMDOMSecurityPolicyInternal.h in Headers */,
2278522804 8502AB9C0AD4394E00378540 /* DOMSVGFEMergeElementInternal.h in Headers */,
2278622805 8502AB5E0AD438C000378540 /* DOMSVGFEMergeNodeElement.h in Headers */,
2278722806 8502AB9D0AD4394E00378540 /* DOMSVGFEMergeNodeElementInternal.h in Headers */,

2329623315 977B386D122883E900B81FF8 /* HTMLEntityTable.h in Headers */,
2329723316 A81369D4097374F600D74463 /* HTMLFieldSetElement.h in Headers */,
2329823317 A8CFF7A60A156978000A4234 /* HTMLFontElement.h in Headers */,
 23318 2D9A246E15B9BD0000D34527 /* DOMSecurityPolicy.h in Headers */,
2329923319 977B386F122883E900B81FF8 /* HTMLFormattingElementList.h in Headers */,
2330023320 A8DF3FCE097FA0FC0052981B /* HTMLFormCollection.h in Headers */,
2330123321 A81369CE097374F600D74463 /* HTMLFormControlElement.h in Headers */,

2560825628 buildActionMask = 2147483647;
2560925629 files = (
2561025630 FDE6860215B0A93B00BB480C /* WrapShapeFunctions.cpp in Sources */,
 25631 2D9A247315B9C2D100D34527 /* DOMDOMSecurityPolicy.mm in Sources */,
2561125632 97BC69DA1505F076001B74AC /* AbstractDatabase.cpp in Sources */,
2561225633 41E1B1D00FF5986900576B3B /* AbstractWorker.cpp in Sources */,
2561325634 0F29C16E1300C2E2002D794E /* AccessibilityAllInOne.cpp in Sources */,

2606626087 8538F05C0AD722F1006A81D1 /* DOMRange.mm in Sources */,
2606726088 858C38A80AA8F20400B187A4 /* DOMRect.mm in Sources */,
2606826089 BCAEFCAE1016CE4A0040D34E /* DOMRGBColor.mm in Sources */,
 26090 2D9A246F15B9BD2F00D34527 /* DOMSecurityPolicy.cpp in Sources */,
2606926091 BC5A86840C33676000EEA649 /* DOMSelection.cpp in Sources */,
2607026092 4ACBC0C312713CCA0094F9B2 /* DOMSettableTokenList.cpp in Sources */,
2607126093 C55610F111A704EB00B82D27 /* DOMStringList.cpp in Sources */,

Source/WebCore/bindings/gobject/GNUmakefile.am

@@webkitgtk_gdom_built_sources += \
4343 DerivedSources/webkit/WebKitDOMDOMPluginArrayPrivate.h \
4444 DerivedSources/webkit/WebKitDOMDOMPlugin.cpp \
4545 DerivedSources/webkit/WebKitDOMDOMPluginPrivate.h \
 46 DerivedSources/webkit/WebKitDOMDOMSecurityPolicy.cpp \
 47 DerivedSources/webkit/WebKitDOMDOMSecurityPolicyPrivate.h \
4648 DerivedSources/webkit/WebKitDOMDOMSelection.cpp \
4749 DerivedSources/webkit/WebKitDOMDOMSelectionPrivate.h \
4850 DerivedSources/webkit/WebKitDOMDOMStringList.cpp \

@@webkitgtk_built_h_api += \
278280 DerivedSources/webkit/WebKitDOMDocumentType.h \
279281 DerivedSources/webkit/WebKitDOMDOMImplementation.h \
280282 DerivedSources/webkit/WebKitDOMDOMSettableTokenList.h \
 283 DerivedSources/webkit/WebKitDOMDOMSecurityPolicy.h \
281284 DerivedSources/webkit/WebKitDOMDOMStringList.h \
282285 DerivedSources/webkit/WebKitDOMDOMStringMap.h \
283286 DerivedSources/webkit/WebKitDOMDOMTokenList.h \

Source/WebCore/dom/Document.cpp

222222#include "TextAutosizer.h"
223223#endif
224224
 225#if ENABLE(CSP_NEXT)
 226#include "DOMSecurityPolicy.h"
 227#endif
 228
225229using namespace std;
226230using namespace WTF;
227231using namespace Unicode;

@@void Document::dispatchVisibilityStateChangeEvent()
16411645}
16421646#endif
16431647
 1648#if ENABLE(CSP_NEXT)
 1649DOMSecurityPolicy* Document::securityPolicy()
 1650{
 1651 if (!m_domSecurityPolicy)
 1652 m_domSecurityPolicy = DOMSecurityPolicy::create(this);
 1653 return m_domSecurityPolicy.get();
 1654}
 1655#endif
 1656
16441657String Document::nodeName() const
16451658{
16461659 return "#document";

Source/WebCore/dom/Document.h

@@class Prerenderer;
179179class TextAutosizer;
180180#endif
181181
 182#if ENABLE(CSP_NEXT)
 183class DOMSecurityPolicy;
 184#endif
 185
182186typedef int ExceptionCode;
183187
184188enum PageshowEventPersistence {

@@public:
416420 void dispatchVisibilityStateChangeEvent();
417421#endif
418422
 423#if ENABLE(CSP_NEXT)
 424 DOMSecurityPolicy* securityPolicy();
 425#endif
 426
419427 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
420428
421429 PassRefPtr<HTMLCollection> images();

@@private:
15321540
15331541 RefPtr<WebKitNamedFlowCollection> m_namedFlows;
15341542
 1543#if ENABLE(CSP_NEXT)
 1544 RefPtr<DOMSecurityPolicy> m_domSecurityPolicy;
 1545#endif
 1546
15351547#ifndef NDEBUG
15361548 bool m_didDispatchViewportPropertiesChanged;
15371549#endif

Source/WebCore/dom/Document.idl

@@module core {
375375 readonly attribute [Conditional=PAGE_VISIBILITY_API] DOMString webkitVisibilityState;
376376 readonly attribute [Conditional=PAGE_VISIBILITY_API] boolean webkitHidden;
377377
 378 // Security Policy API: http://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces
 379 readonly attribute [Conditional=CSP_NEXT] DOMSecurityPolicy SecurityPolicy;
 380
378381 };
379382
380383}

Source/WebCore/page/ContentSecurityPolicy.cpp

2727#include "ContentSecurityPolicy.h"
2828
2929#include "Console.h"
 30#include "DOMStringList.h"
3031#include "Document.h"
3132#include "FormData.h"
3233#include "FormDataList.h"

@@public:
546547 const String& header() const { return m_header; }
547548 ContentSecurityPolicy::HeaderType headerType() const { return m_reportOnly ? ContentSecurityPolicy::ReportOnly : ContentSecurityPolicy::EnforcePolicy; }
548549
549  bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
550  bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
551  bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
552  bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
553  bool allowEval(PassRefPtr<ScriptCallStack>) const;
 550 bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
 551 bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
 552 bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
 553 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
 554 bool allowEval(PassRefPtr<ScriptCallStack>, ContentSecurityPolicy::ReportingStatus) const;
554555 bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL&) const;
555556
556  bool allowScriptFromSource(const KURL&) const;
557  bool allowObjectFromSource(const KURL&) const;
558  bool allowChildFrameFromSource(const KURL&) const;
559  bool allowImageFromSource(const KURL&) const;
560  bool allowStyleFromSource(const KURL&) const;
561  bool allowFontFromSource(const KURL&) const;
562  bool allowMediaFromSource(const KURL&) const;
563  bool allowConnectToSource(const KURL&) const;
 557 bool allowScriptFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 558 bool allowObjectFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 559 bool allowChildFrameFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 560 bool allowImageFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 561 bool allowStyleFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 562 bool allowFontFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 563 bool allowMediaFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 564 bool allowConnectToSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
 565
 566 void gatherReportURIs(DOMStringList&) const;
564567
565568private:
566569 explicit CSPDirectiveList(ScriptExecutionContext*);

@@private:
580583 void logUnrecognizedDirective(const String& name) const;
581584 void logDuplicateDirective(const String& name) const;
582585 void logInvalidNonce(const String& nonce) const;
 586
583587 bool checkEval(CSPDirective*) const;
 588 bool checkInline(CSPDirective*) const;
 589 bool checkNonce(const String&) const;
 590 bool checkSource(CSPDirective*, const KURL&) const;
584591
 592 bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
585593 bool checkInlineAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
586594 bool checkNonceAndReportViolation(const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
587  bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
588595 bool checkSourceAndReportViolation(CSPDirective*, const KURL&, const String& type) const;
589596
590597 bool denyIfEnforcingPolicy() const { return m_reportOnly; }

@@bool CSPDirectiveList::checkEval(CSPDirective* directive) const
707714 return !directive || directive->allowEval();
708715}
709716
 717bool CSPDirectiveList::checkInline(CSPDirective* directive) const
 718{
 719 return !directive || directive->allowInline();
 720}
 721
 722bool CSPDirectiveList::checkNonce(const String& nonce) const
 723{
 724 return (m_scriptNonce.isNull()
 725 || (!m_scriptNonce.isEmpty()
 726 && nonce.stripWhiteSpace() == m_scriptNonce));
 727}
 728
 729bool CSPDirectiveList::checkSource(CSPDirective* directive, const KURL& url) const
 730{
 731 return !directive || directive->allows(url);
 732}
 733
710734CSPDirective* CSPDirectiveList::operativeDirective(CSPDirective* directive) const
711735{
712736 return directive ? directive : m_defaultSrc.get();
713737}
714738
715 bool CSPDirectiveList::checkInlineAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 739bool CSPDirectiveList::checkEvalAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, PassRefPtr<ScriptCallStack> callStack) const
716740{
717  if (!directive || directive->allowInline())
 741 if (checkEval(directive))
718742 return true;
719  reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine);
 743 reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine, callStack);
720744 return denyIfEnforcingPolicy();
721745}
722746
723747bool CSPDirectiveList::checkNonceAndReportViolation(const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
724748{
725  if (m_scriptNonce.isNull() || (!m_scriptNonce.isEmpty() && nonce.stripWhiteSpace() == m_scriptNonce))
 749 if (checkNonce(nonce))
726750 return true;
727751 reportViolation(m_scriptNonce, consoleMessage + "\"script-nonce " + m_scriptNonce + "\".\n", KURL(), contextURL, contextLine);
728752 return denyIfEnforcingPolicy();
729753}
730754
731 bool CSPDirectiveList::checkEvalAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, PassRefPtr<ScriptCallStack> callStack) const
 755bool CSPDirectiveList::checkInlineAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
732756{
733  if (checkEval(directive))
 757 if (checkInline(directive))
734758 return true;
735  reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine, callStack);
 759 reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine);
736760 return denyIfEnforcingPolicy();
737761}
738762
739763bool CSPDirectiveList::checkSourceAndReportViolation(CSPDirective* directive, const KURL& url, const String& type) const
740764{
741  if (!directive || directive->allows(url))
 765 if (checkSource(directive, url))
742766 return true;
743767 String verb = type == "connect" ? "connect to" : "load the";
744768 reportViolation(directive->text(), "Refused to " + verb + " " + type + " '" + url.string() + "' because it violates the following Content Security Policy directive: \"" + directive->text() + "\".\n", url);
745769 return denyIfEnforcingPolicy();
746770}
747771
748 bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 772bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
749773{
750774 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "));
751  return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
752  && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
 775 if (reportingStatus == ContentSecurityPolicy::SendReport) {
 776 return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
 777 && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
 778 } else {
 779 return (checkInline(operativeDirective(m_scriptSrc.get()))
 780 && checkNonce(String()));
 781 }
753782}
754783
755 bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 784bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
756785{
757786 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute inline event handler because it violates the following Content Security Policy directive: "));
758  return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
759  && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
 787 if (reportingStatus == ContentSecurityPolicy::SendReport) {
 788 return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
 789 && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
 790 } else {
 791 return (checkInline(operativeDirective(m_scriptSrc.get()))
 792 && checkNonce(String()));
 793 }
760794}
761795
762 bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 796bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
763797{
764798 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute inline script because it violates the following Content Security Policy directive: "));
765  return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine);
 799 return reportingStatus == ContentSecurityPolicy::SendReport ?
 800 checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine) :
 801 checkInline(operativeDirective(m_scriptSrc.get()));
766802}
767803
768 bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 804bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
769805{
770806 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to apply inline style because it violates the following Content Security Policy directive: "));
771  return checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine);
 807 return reportingStatus == ContentSecurityPolicy::SendReport ?
 808 checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine) :
 809 checkInline(operativeDirective(m_styleSrc.get()));
772810}
773811
774 bool CSPDirectiveList::allowEval(PassRefPtr<ScriptCallStack> callStack) const
 812bool CSPDirectiveList::allowEval(PassRefPtr<ScriptCallStack> callStack, ContentSecurityPolicy::ReportingStatus reportingStatus) const
775813{
776814 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to evaluate script because it violates the following Content Security Policy directive: "));
777  return checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, String(), WTF::OrdinalNumber::beforeFirst(), callStack);
 815 return reportingStatus == ContentSecurityPolicy::SendReport ?
 816 checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, String(), WTF::OrdinalNumber::beforeFirst(), callStack) :
 817 checkEval(operativeDirective(m_scriptSrc.get()));
778818}
779819
780820bool CSPDirectiveList::allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL& url) const

@@bool CSPDirectiveList::allowScriptNonce(const String& nonce, const String& conte
785825 return checkNonceAndReportViolation(nonce, "Refused to load '" + url.string() + "' because it violates the following Content Security Policy directive: ", contextURL, contextLine);
786826}
787827
788 bool CSPDirectiveList::allowScriptFromSource(const KURL& url) const
 828bool CSPDirectiveList::allowScriptFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
789829{
790830 DEFINE_STATIC_LOCAL(String, type, ("script"));
791  return checkSourceAndReportViolation(operativeDirective(m_scriptSrc.get()), url, type);
 831 return reportingStatus == ContentSecurityPolicy::SendReport ?
 832 checkSourceAndReportViolation(operativeDirective(m_scriptSrc.get()), url, type) :
 833 checkSource(operativeDirective(m_scriptSrc.get()), url);
792834}
793835
794 bool CSPDirectiveList::allowObjectFromSource(const KURL& url) const
 836bool CSPDirectiveList::allowObjectFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
795837{
796838 DEFINE_STATIC_LOCAL(String, type, ("object"));
797839 if (url.isBlankURL())
798840 return true;
799  return checkSourceAndReportViolation(operativeDirective(m_objectSrc.get()), url, type);
 841 return reportingStatus == ContentSecurityPolicy::SendReport ?
 842 checkSourceAndReportViolation(operativeDirective(m_objectSrc.get()), url, type) :
 843 checkSource(operativeDirective(m_objectSrc.get()), url);
800844}
801845
802 bool CSPDirectiveList::allowChildFrameFromSource(const KURL& url) const
 846bool CSPDirectiveList::allowChildFrameFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
803847{
804848 DEFINE_STATIC_LOCAL(String, type, ("frame"));
805849 if (url.isBlankURL())
806850 return true;
807  return checkSourceAndReportViolation(operativeDirective(m_frameSrc.get()), url, type);
 851 return reportingStatus == ContentSecurityPolicy::SendReport ?
 852 checkSourceAndReportViolation(operativeDirective(m_frameSrc.get()), url, type) :
 853 checkSource(operativeDirective(m_frameSrc.get()), url);
808854}
809855
810 bool CSPDirectiveList::allowImageFromSource(const KURL& url) const
 856bool CSPDirectiveList::allowImageFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
811857{
812858 DEFINE_STATIC_LOCAL(String, type, ("image"));
813  return checkSourceAndReportViolation(operativeDirective(m_imgSrc.get()), url, type);
 859 return reportingStatus == ContentSecurityPolicy::SendReport ?
 860 checkSourceAndReportViolation(operativeDirective(m_imgSrc.get()), url, type) :
 861 checkSource(operativeDirective(m_imgSrc.get()), url);
814862}
815863
816 bool CSPDirectiveList::allowStyleFromSource(const KURL& url) const
 864bool CSPDirectiveList::allowStyleFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
817865{
818866 DEFINE_STATIC_LOCAL(String, type, ("style"));
819  return checkSourceAndReportViolation(operativeDirective(m_styleSrc.get()), url, type);
 867 return reportingStatus == ContentSecurityPolicy::SendReport ?
 868 checkSourceAndReportViolation(operativeDirective(m_styleSrc.get()), url, type) :
 869 checkSource(operativeDirective(m_styleSrc.get()), url);
820870}
821871
822 bool CSPDirectiveList::allowFontFromSource(const KURL& url) const
 872bool CSPDirectiveList::allowFontFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
823873{
824874 DEFINE_STATIC_LOCAL(String, type, ("font"));
825  return checkSourceAndReportViolation(operativeDirective(m_fontSrc.get()), url, type);
 875 return reportingStatus == ContentSecurityPolicy::SendReport ?
 876 checkSourceAndReportViolation(operativeDirective(m_fontSrc.get()), url, type) :
 877 checkSource(operativeDirective(m_fontSrc.get()), url);
826878}
827879
828 bool CSPDirectiveList::allowMediaFromSource(const KURL& url) const
 880bool CSPDirectiveList::allowMediaFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
829881{
830882 DEFINE_STATIC_LOCAL(String, type, ("media"));
831  return checkSourceAndReportViolation(operativeDirective(m_mediaSrc.get()), url, type);
 883 return reportingStatus == ContentSecurityPolicy::SendReport ?
 884 checkSourceAndReportViolation(operativeDirective(m_mediaSrc.get()), url, type) :
 885 checkSource(operativeDirective(m_mediaSrc.get()), url);
832886}
833887
834 bool CSPDirectiveList::allowConnectToSource(const KURL& url) const
 888bool CSPDirectiveList::allowConnectToSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
835889{
836890 DEFINE_STATIC_LOCAL(String, type, ("connect"));
837  return checkSourceAndReportViolation(operativeDirective(m_connectSrc.get()), url, type);
 891 return reportingStatus == ContentSecurityPolicy::SendReport ?
 892 checkSourceAndReportViolation(operativeDirective(m_connectSrc.get()), url, type) :
 893 checkSource(operativeDirective(m_connectSrc.get()), url);
 894}
 895
 896void CSPDirectiveList::gatherReportURIs(DOMStringList& list) const
 897{
 898 for (size_t i = 0; i < m_reportURIs.size(); ++i)
 899 list.append(m_reportURIs[i].string());
838900}
839901
840902// policy = directive-list

@@ContentSecurityPolicy::HeaderType ContentSecurityPolicy::deprecatedHeaderType()
10821144 return m_policies.isEmpty() ? EnforcePolicy : m_policies[0]->headerType();
10831145}
10841146
1085 template<bool (CSPDirectiveList::*allowed)(PassRefPtr<ScriptCallStack>) const>
1086 bool isAllowedByAllWithCallStack(const CSPDirectiveListVector& policies, PassRefPtr<ScriptCallStack> callStack)
 1147template<bool (CSPDirectiveList::*allowed)(PassRefPtr<ScriptCallStack>, ContentSecurityPolicy::ReportingStatus) const>
 1148bool isAllowedByAllWithCallStack(const CSPDirectiveListVector& policies, PassRefPtr<ScriptCallStack> callStack, ContentSecurityPolicy::ReportingStatus reportingStatus)
10871149{
10881150 for (size_t i = 0; i < policies.size(); ++i) {
1089  if (!(policies[i].get()->*allowed)(callStack))
 1151 if (!(policies[i].get()->*allowed)(callStack, reportingStatus))
10901152 return false;
10911153 }
10921154 return true;
10931155}
10941156
1095 template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumber&) const>
1096 bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const String& contextURL, const WTF::OrdinalNumber& contextLine)
 1157template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumber&, ContentSecurityPolicy::ReportingStatus) const>
 1158bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus)
10971159{
10981160 for (size_t i = 0; i < policies.size(); ++i) {
1099  if (!(policies[i].get()->*allowed)(contextURL, contextLine))
 1161 if (!(policies[i].get()->*allowed)(contextURL, contextLine, reportingStatus))
11001162 return false;
11011163 }
11021164 return true;

@@bool isAllowedByAllWithNonce(const CSPDirectiveListVector& policies, const Strin
11121174 return true;
11131175}
11141176
1115 template<bool (CSPDirectiveList::*allowFromURL)(const KURL&) const>
1116 bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& url)
 1177template<bool (CSPDirectiveList::*allowFromURL)(const KURL&, ContentSecurityPolicy::ReportingStatus) const>
 1178bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus)
11171179{
11181180 if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
11191181 return true;
11201182
11211183 for (size_t i = 0; i < policies.size(); ++i) {
1122  if (!(policies[i].get()->*allowFromURL)(url))
 1184 if (!(policies[i].get()->*allowFromURL)(url, reportingStatus))
11231185 return false;
11241186 }
11251187 return true;
11261188}
11271189
1128 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 1190bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11291191{
1130  return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_policies, contextURL, contextLine);
 1192 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_policies, contextURL, contextLine, reportingStatus);
11311193}
11321194
1133 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 1195bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11341196{
1135  return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers>(m_policies, contextURL, contextLine);
 1197 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers>(m_policies, contextURL, contextLine, reportingStatus);
11361198}
11371199
1138 bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 1200bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11391201{
1140  return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineScript>(m_policies, contextURL, contextLine);
 1202 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineScript>(m_policies, contextURL, contextLine, reportingStatus);
11411203}
11421204
1143 bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
 1205bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11441206{
11451207 if (m_overrideInlineStyleAllowed)
11461208 return true;
1147  return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_policies, contextURL, contextLine);
 1209 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_policies, contextURL, contextLine, reportingStatus);
11481210}
11491211
1150 bool ContentSecurityPolicy::allowEval(PassRefPtr<ScriptCallStack> callStack) const
 1212bool ContentSecurityPolicy::allowEval(PassRefPtr<ScriptCallStack> callStack, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11511213{
1152  return isAllowedByAllWithCallStack<&CSPDirectiveList::allowEval>(m_policies, callStack);
 1214 return isAllowedByAllWithCallStack<&CSPDirectiveList::allowEval>(m_policies, callStack, reportingStatus);
11531215}
11541216
11551217bool ContentSecurityPolicy::allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL& url) const

@@bool ContentSecurityPolicy::allowScriptNonce(const String& nonce, const String&
11571219 return isAllowedByAllWithNonce<&CSPDirectiveList::allowScriptNonce>(m_policies, nonce, contextURL, contextLine, url);
11581220}
11591221
1160 bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url) const
 1222bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
 1223{
 1224 return isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_policies, url, reportingStatus);
 1225}
 1226
 1227bool ContentSecurityPolicy::allowObjectFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
 1228{
 1229 return isAllowedByAllWithURL<&CSPDirectiveList::allowObjectFromSource>(m_policies, url, reportingStatus);
 1230}
 1231
 1232bool ContentSecurityPolicy::allowChildFrameFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11611233{
1162  return isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_policies, url);
 1234 return isAllowedByAllWithURL<&CSPDirectiveList::allowChildFrameFromSource>(m_policies, url, reportingStatus);
11631235}
11641236
1165 bool ContentSecurityPolicy::allowObjectFromSource(const KURL& url) const
 1237bool ContentSecurityPolicy::allowImageFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11661238{
1167  return isAllowedByAllWithURL<&CSPDirectiveList::allowObjectFromSource>(m_policies, url);
 1239 return isAllowedByAllWithURL<&CSPDirectiveList::allowImageFromSource>(m_policies, url, reportingStatus);
11681240}
11691241
1170 bool ContentSecurityPolicy::allowChildFrameFromSource(const KURL& url) const
 1242bool ContentSecurityPolicy::allowStyleFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11711243{
1172  return isAllowedByAllWithURL<&CSPDirectiveList::allowChildFrameFromSource>(m_policies, url);
 1244 return isAllowedByAllWithURL<&CSPDirectiveList::allowStyleFromSource>(m_policies, url, reportingStatus);
11731245}
11741246
1175 bool ContentSecurityPolicy::allowImageFromSource(const KURL& url) const
 1247bool ContentSecurityPolicy::allowFontFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11761248{
1177  return isAllowedByAllWithURL<&CSPDirectiveList::allowImageFromSource>(m_policies, url);
 1249 return isAllowedByAllWithURL<&CSPDirectiveList::allowFontFromSource>(m_policies, url, reportingStatus);
11781250}
11791251
1180 bool ContentSecurityPolicy::allowStyleFromSource(const KURL& url) const
 1252bool ContentSecurityPolicy::allowMediaFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11811253{
1182  return isAllowedByAllWithURL<&CSPDirectiveList::allowStyleFromSource>(m_policies, url);
 1254 return isAllowedByAllWithURL<&CSPDirectiveList::allowMediaFromSource>(m_policies, url, reportingStatus);
11831255}
11841256
1185 bool ContentSecurityPolicy::allowFontFromSource(const KURL& url) const
 1257bool ContentSecurityPolicy::allowConnectToSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
11861258{
1187  return isAllowedByAllWithURL<&CSPDirectiveList::allowFontFromSource>(m_policies, url);
 1259 return isAllowedByAllWithURL<&CSPDirectiveList::allowConnectToSource>(m_policies, url, reportingStatus);
11881260}
11891261
1190 bool ContentSecurityPolicy::allowMediaFromSource(const KURL& url) const
 1262bool ContentSecurityPolicy::isActive() const
11911263{
1192  return isAllowedByAllWithURL<&CSPDirectiveList::allowMediaFromSource>(m_policies, url);
 1264 return !m_policies.isEmpty();
11931265}
11941266
1195 bool ContentSecurityPolicy::allowConnectToSource(const KURL& url) const
 1267void ContentSecurityPolicy::gatherReportURIs(DOMStringList& list) const
11961268{
1197  return isAllowedByAllWithURL<&CSPDirectiveList::allowConnectToSource>(m_policies, url);
 1269 for (size_t i = 0; i < m_policies.size(); ++i)
 1270 m_policies[i].get()->gatherReportURIs(list);
11981271}
11991272
12001273}

Source/WebCore/page/ContentSecurityPolicy.h

@@namespace WebCore {
4040
4141class CSPDirectiveList;
4242class ScriptCallStack;
 43class DOMStringList;
4344class ScriptExecutionContext;
4445
4546typedef Vector<OwnPtr<CSPDirectiveList> > CSPDirectiveListVector;

@@public:
5960 EnforcePolicy
6061 };
6162
 63 enum ReportingStatus {
 64 SendReport,
 65 SuppressReport
 66 };
 67
6268 void didReceiveHeader(const String&, HeaderType);
6369
64  // These functions are wrong becuase they assume that there is only one header.
 70 // These functions are wrong because they assume that there is only one header.
6571 // FIXME: Replace them with functions that return vectors.
6672 const String& deprecatedHeader() const;
6773 HeaderType deprecatedHeaderType() const;
6874
69  bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
70  bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
71  bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
72  bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
73  bool allowEval(PassRefPtr<ScriptCallStack>) const;
 75 bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
 76 bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
 77 bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
 78 bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
 79 bool allowEval(PassRefPtr<ScriptCallStack>, ReportingStatus = SendReport) const;
7480 bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL& = KURL()) const;
7581
76  bool allowScriptFromSource(const KURL&) const;
77  bool allowObjectFromSource(const KURL&) const;
78  bool allowChildFrameFromSource(const KURL&) const;
79  bool allowImageFromSource(const KURL&) const;
80  bool allowStyleFromSource(const KURL&) const;
81  bool allowFontFromSource(const KURL&) const;
82  bool allowMediaFromSource(const KURL&) const;
83  bool allowConnectToSource(const KURL&) const;
 82 bool allowScriptFromSource(const KURL&, ReportingStatus = SendReport) const;
 83 bool allowObjectFromSource(const KURL&, ReportingStatus = SendReport) const;
 84 bool allowChildFrameFromSource(const KURL&, ReportingStatus = SendReport) const;
 85 bool allowImageFromSource(const KURL&, ReportingStatus = SendReport) const;
 86 bool allowStyleFromSource(const KURL&, ReportingStatus = SendReport) const;
 87 bool allowFontFromSource(const KURL&, ReportingStatus = SendReport) const;
 88 bool allowMediaFromSource(const KURL&, ReportingStatus = SendReport) const;
 89 bool allowConnectToSource(const KURL&, ReportingStatus = SendReport) const;
8490
8591 void setOverrideAllowInlineStyle(bool);
8692
 93 bool isActive() const;
 94 void gatherReportURIs(DOMStringList&) const;
 95
8796private:
8897 explicit ContentSecurityPolicy(ScriptExecutionContext*);
8998

Source/WebCore/page/DOMSecurityPolicy.cpp

 1/*
 2 * Copyright (C) 2012 Google, Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "DOMSecurityPolicy.h"
 28
 29#include "ContentSecurityPolicy.h"
 30#include "ContextDestructionObserver.h"
 31#include "DOMStringList.h"
 32#include "Frame.h"
 33#include "ScriptExecutionContext.h"
 34#include <wtf/text/TextPosition.h>
 35#include <wtf/text/WTFString.h>
 36
 37
 38namespace WebCore {
 39
 40namespace {
 41
 42bool isPolicyActiveInContext(ScriptExecutionContext* context)
 43{
 44 // If the ScriptExecutionContext has been destroyed, there's no active policy.
 45 if (!context)
 46 return false;
 47
 48 return context->contentSecurityPolicy()->isActive();
 49}
 50
 51template<bool (ContentSecurityPolicy::*allowWithURL)(const KURL&, ContentSecurityPolicy::ReportingStatus) const>
 52bool isAllowedWithURL(ScriptExecutionContext* context, String url)
 53{
 54 if (!isPolicyActiveInContext(context))
 55 return true;
 56
 57 KURL parsedURL = context->completeURL(url);
 58 if (!parsedURL.isValid())
 59 return false; // FIXME: Figure out how to throw a JavaScript error.
 60
 61 return (context->contentSecurityPolicy()->*allowWithURL)(parsedURL, ContentSecurityPolicy::SuppressReport);
 62}
 63
 64template<bool (ContentSecurityPolicy::*allowWithContext)(const String&, const WTF::OrdinalNumber&, ContentSecurityPolicy::ReportingStatus) const>
 65bool isAllowed(ScriptExecutionContext* context)
 66{
 67 if (!isPolicyActiveInContext(context))
 68 return true;
 69
 70 return (context->contentSecurityPolicy()->*allowWithContext)(KURL(), WTF::OrdinalNumber::beforeFirst(), ContentSecurityPolicy::SuppressReport);
 71}
 72
 73} // namespace
 74
 75DOMSecurityPolicy::DOMSecurityPolicy(ScriptExecutionContext* context)
 76 : ContextDestructionObserver(context)
 77{
 78}
 79
 80DOMSecurityPolicy::~DOMSecurityPolicy()
 81{
 82}
 83
 84bool DOMSecurityPolicy::isActive() const
 85{
 86 return isPolicyActiveInContext(scriptExecutionContext());
 87}
 88
 89PassRefPtr<DOMStringList> DOMSecurityPolicy::reportURIs() const
 90{
 91 RefPtr<DOMStringList> result = DOMStringList::create();
 92
 93 if (isActive())
 94 scriptExecutionContext()->contentSecurityPolicy()->gatherReportURIs(*result.get());
 95
 96 return result.release();
 97}
 98
 99bool DOMSecurityPolicy::allowsInlineScript() const
 100{
 101 return isAllowed<&ContentSecurityPolicy::allowInlineScript>(scriptExecutionContext());
 102}
 103
 104bool DOMSecurityPolicy::allowsInlineStyle() const
 105{
 106 return isAllowed<&ContentSecurityPolicy::allowInlineStyle>(scriptExecutionContext());
 107}
 108
 109bool DOMSecurityPolicy::allowsEval() const
 110{
 111 if (!isActive())
 112 return true;
 113
 114 return scriptExecutionContext()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport);
 115}
 116
 117
 118bool DOMSecurityPolicy::allowsConnectionTo(String url) const
 119{
 120 return isAllowedWithURL<&ContentSecurityPolicy::allowConnectToSource>(scriptExecutionContext(), url);
 121}
 122
 123bool DOMSecurityPolicy::allowsFontFrom(String url) const
 124{
 125 return isAllowedWithURL<&ContentSecurityPolicy::allowFontFromSource>(scriptExecutionContext(), url);
 126}
 127
 128bool DOMSecurityPolicy::allowsFrameFrom(String url) const
 129{
 130 return isAllowedWithURL<&ContentSecurityPolicy::allowChildFrameFromSource>(scriptExecutionContext(), url);
 131}
 132
 133bool DOMSecurityPolicy::allowsImageFrom(String url) const
 134{
 135 return isAllowedWithURL<&ContentSecurityPolicy::allowImageFromSource>(scriptExecutionContext(), url);
 136}
 137
 138bool DOMSecurityPolicy::allowsMediaFrom(String url) const
 139{
 140 return isAllowedWithURL<&ContentSecurityPolicy::allowMediaFromSource>(scriptExecutionContext(), url);
 141}
 142
 143bool DOMSecurityPolicy::allowsObjectFrom(String url) const
 144{
 145 return isAllowedWithURL<&ContentSecurityPolicy::allowObjectFromSource>(scriptExecutionContext(), url);
 146}
 147
 148bool DOMSecurityPolicy::allowsScriptFrom(String url) const
 149{
 150 return isAllowedWithURL<&ContentSecurityPolicy::allowScriptFromSource>(scriptExecutionContext(), url);
 151}
 152
 153bool DOMSecurityPolicy::allowsStyleFrom(String url) const
 154{
 155 return isAllowedWithURL<&ContentSecurityPolicy::allowStyleFromSource>(scriptExecutionContext(), url);
 156}
 157
 158} // namespace WebCore

Source/WebCore/page/DOMSecurityPolicy.h

 1/*
 2 * Copyright (C) 2011 Google, Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef DOMSecurityPolicy_h
 27#define DOMSecurityPolicy_h
 28
 29#include "ContextDestructionObserver.h"
 30#include <wtf/PassOwnPtr.h>
 31#include <wtf/RefCounted.h>
 32#include <wtf/Vector.h>
 33#include <wtf/text/WTFString.h>
 34
 35namespace WebCore {
 36
 37class ContentSecurityPolicy;
 38class DOMStringList;
 39class Frame;
 40
 41class DOMSecurityPolicy : public RefCounted<DOMSecurityPolicy>, public ContextDestructionObserver {
 42public:
 43 static PassRefPtr<DOMSecurityPolicy> create(ScriptExecutionContext* context)
 44 {
 45 return adoptRef(new DOMSecurityPolicy(context));
 46 }
 47 ~DOMSecurityPolicy();
 48
 49 bool isActive() const;
 50 PassRefPtr<DOMStringList> reportURIs() const;
 51
 52 bool allowsInlineScript() const;
 53 bool allowsInlineStyle() const;
 54 bool allowsEval() const;
 55
 56 bool allowsConnectionTo(String url) const;
 57 bool allowsFontFrom(String url) const;
 58 bool allowsFrameFrom(String url) const;
 59 bool allowsImageFrom(String url) const;
 60 bool allowsMediaFrom(String url) const;
 61 bool allowsObjectFrom(String url) const;
 62 bool allowsScriptFrom(String url) const;
 63 bool allowsStyleFrom(String url) const;
 64
 65private:
 66 explicit DOMSecurityPolicy(ScriptExecutionContext*);
 67};
 68
 69}
 70
 71#endif

Source/WebCore/page/DOMSecurityPolicy.idl

 1/*
 2 * Copyright (C) 2012 Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 23 */
 24
 25module core {
 26
 27 interface [
 28 Conditional=CSP_NEXT,
 29 OmitConstructor,
 30 InterfaceName=securityPolicy
 31 ] DOMSecurityPolicy {
 32 readonly attribute DOMStringList reportURIs;
 33
 34 boolean isActive();
 35
 36 boolean allowsConnectionTo(in DOMString url);
 37 boolean allowsFontFrom(in DOMString url);
 38 boolean allowsFrameFrom(in DOMString url);
 39 boolean allowsImageFrom(in DOMString url);
 40 boolean allowsMediaFrom(in DOMString url);
 41 boolean allowsObjectFrom(in DOMString url);
 42 boolean allowsScriptFrom(in DOMString url);
 43 boolean allowsStyleFrom(in DOMString url);
 44
 45 boolean allowsEval();
 46 boolean allowsInlineScript();
 47 boolean allowsInlineStyle();
 48 };
 49
 50}
 51

LayoutTests/ChangeLog

 12012-07-19 Mike West <mkwst@chromium.org>
 2
 3 Implement the experimental Content Security Policy script interface.
 4 https://bugs.webkit.org/show_bug.cgi?id=91707
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto-expected.txt: Added.
 9 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html: Added.
 10 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval-expected.txt: Added.
 11 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html: Added.
 12 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom-expected.txt: Added.
 13 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html: Added.
 14 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom-expected.txt: Added.
 15 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html: Added.
 16 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom-expected.txt: Added.
 17 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html: Added.
 18 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom-expected.txt: Added.
 19 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html: Added.
 20 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom-expected.txt: Added.
 21 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html: Added.
 22 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom-expected.txt: Added.
 23 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html: Added.
 24 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom-expected.txt: Added.
 25 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html: Added.
 26 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive-expected.txt: Added.
 27 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html: Added.
 28 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi-expected.txt: Added.
 29 * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html: Added.
 30 * http/tests/security/contentSecurityPolicy/resources/securitypolicy-tests-base.js: Added.
 31 (log):
 32 (injectPolicy):
 33
1342012-07-19 Zan Dobersek <zandobersek@gmail.com>
235
336 Unreviewed GTK gardening, adding missing baseline required after r122761.

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto-expected.txt

 1PASS connection is allowed when no policy exists.
 2PASS connection is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsConnectionTo('http://example.com/'))
 7 log('PASS connection is allowed when no policy exists.');
 8 else
 9 log('FAIL connection is not allowed when no policy exists.');
 10
 11
 12 injectPolicy("connect-src http://notexample.com/;");
 13
 14 if (!document.SecurityPolicy.allowsConnectionTo('http://example.com/'))
 15 log('PASS connection is not allowed when policy exists.');
 16 else
 17 log('FAIL connection is allowed when policy exists.');
 18 </script>
 19 </body>
 20</html>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval-expected.txt

 1PASS eval is allowed when no policy exists.
 2PASS eval is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsEval())
 7 log('PASS eval is allowed when no policy exists.');
 8 else
 9 log('FAIL eval is not allowed when no policy exists.');
 10
 11 injectPolicy("script-src 'unsafe-inline';");
 12
 13 if (!document.SecurityPolicy.allowsEval())
 14 log('PASS eval is not allowed when policy exists.');
 15 else
 16 log('FAIL eval is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom-expected.txt

 1PASS font is allowed when no policy exists.
 2PASS font is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsFontFrom('http://example.com/'))
 7 log('PASS font is allowed when no policy exists.');
 8 else
 9 log('FAIL font is not allowed when no policy exists.');
 10
 11 injectPolicy("font-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsFontFrom('http://example.com/'))
 14 log('PASS font is not allowed when policy exists.');
 15 else
 16 log('PASS font is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom-expected.txt

 1PASS frame is allowed when no policy exists.
 2PASS frame is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsFrameFrom('http://example.com/'))
 7 log('PASS frame is allowed when no policy exists.');
 8 else
 9 log('FAIL frame is not allowed when no policy exists.');
 10
 11 injectPolicy("frame-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsFrameFrom('http://example.com/'))
 14 log('PASS frame is not allowed when policy exists.');
 15 else
 16 log('FAIL frame is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom-expected.txt

 1PASS image is allowed when no policy exists.
 2PASS image is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsImageFrom('http://example.com/'))
 7 log('PASS image is allowed when no policy exists.');
 8 else
 9 log('FAIL image is not allowed when no policy exists.');
 10
 11 injectPolicy("img-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsImageFrom('http://example.com/'))
 14 log('PASS image is not allowed when policy exists.');
 15 else
 16 log('FAIL image is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom-expected.txt

 1PASS media is allowed when no policy exists.
 2PASS media is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsMediaFrom('http://example.com/'))
 7 log('PASS media is allowed when no policy exists.');
 8 else
 9 log('FAIL media is not allowed when no policy exists.');
 10
 11 injectPolicy("media-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsMediaFrom('http://example.com/'))
 14 log('PASS media is not allowed when policy exists.');
 15 else
 16 log('FAIL media is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom-expected.txt

 1PASS object is allowed when no policy exists.
 2PASS object is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsObjectFrom('http://example.com/'))
 7 log('PASS object is allowed when no policy exists.');
 8 else
 9 log('FAIL object is not allowed when no policy exists.');
 10
 11 injectPolicy("object-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsObjectFrom('http://example.com/'))
 14 log('PASS object is not allowed when policy exists.');
 15 else
 16 log('FAIL object is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom-expected.txt

 1PASS script is allowed when no policy exists.
 2PASS script is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsScriptFrom('http://example.com/'))
 7 log('PASS script is allowed when no policy exists.');
 8 else
 9 log('FAIL script is not allowed when no policy exists.');
 10
 11 injectPolicy("script-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsScriptFrom('http://example.com/'))
 14 log('PASS script is not allowed when policy exists.');
 15 else
 16 log('FAIL script is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>
 20

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom-expected.txt

 1PASS style is allowed when no policy exists.
 2PASS style is not allowed when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.allowsStyleFrom('http://example.com/'))
 7 log('PASS style is allowed when no policy exists.');
 8 else
 9 log('FAIL style is not allowed when no policy exists.');
 10
 11 injectPolicy("style-src http://notexample.com/;");
 12
 13 if (!document.SecurityPolicy.allowsStyleFrom('http://example.com/'))
 14 log('PASS style is not allowed when policy exists.');
 15 else
 16 log('FAIL style is allowed when policy exists.');
 17 </script>
 18 </body>
 19</html>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive-expected.txt

 1PASS document.SecurityPolicy.active is false when no policy exists.
 2PASS document.SecurityPolicy.active is true when policy exists.
 3

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (!document.SecurityPolicy.isActive())
 7 log('PASS document.SecurityPolicy.active is false when no policy exists.');
 8 else
 9 log('FAIL document.SecurityPolicy.active is truw when no policy exists.');
 10
 11 injectPolicy("script-src 'unsafe-inline';");
 12
 13 if (document.SecurityPolicy.isActive())
 14 log('PASS document.SecurityPolicy.active is true when policy exists.');
 15 else
 16 log('FAIL document.SecurityPolicy.active is false when policy exists.');
 17 </script>
 18 </body>
 19</html>

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi-expected.txt

 1PASS document.SecurityPolicy.reportURIs has length 0 when no policy exists.
 2PASS document.SecurityPolicy.reportURIs has length 1 when policy exists.
 3PASS document.SecurityPolicy.reportURIs[0] is correct.
 4

LayoutTests/http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html

 1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 2<html>
 3 <body>
 4 <script src="../resources/securitypolicy-tests-base.js"></script>
 5 <script>
 6 if (document.SecurityPolicy.reportURIs.length === 0)
 7 log('PASS document.SecurityPolicy.reportURIs has length 0 when no policy exists.');
 8 else
 9 log('FAIL document.SecurityPolicy.reportURIs has length ' + document.SecurityPolicy.reportURIs.length + ' when no policy exists.');
 10
 11 injectPolicy('report-uri http://example.com/');
 12
 13 if (document.SecurityPolicy.reportURIs.length === 1)
 14 log('PASS document.SecurityPolicy.reportURIs has length 1 when policy exists.');
 15 else
 16 log('FAIL document.SecurityPolicy.reportURIs has length ' + document.SecurityPolicy.reportURIs.length + ' when policy exists.');
 17
 18 if (document.SecurityPolicy.reportURIs[0] === "http://example.com/")
 19 log('PASS document.SecurityPolicy.reportURIs[0] is correct.');
 20 else
 21 log('FAIL document.SecurityPolicy.reportURIs[0] is ' + document.SecurityPolicy.reportURIs[0] + ' (should be `http://example.com/`).');
 22 </script>
 23 </body>
 24</html>

LayoutTests/http/tests/security/contentSecurityPolicy/resources/securitypolicy-tests-base.js

 1if (window.layoutTestController)
 2 layoutTestController.dumpAsText();
 3
 4function log(msg) {
 5 var txt = document.createTextNode(msg);
 6 document.querySelector('body').appendChild(txt);
 7 document.querySelector('body').appendChild(document.createElement('br'));
 8}
 9
 10function injectPolicy(policy) {
 11 var meta = document.createElement('meta');
 12 meta.setAttribute('http-equiv', 'X-WebKit-CSP');
 13 meta.setAttribute('content', policy);
 14 document.head.appendChild(meta);
 15}
 16
 17if (!document.SecurityPolicy)
 18 log('FAIL document.securityPolicy is not defined.')
 19