WebKit
WebKit copied to clipboard
Implement enforcement of `require-trusted-types-for` CSP directive
49d817ecf413c20c5a08507428bd39073c48a886
Implement enforcement of `require-trusted-types-for` CSP directive https://bugs.webkit.org/show_bug.cgi?id=267685 Reviewed by NOBODY (OOPS!). This patch implements the StringContext idl attribute to check the `require-trusted-types-for` CSP and enforce trusted types accordingly. This patch also makes use of the StringContext IDL attribute on an initial set of sinks. More complicated sinks such as setAttribute, execCommand, eval and timer functions will be addressed in follow ups. Spec: https://w3c.github.io/trusted-types/dist/spec/#integrations * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/content-security-policy/reporting/report-clips-sample.https-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/HTMLElement-generic-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/HTMLScriptElement-internal-slot-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/WorkerGlobalScope-importScripts-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-DOMParser-parseFromString-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-write-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-outerHTML-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-HTMLElement-generic-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Range-createContextualFragment-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-text-node-insertion-into-script-element-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/default-policy-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/default-policy-report-only-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/empty-default-policy-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/empty-default-policy-report-only-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/no-require-trusted-types-for-report-only-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/require-trusted-types-for-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/require-trusted-types-for-report-only-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-createHTMLDocument-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-report-only-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-reporting-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-source-file-path-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-svg-script-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/worker-constructor.https-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/bindings/IDLTypes.h: * Source/WebCore/bindings/js/JSDOMConvertStrings.cpp: (WebCore::getTrustedTypeCompliantString): * Source/WebCore/bindings/js/JSDOMConvertStrings.h: (WebCore::Converter<IDLStringContextTrustedHTMLAdaptor<T>>::convert): (WebCore::JSConverter<IDLStringContextTrustedHTMLAdaptor<T>>::convert): (WebCore::Converter<IDLLegacyNullToEmptyStringStringContextTrustedHTMLAdaptor<T>>::convert): (WebCore::JSConverter<IDLLegacyNullToEmptyStringStringContextTrustedHTMLAdaptor<T>>::convert): (WebCore::Converter<IDLStringContextTrustedScriptAdaptor<T>>::convert): (WebCore::JSConverter<IDLStringContextTrustedScriptAdaptor<T>>::convert): (WebCore::Converter<IDLLegacyNullToEmptyStringStringContextTrustedScriptAdaptor<T>>::convert): (WebCore::JSConverter<IDLLegacyNullToEmptyStringStringContextTrustedScriptAdaptor<T>>::convert): (WebCore::Converter<IDLStringContextTrustedScriptURLAdaptor<T>>::convert): (WebCore::JSConverter<IDLStringContextTrustedScriptURLAdaptor<T>>::convert): (WebCore::Converter<IDLLegacyNullToEmptyStringStringContextTrustedScriptURLAdaptor<T>>::convert): (WebCore::JSConverter<IDLLegacyNullToEmptyStringStringContextTrustedScriptURLAdaptor<T>>::convert): (WebCore::Converter<IDLAtomStringStringContextTrustedHTMLAdaptor<T>>::convert): (WebCore::JSConverter<IDLAtomStringStringContextTrustedHTMLAdaptor<T>>::convert): (WebCore::Converter<IDLAtomStringStringContextTrustedScriptAdaptor<T>>::convert): (WebCore::JSConverter<IDLAtomStringStringContextTrustedScriptAdaptor<T>>::convert): (WebCore::Converter<IDLAtomStringStringContextTrustedScriptURLAdaptor<T>>::convert): (WebCore::JSConverter<IDLAtomStringStringContextTrustedScriptURLAdaptor<T>>::convert): * Source/WebCore/bindings/scripts/CodeGeneratorJS.pm: (GenerateParametersCheck): (IsAnnotatedType): (GetAnnotatedIDLType): (JSValueToNative): * Source/WebCore/bindings/scripts/IDLAttributes.json: * Source/WebCore/bindings/scripts/test/BindingTestGlobalConstructors.idl: * Source/WebCore/bindings/scripts/test/JS/JSTestGlobalObject.cpp: (WebCore::jsTestGlobalObject_TestStringContextConstructorGetter): (WebCore::JSC_DEFINE_CUSTOM_GETTER): * Source/WebCore/bindings/scripts/test/JS/JSTestStringContext.cpp: Added. (WebCore::JSTestStringContextDOMConstructor::prototypeForStructure): (WebCore::JSTestStringContextDOMConstructor::initializeProperties): (WebCore::JSTestStringContextPrototype::finishCreation): (WebCore::JSTestStringContext::JSTestStringContext): (WebCore::JSTestStringContext::createPrototype): (WebCore::JSTestStringContext::prototype): (WebCore::JSTestStringContext::getConstructor): (WebCore::JSTestStringContext::destroy): (WebCore::JSC_DEFINE_CUSTOM_GETTER): (WebCore::jsTestStringContext_attributeWithStringContextTrustedHTMLGetter): (WebCore::setJSTestStringContext_attributeWithStringContextTrustedHTMLSetter): (WebCore::JSC_DEFINE_CUSTOM_SETTER): (WebCore::jsTestStringContext_attributeWithStringContextTrustedScriptGetter): (WebCore::setJSTestStringContext_attributeWithStringContextTrustedScriptSetter): (WebCore::jsTestStringContext_attributeWithStringContextTrustedScriptURLGetter): (WebCore::setJSTestStringContext_attributeWithStringContextTrustedScriptURLSetter): (WebCore::jsTestStringContext_attributeWithStringContextTrustedHTMLAndLegacyNullToEmptyStringGetter): (WebCore::setJSTestStringContext_attributeWithStringContextTrustedHTMLAndLegacyNullToEmptyStringSetter): (WebCore::jsTestStringContext_attributeWithStringContextTrustedScriptAndLegacyNullToEmptyStringGetter): (WebCore::setJSTestStringContext_attributeWithStringContextTrustedScriptAndLegacyNullToEmptyStringSetter): (WebCore::jsTestStringContext_attributeWithStringContextTrustedScriptURLAndLegacyNullToEmptyStringGetter): (WebCore::setJSTestStringContext_attributeWithStringContextTrustedScriptURLAndLegacyNullToEmptyStringSetter): (WebCore::jsTestStringContext_reflectedAttributeWithStringContextTrustedHTMLGetter): (WebCore::setJSTestStringContext_reflectedAttributeWithStringContextTrustedHTMLSetter): (WebCore::jsTestStringContext_reflectedAttributeWithStringContextTrustedScriptGetter): (WebCore::setJSTestStringContext_reflectedAttributeWithStringContextTrustedScriptSetter): (WebCore::jsTestStringContext_reflectedAttributeWithStringContextTrustedScriptURLGetter): (WebCore::setJSTestStringContext_reflectedAttributeWithStringContextTrustedScriptURLSetter): (WebCore::jsTestStringContext_reflectedUrlAttributeWithStringContextTrustedHTMLGetter): (WebCore::setJSTestStringContext_reflectedUrlAttributeWithStringContextTrustedHTMLSetter): (WebCore::jsTestStringContext_reflectedUrlAttributeWithStringContextTrustedScriptGetter): (WebCore::setJSTestStringContext_reflectedUrlAttributeWithStringContextTrustedScriptSetter): (WebCore::jsTestStringContext_reflectedUrlAttributeWithStringContextTrustedScriptURLGetter): (WebCore::setJSTestStringContext_reflectedUrlAttributeWithStringContextTrustedScriptURLSetter): (WebCore::jsTestStringContextPrototypeFunction_methodWithStringContextTrustedHTMLBody): (WebCore::JSC_DEFINE_HOST_FUNCTION): (WebCore::jsTestStringContextPrototypeFunction_methodWithStringContextTrustedScriptBody): (WebCore::jsTestStringContextPrototypeFunction_methodWithStringContextTrustedScriptURLBody): (WebCore::jsTestStringContextPrototypeFunction_methodWithStringContextTrustedHTMLAndLegacyNullToEmptyStringBody): (WebCore::jsTestStringContextPrototypeFunction_methodWithStringContextTrustedScriptAndLegacyNullToEmptyStringBody): (WebCore::jsTestStringContextPrototypeFunction_methodWithStringContextTrustedScriptURLAndLegacyNullToEmptyStringBody): (WebCore::JSTestStringContext::subspaceForImpl): (WebCore::JSTestStringContext::analyzeHeap): (WebCore::JSTestStringContextOwner::isReachableFromOpaqueRoots): (WebCore::JSTestStringContextOwner::finalize): (WebCore::toJSNewlyCreated): (WebCore::toJS): (WebCore::JSTestStringContext::toWrapped): * Source/WebCore/bindings/scripts/test/JS/JSTestStringContext.h: Added. (WebCore::JSTestStringContext::create): (WebCore::JSTestStringContext::createStructure): (WebCore::JSTestStringContext::subspaceFor): (WebCore::wrapperOwner): (WebCore::wrapperKey): (WebCore::toJS): (WebCore::toJSNewlyCreated): * Source/WebCore/bindings/scripts/test/SupplementalDependencies.dep: * Source/WebCore/bindings/scripts/test/TestStringContext.idl: Added. * Source/WebCore/dom/Document+HTML.idl: * Source/WebCore/dom/Document.idl: * Source/WebCore/dom/Element+DOMParsing.idl: * Source/WebCore/dom/InnerHTML.idl: * Source/WebCore/dom/Range+DOMParsing.idl: * Source/WebCore/dom/TrustedType.cpp: Added. (WebCore::TrustedTypeVisitor::operator()): (WebCore::trustedTypeToString): (WebCore::trustedTypeToCallbackName): (WebCore::processValueWithDefaultPolicy): (WebCore::getTrustedTypeCompliantString): * Source/WebCore/dom/TrustedType.h: Copied from Source/WebCore/workers/Worker.idl. * Source/WebCore/dom/TrustedTypePolicy.cpp: (WebCore::TrustedTypePolicy::createHTML): (WebCore::TrustedTypePolicy::createScript): (WebCore::TrustedTypePolicy::createScriptURL): (WebCore::TrustedTypePolicy::getPolicyValue): * Source/WebCore/dom/TrustedTypePolicy.h: * Source/WebCore/html/HTMLEmbedElement.idl: * Source/WebCore/html/HTMLIFrameElement.idl: * Source/WebCore/html/HTMLObjectElement.idl: * Source/WebCore/html/HTMLScriptElement.idl: * Source/WebCore/page/csp/ContentSecurityPolicy.cpp: (WebCore::ContentSecurityPolicy::requireTrustedTypesForSinkGroup const): (WebCore::ContentSecurityPolicy::allowMissingTrustedTypesForSinkGroup const): (WebCore::ContentSecurityPolicy::reportViolation const): * Source/WebCore/page/csp/ContentSecurityPolicy.h: * Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp: (WebCore::ContentSecurityPolicyDirectiveList::shouldReportSample const): * Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.h: (WebCore::ContentSecurityPolicyDirectiveList::requiresTrustedTypesForScript const): * Source/WebCore/workers/Worker.idl: * Source/WebCore/workers/WorkerGlobalScope.idl: * Source/WebCore/workers/service/ServiceWorkerContainer.idl: * Source/WebCore/workers/shared/SharedWorker.idl: * Source/WebCore/xml/DOMParser.idl:
https://github.com/WebKit/WebKit/commit/49d817ecf413c20c5a08507428bd39073c48a886
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/0ddfb1a5af8f2f35d52a94911c5bc1ae7c5c7127)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/a87a721eb20db7e6373ad6bba197d950e09f4c68)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/3291302f627b468d9c76b91a8213dd50e471dcaf)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/ad81fce56faaaf31f000919560bc55e19f02208a)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/4fa428eac2c4897296efa1039ab0627cfe3a1d85)
EWS run on current version of this PR (hash https://github.com/WebKit/WebKit/commit/f953c9ba846218f909c16da59d4ab64cb5ec7480)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/f953c9ba846218f909c16da59d4ab64cb5ec7480)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/b7974551423968fadb499b2dc61b668994d2a7b0)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/2057ffd18936b86f69f5ff85aa46b7f7aa10063a)
Starting EWS tests for https://github.com/WebKit/WebKit/commit/e6ad96c879c9401b5b23218097d19c6338e33a55. Live statuses available at the PR page, https://github.com/WebKit/WebKit/pull/23412
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/e6ad96c879c9401b5b23218097d19c6338e33a55)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/240e525846a872515b76ee362f773bbb7a25606c)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/b9d1c44aaba4f010c75f970273cddb7fe9581cd0)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/bfdf2af7a04cea540966c56c963d08b8b17d60f1)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/8183bf5aeb31217b0009b76b77361aa52ef47e1d)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/c73190eca0751aa49f5f922f3f6e85cf71d75e17)
EWS run on current version of this PR (hash https://github.com/WebKit/WebKit/commit/1bd1556a86c680c6e25c3fa7d34c312f1df13636)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/1bd1556a86c680c6e25c3fa7d34c312f1df13636)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/4b6ce8295e1dcfd2483c9bbf9ca45d102e005c23)
Starting EWS tests for https://github.com/WebKit/WebKit/commit/a40c9d91d00b013168356f6e4ffeb64eb40a73b0. Live statuses available at the PR page, https://github.com/WebKit/WebKit/pull/23412
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/a40c9d91d00b013168356f6e4ffeb64eb40a73b0)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/719c53da1e895cf63c40fce3798406c3189dda3f)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/cd0ce4e621e6097efd7cc7ca6a53f1cb0725651d)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/78aec8804f45de62b5ff600e2d45872950c1d7d7)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/209e880f7b52a3a218f1368c97ed92c61c95bfe7)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/28ca4cf354950962172dbb05dcda5efa8b4c0b11)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/9cef2615fcfe5f38a7a912805bd624943c5320ca)
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/98035d4495d990ea6f4c5e134743b9ded36b67a0)
@youennf this should be ready for another look over, so just giving a nudge
EWS run on previous version of this PR (hash https://github.com/WebKit/WebKit/commit/4117d54cad6ff40ec2247880a56fd456b6524cde)