Changeset 286860 in webkit
- Timestamp:
- Dec 10, 2021, 11:00:44 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/nonce-enforce-blocked-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/Element.cpp (modified) (3 diffs)
-
Source/WebCore/dom/Element.h (modified) (3 diffs)
-
Source/WebCore/html/parser/AtomHTMLToken.h (modified) (4 diffs)
-
Source/WebCore/html/parser/HTMLConstructionSite.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r286855 r286860 1 2021-12-10 Patrick Griffis <pgriffis@igalia.com> 2 3 CSP: Implement protections against nonce-hijacking 4 https://bugs.webkit.org/show_bug.cgi?id=233087 5 6 Reviewed by Brent Fulgham. 7 8 Update expectations. 9 10 * web-platform-tests/content-security-policy/script-src/nonce-enforce-blocked-expected.txt: 11 1 12 2021-12-10 Chris Dumez <cdumez@apple.com> 2 13 -
trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/script-src/nonce-enforce-blocked-expected.txt
r246330 r286860 1 1 2 FAIL Unnonced scripts generate reports. assert_unreached: '<script' attribute, no execution. Reached unreachable code 2 PASS Unnonced scripts generate reports. 3 3 -
trunk/Source/WebCore/ChangeLog
r286858 r286860 1 2021-12-10 Patrick Griffis <pgriffis@igalia.com> 2 3 CSP: Prevent nonce-hijacking 4 https://bugs.webkit.org/show_bug.cgi?id=233087 5 6 Reviewed by Brent Fulgham. 7 8 Implement protections against nonce-hijacking as described in this spec: 9 https://www.w3.org/TR/CSP3/#security-nonce-hijacking 10 11 * dom/Element.cpp: 12 (WebCore::Element::isNonceable const): 13 (WebCore::Element::nonce const): 14 * dom/Element.h: 15 (WebCore::Element::hasDuplicateAttribute const): 16 (WebCore::Element::setHasDuplicateAttribute): 17 * html/parser/AtomHTMLToken.h: 18 (WebCore::AtomHTMLToken::hasDuplicateAttribute const): 19 (WebCore::AtomHTMLToken::initializeAttributes): 20 * html/parser/HTMLConstructionSite.cpp: 21 (WebCore::setAttributes): 22 (WebCore::HTMLConstructionSite::insertCustomElement): 23 1 24 2021-12-09 Darin Adler <darin@apple.com> 2 25 -
trunk/Source/WebCore/dom/Element.cpp
r286776 r286860 75 75 #include "HTMLOptionElement.h" 76 76 #include "HTMLParserIdioms.h" 77 #include "HTMLScriptElement.h" 77 78 #include "HTMLSelectElement.h" 78 79 #include "HTMLTemplateElement.h" … … 110 111 #include "SVGNames.h" 111 112 #include "SVGSVGElement.h" 113 #include "SVGScriptElement.h" 112 114 #include "ScriptDisallowedScope.h" 113 115 #include "ScrollIntoViewOptions.h" … … 319 321 } 320 322 323 bool Element::isNonceable() const 324 { 325 // https://www.w3.org/TR/CSP3/#is-element-nonceable 326 if (elementRareData()->nonce().isNull()) 327 return false; 328 329 if (hasDuplicateAttribute()) 330 return false; 331 332 if (hasAttributes() 333 && (is<HTMLScriptElement>(*this) || is<SVGScriptElement>(*this))) { 334 static const char scriptString[] = "<script"; 335 static const char styleString[] = "<style"; 336 337 for (const auto& attribute : attributesIterator()) { 338 auto name = attribute.localName().convertToASCIILowercase(); 339 auto value = attribute.value().convertToASCIILowercase(); 340 if (name.contains(scriptString) 341 || name.contains(styleString) 342 || value.contains(scriptString) 343 || value.contains(styleString)) 344 return false; 345 } 346 } 347 348 return true; 349 } 350 321 351 const AtomString& Element::nonce() const 322 352 { 323 return hasRareData() ? elementRareData()->nonce() : emptyAtom(); 353 if (hasRareData() && isNonceable()) 354 return elementRareData()->nonce(); 355 356 return emptyAtom(); 324 357 } 325 358 -
trunk/Source/WebCore/dom/Element.h
r286136 r286860 653 653 String debugDescription() const override; 654 654 655 bool hasDuplicateAttribute() const { return m_hasDuplicateAttribute; }; 656 void setHasDuplicateAttribute(bool hasDuplicateAttribute) { m_hasDuplicateAttribute = hasDuplicateAttribute; }; 657 655 658 protected: 656 659 Element(const QualifiedName&, Document&, ConstructionType); … … 688 691 bool isUserActionElementHasFocusVisible() const; 689 692 bool isUserActionElementHasFocusWithin() const; 693 694 bool isNonceable() const; 690 695 691 696 virtual void didAddUserAgentShadowRoot(ShadowRoot&) { } … … 766 771 QualifiedName m_tagName; 767 772 RefPtr<ElementData> m_elementData; 773 774 bool m_hasDuplicateAttribute { false }; 768 775 }; 769 776 -
trunk/Source/WebCore/html/parser/AtomHTMLToken.h
r282142 r286860 32 32 namespace WebCore { 33 33 34 enum class HasDuplicateAttribute : bool { No, Yes }; 35 34 36 class AtomHTMLToken { 35 37 public: … … 70 72 71 73 const String& comment() const; 74 75 HasDuplicateAttribute hasDuplicateAttribute() const { return m_hasDuplicateAttribute; }; 72 76 73 77 private: … … 91 95 bool m_selfClosing; // StartTag, EndTag. 92 96 Vector<Attribute> m_attributes; // StartTag, EndTag. 97 98 HasDuplicateAttribute m_hasDuplicateAttribute { HasDuplicateAttribute::No }; 93 99 }; 94 100 … … 209 215 if (!hasAttribute(m_attributes, localName)) 210 216 m_attributes.uncheckedAppend(Attribute(QualifiedName(nullAtom(), localName, nullAtom()), HTMLAtomStringCache::makeAttributeValue(attribute.value))); 217 else 218 m_hasDuplicateAttribute = HasDuplicateAttribute::Yes; 211 219 } 212 220 } -
trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp
r286308 r286860 56 56 using namespace HTMLNames; 57 57 58 static inline void setAttributes(Element& element, Vector<Attribute>& attributes, ParserContentPolicy parserContentPolicy)58 static inline void setAttributes(Element& element, Vector<Attribute>& attributes, HasDuplicateAttribute hasDuplicateAttribute, ParserContentPolicy parserContentPolicy) 59 59 { 60 60 if (!scriptingContentIsAllowed(parserContentPolicy)) 61 61 element.stripScriptingAttributes(attributes); 62 62 element.parserSetAttributes(attributes); 63 element.setHasDuplicateAttribute(hasDuplicateAttribute == HasDuplicateAttribute::Yes); 63 64 } 64 65 65 66 static inline void setAttributes(Element& element, AtomHTMLToken& token, ParserContentPolicy parserContentPolicy) 66 67 { 67 setAttributes(element, token.attributes(), parserContentPolicy);68 setAttributes(element, token.attributes(), token.hasDuplicateAttribute(), parserContentPolicy); 68 69 } 69 70 … … 517 518 void HTMLConstructionSite::insertCustomElement(Ref<Element>&& element, const AtomString& localName, Vector<Attribute>&& attributes) 518 519 { 519 setAttributes(element, attributes, m_parserContentPolicy);520 setAttributes(element, attributes, HasDuplicateAttribute::No, m_parserContentPolicy); 520 521 attachLater(currentNode(), element.copyRef()); 521 522 m_openElements.push(HTMLStackItem::create(WTFMove(element), localName, WTFMove(attributes)));
Note:
See TracChangeset
for help on using the changeset viewer.