Diff
Modified: trunk/Source/WebCore/dom/Element.cpp (295746 => 295747)
--- trunk/Source/WebCore/dom/Element.cpp 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Source/WebCore/dom/Element.cpp 2022-06-22 20:11:59 UTC (rev 295747)
@@ -2315,7 +2315,7 @@
return attribute.name().namespaceURI().isNull() && attribute.name().localName().startsWith("on"_s);
}
-bool Element::isJavaScriptURLAttribute(const Attribute& attribute) const
+bool Element::attributeContainsJavascriptURL(const Attribute& attribute) const
{
return isURLAttribute(attribute) && WTF::protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(attribute.value()));
}
@@ -2324,7 +2324,7 @@
{
attributeVector.removeAllMatching([this](auto& attribute) -> bool {
return this->isEventHandlerAttribute(attribute)
- || this->isJavaScriptURLAttribute(attribute)
+ || this->attributeContainsJavascriptURL(attribute)
|| this->isHTMLContentAttribute(attribute);
});
}
Modified: trunk/Source/WebCore/dom/Element.h (295746 => 295747)
--- trunk/Source/WebCore/dom/Element.h 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Source/WebCore/dom/Element.h 2022-06-22 20:11:59 UTC (rev 295747)
@@ -294,7 +294,7 @@
void parserSetAttributes(const Vector<Attribute>&);
bool isEventHandlerAttribute(const Attribute&) const;
- bool isJavaScriptURLAttribute(const Attribute&) const;
+ virtual bool attributeContainsJavascriptURL(const Attribute&) const;
// Remove attributes that might introduce scripting from the vector leaving the element unchanged.
void stripScriptingAttributes(Vector<Attribute>&) const;
Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (295746 => 295747)
--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp 2022-06-22 20:11:59 UTC (rev 295747)
@@ -238,7 +238,7 @@
}
if (element->hasAttributes()) {
for (auto& attribute : element->attributesIterator()) {
- if (element->isEventHandlerAttribute(attribute) || element->isJavaScriptURLAttribute(attribute))
+ if (element->isEventHandlerAttribute(attribute) || element->attributeContainsJavascriptURL(attribute))
attributesToRemove.append({ element.copyRef(), attribute.name() });
}
}
Modified: trunk/Source/WebCore/editing/markup.cpp (295746 => 295747)
--- trunk/Source/WebCore/editing/markup.cpp 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Source/WebCore/editing/markup.cpp 2022-06-22 20:11:59 UTC (rev 295747)
@@ -556,7 +556,7 @@
// We'll handle the style attribute separately, below.
if (attribute.name() == styleAttr && shouldOverrideStyleAttr)
continue;
- if (element.isEventHandlerAttribute(attribute) || element.isJavaScriptURLAttribute(attribute))
+ if (element.isEventHandlerAttribute(attribute) || element.attributeContainsJavascriptURL(attribute))
continue;
#if ENABLE(DATA_DETECTION)
if (replacementType == SpanReplacementType::DataDetector && DataDetection::isDataDetectorAttribute(attribute.name()))
Modified: trunk/Source/WebCore/svg/SVGAnimationElement.cpp (295746 => 295747)
--- trunk/Source/WebCore/svg/SVGAnimationElement.cpp 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Source/WebCore/svg/SVGAnimationElement.cpp 2022-06-22 20:11:59 UTC (rev 295747)
@@ -31,6 +31,7 @@
#include "CSSPropertyParser.h"
#include "Document.h"
#include "FloatConversion.h"
+#include "HTMLParserIdioms.h"
#include "RenderObject.h"
#include "SVGAnimateColorElement.h"
#include "SVGAnimateElement.h"
@@ -147,6 +148,21 @@
return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
}
+bool SVGAnimationElement::attributeContainsJavascriptURL(const Attribute& attribute) const
+{
+ if (attribute.name() == SVGNames::fromAttr || attribute.name() == SVGNames::toAttr)
+ return WTF::protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(attribute.value()));
+
+ if (attribute.name() == SVGNames::valuesAttr) {
+ for (auto innerValue : StringView(attribute.value()).split(';')) {
+ if (WTF::protocolIsJavaScript(innerValue.stripWhiteSpace()))
+ return true;
+ }
+ return false;
+ }
+ return Element::attributeContainsJavascriptURL(attribute);
+}
+
void SVGAnimationElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == SVGNames::valuesAttr) {
Modified: trunk/Source/WebCore/svg/SVGAnimationElement.h (295746 => 295747)
--- trunk/Source/WebCore/svg/SVGAnimationElement.h 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Source/WebCore/svg/SVGAnimationElement.h 2022-06-22 20:11:59 UTC (rev 295747)
@@ -88,6 +88,7 @@
virtual void resetAnimation();
static bool isSupportedAttribute(const QualifiedName&);
+ bool attributeContainsJavascriptURL(const Attribute&) const final;
void parseAttribute(const QualifiedName&, const AtomString&) override;
void svgAttributeChanged(const QualifiedName&) override;
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewConfiguration.mm (295746 => 295747)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewConfiguration.mm 2022-06-22 19:59:07 UTC (rev 295746)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewConfiguration.mm 2022-06-22 20:11:59 UTC (rev 295747)
@@ -172,3 +172,25 @@
NSString *bodyHTML = [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"];
EXPECT_WK_STREQ(bodyHTML, @"<table></table>");
}
+
+TEST(WebKit, ConfigurationDisableJavaScriptSVGAnimateElement)
+{
+ auto configuration = adoptNS([WKWebViewConfiguration new]);
+ EXPECT_TRUE([configuration _allowsJavaScriptMarkup]);
+ [configuration _setAllowsJavaScriptMarkup:NO];
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 200, 200) configuration:configuration.get()]);
+ [webView synchronouslyLoadHTMLString:@"<svg><a><rect fill=\"green\" width=\"10\" height=\"10\"></rect><animate attributeName=\"href\" to=\"_javascript_:document.write('FAIL')\"/></a></svg>"];
+ NSString *bodyHTML = [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"];
+ EXPECT_WK_STREQ(bodyHTML, @"<svg><a><rect fill=\"green\" width=\"10\" height=\"10\"></rect><animate attributeName=\"href\"></animate></a></svg>");
+}
+
+TEST(WebKit, ConfigurationDisableJavaScriptSVGAnimateElementComplex)
+{
+ auto configuration = adoptNS([WKWebViewConfiguration new]);
+ EXPECT_TRUE([configuration _allowsJavaScriptMarkup]);
+ [configuration _setAllowsJavaScriptMarkup:NO];
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:configuration.get()]);
+ [webView synchronouslyLoadHTMLString:@"<svg><a><rect fill=\"green\" width=\"10\" height=\"10\"></rect><animate attributeName=\"href\" dur=\"4s\" calcMode=\"spline\" repeatCount=\"indefinite\" values=\"_javascript_:document.write('FAIL'); _javascript_:document.write('FAIL'); _javascript_:document.write(location.href); _javascript_:document.write('FAIL'); _javascript_:document.write('FAIL')\" keyTimes=\"0; 0.25; 0.5; 0.75; 1\" keySplines=\"0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1\"/></a></svg>"];
+ NSString *bodyHTML = [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"];
+ EXPECT_WK_STREQ(bodyHTML, @"<svg><a><rect fill=\"green\" width=\"10\" height=\"10\"></rect><animate attributeName=\"href\" dur=\"4s\" calcMode=\"spline\" repeatCount=\"indefinite\" keyTimes=\"0; 0.25; 0.5; 0.75; 1\" keySplines=\"0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1\"></animate></a></svg>");
+}