-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement enforcement of require-trusted-types-for CSP directive
#23412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement enforcement of require-trusted-types-for CSP directive
#23412
Conversation
|
EWS run on previous version of this PR (hash 0ddfb1a) |
0ddfb1a to
a87a721
Compare
|
EWS run on previous version of this PR (hash a87a721) |
a87a721 to
3291302
Compare
|
EWS run on previous version of this PR (hash 3291302) |
3291302 to
ad81fce
Compare
|
EWS run on previous version of this PR (hash ad81fce) |
ad81fce to
4fa428e
Compare
|
EWS run on previous version of this PR (hash 4fa428e) |
4fa428e to
f953c9b
Compare
|
EWS run on current version of this PR (hash f953c9b) |
|
EWS run on previous version of this PR (hash f953c9b)
|
require-trusted-types-for CSP directive
require-trusted-types-for CSP directivef953c9b to
b797455
Compare
require-trusted-types-for CSP directive
|
EWS run on previous version of this PR (hash b797455)
|
4117d54 to
9a795ba
Compare
|
EWS run on previous version of this PR (hash 9a795ba)
|
darinadler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass and found some things to improve.
| webkit.org/b/261849 imported/w3c/web-platform-tests/css/css-scroll-anchoring/start-edge-in-block-layout-direction.html [ Skip ] | ||
|
|
||
| # Trusted Types aren't implemented yet | ||
| # Trusted Types aren't fully implemented yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it best to skip these tests instead of expecting failures? Normally we would only want to skip a test if it hangs or runs very slowly. It’s much better to just expect a failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all of these are timeouts because they timeout in the failure case.
| ExceptionOr<Ref<TrustedHTML>> createHTML(const String& input, FixedVector<JSC::Strong<JSC::Unknown>>&&); | ||
| ExceptionOr<Ref<TrustedScript>> createScript(const String& input, FixedVector<JSC::Strong<JSC::Unknown>>&&); | ||
| ExceptionOr<Ref<TrustedScriptURL>> createScriptURL(const String& input, FixedVector<JSC::Strong<JSC::Unknown>>&&); | ||
| ExceptionOr<String> getPolicyValue(const TrustedType trustedTypeName, const String& input, FixedVector<JSC::Strong<JSC::Unknown>>&&, bool throwIfMissing = true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should just be TrustedType not const TrustedType.
We try to avoid mystery bool arguments like this throwIfMissing one. Can we find a way to not have that, perhaps by having more than one function? I think one function can return null string if missing and the one that throws if missing can just call the other and post process it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with returning nullString and post processing is that the callbacks themselves can return null and they shouldn't throw in this situation.
I'll make it a boolean enum instead so it's more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can split this into two separate functions. Whether internally you want to use a bool argument to a common function or can find a way to have one call the other is something we can tinker with. I am almost certain you can have one call the other but I can propose a specific way once I see your revised patch. For example if you can distinguish the specific exception you can convert the exception to a null string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing something like in a GetPolicyValueForProcessDefault function could work? But it doesn't feel great, unfortunately the ExceptionCode alone isn't enough to distinguish because TypeErrors are thrown in other cases (such as from userland code)
auto policyValue = getPolicyValue(trustedTypeName, input, WTFMove(arguments));
if (policyValue.hasException()) {
if (policyValue.exception().message().contains("TrustedTypePolicyOptions did not specify"_s))
return String(nullString());
}
return policyValue;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes clearly wrong if it needs to check the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to an enum so it's at least not a magic bool.
9a795ba to
192efe1
Compare
|
EWS run on previous version of this PR (hash 192efe1)
|
|
@darinadler Thanks for the review I've addressed or replied to all your comments |
192efe1 to
49d817e
Compare
|
EWS run on previous version of this PR (hash 49d817e)
|
49d817e to
8b6337d
Compare
|
EWS run on previous version of this PR (hash 8b6337d)
|
8b6337d to
6f76254
Compare
|
EWS run on current version of this PR (hash 6f76254) |
|
Safe-Merge-Queue: Build #13879. |
https://bugs.webkit.org/show_bug.cgi?id=267685 Reviewed by Darin Adler. 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::trustedTypeCompliantString): * 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::trustedTypeCompliantString): * 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: Canonical link: https://commits.webkit.org/275607@main
6f76254 to
caf4cd7
Compare
|
Committed 275607@main (caf4cd7): https://commits.webkit.org/275607@main Reviewed commits have been landed. Closing PR #23412 and removing active labels. |
🧪 bindings
caf4cd7
6f76254