Changeset 292266 in webkit
- Timestamp:
- Apr 2, 2022 9:22:20 AM (4 months ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/connect-src/connect-src-websocket-self.sub-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/page/csp/ContentSecurityPolicy.cpp (modified) (2 diffs)
-
Source/WebCore/page/csp/ContentSecurityPolicy.h (modified) (1 diff)
-
Source/WebCore/page/csp/ContentSecurityPolicySource.cpp (modified) (5 diffs)
-
Source/WebCore/page/csp/ContentSecurityPolicySource.h (modified) (2 diffs)
-
Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r292222 r292266 1 2022-04-02 Patrick Griffis <pgriffis@igalia.com> 2 3 CSP: Improve compatibility of source matching 4 https://bugs.webkit.org/show_bug.cgi?id=235873 5 6 Reviewed by Darin Adler. 7 8 Update expectation as passing. 9 10 * web-platform-tests/content-security-policy/connect-src/connect-src-websocket-self.sub-expected.txt: 11 1 12 2022-04-01 Tim Nguyen <ntim@apple.com> 2 13 -
trunk/LayoutTests/imported/w3c/web-platform-tests/content-security-policy/connect-src/connect-src-websocket-self.sub-expected.txt
r246330 r292266 1 1 2 FAIL Expecting logs: ["allowed", "allowed"] assert_unreached: unexpected log: blocked Reached unreachable code 2 PASS Expecting logs: ["allowed", "allowed"] 3 3 -
trunk/Source/WebCore/ChangeLog
r292264 r292266 1 2022-04-02 Patrick Griffis <pgriffis@igalia.com> 2 3 CSP: Improve compatibility of source matching 4 https://bugs.webkit.org/show_bug.cgi?id=235873 5 6 Reviewed by Darin Adler. 7 8 - Improved handling of protocol changes: 9 - For host and self sources direct upgrades are allowed (ws->wss) (http->https already worked). 10 - For self sources side grades are now allowed (http->ws). 11 - For self sources upgrades are always allowed (*->https, *->wss). 12 This is documented here: https://www.w3.org/TR/CSP3/#match-url-to-source-expression 13 14 I also included some minor cleanups and adding of comments. 15 16 * page/csp/ContentSecurityPolicy.cpp: 17 (WebCore::ContentSecurityPolicy::updateSourceSelf): 18 (WebCore::ContentSecurityPolicy::protocolMatchesSelf const): Deleted. 19 * page/csp/ContentSecurityPolicy.h: 20 (WebCore::ContentSecurityPolicy::selfProtocol const): 21 * page/csp/ContentSecurityPolicySource.cpp: 22 (WebCore::ContentSecurityPolicySource::ContentSecurityPolicySource): 23 (WebCore::ContentSecurityPolicySource::matches const): 24 (WebCore::ContentSecurityPolicySource::schemeMatches const): 25 (WebCore::ContentSecurityPolicySource::portMatches const): 26 * page/csp/ContentSecurityPolicySource.h: 27 * page/csp/ContentSecurityPolicySourceList.cpp: 28 (WebCore::ContentSecurityPolicySourceList::isProtocolAllowedByStar const): 29 (WebCore::ContentSecurityPolicySourceList::parse): 30 1 31 2022-04-02 Andres Gonzalez <andresg_22@apple.com> 2 32 -
trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp
r292134 r292266 240 240 void ContentSecurityPolicy::updateSourceSelf(const SecurityOrigin& securityOrigin) 241 241 { 242 m_selfSourceProtocol = securityOrigin.protocol() ;243 m_selfSource = makeUnique<ContentSecurityPolicySource>(*this, m_selfSourceProtocol, securityOrigin.host(), securityOrigin.port(), emptyString(), false, false );242 m_selfSourceProtocol = securityOrigin.protocol().convertToASCIILowercase(); 243 m_selfSource = makeUnique<ContentSecurityPolicySource>(*this, m_selfSourceProtocol, securityOrigin.host(), securityOrigin.port(), emptyString(), false, false, IsSelfSource::Yes); 244 244 } 245 245 … … 294 294 return downcast<Document>(*m_scriptExecutionContext).settings().allowContentSecurityPolicySourceStarToMatchAnyProtocol(); 295 295 return false; 296 }297 298 bool ContentSecurityPolicy::protocolMatchesSelf(const URL& url) const299 {300 if (equalLettersIgnoringASCIICase(m_selfSourceProtocol, "http"))301 return url.protocolIsInHTTPFamily();302 return equalIgnoringASCIICase(url.protocol(), m_selfSourceProtocol);303 296 } 304 297 -
trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h
r292229 r292266 177 177 178 178 // Used by ContentSecurityPolicySource 179 bool protocolMatchesSelf(const URL&) const;179 const String& selfProtocol() const { return m_selfSourceProtocol; }; 180 180 181 181 void setUpgradeInsecureRequests(bool); -
trunk/Source/WebCore/page/csp/ContentSecurityPolicySource.cpp
r291837 r292266 35 35 namespace WebCore { 36 36 37 ContentSecurityPolicySource::ContentSecurityPolicySource(const ContentSecurityPolicy& policy, const String& scheme, const String& host, std::optional<uint16_t> port, const String& path, bool hostHasWildcard, bool portHasWildcard )37 ContentSecurityPolicySource::ContentSecurityPolicySource(const ContentSecurityPolicy& policy, const String& scheme, const String& host, std::optional<uint16_t> port, const String& path, bool hostHasWildcard, bool portHasWildcard, IsSelfSource isSelfSource) 38 38 : m_policy(policy) 39 39 , m_scheme(scheme) … … 43 43 , m_hostHasWildcard(hostHasWildcard) 44 44 , m_portHasWildcard(portHasWildcard) 45 , m_isSelfSource(isSelfSource == IsSelfSource::Yes) 45 46 { 46 47 } … … 48 49 bool ContentSecurityPolicySource::matches(const URL& url, bool didReceiveRedirectResponse) const 49 50 { 51 // https://www.w3.org/TR/CSP3/#match-url-to-source-expression. 50 52 if (!schemeMatches(url)) 51 53 return false; … … 57 59 bool ContentSecurityPolicySource::schemeMatches(const URL& url) const 58 60 { 59 if (m_scheme.isEmpty()) 60 return m_policy.protocolMatchesSelf(url); 61 if (equalLettersIgnoringASCIICase(m_scheme, "http")) 62 return url.protocolIsInHTTPFamily(); 63 return equalIgnoringASCIICase(url.protocol(), m_scheme); 61 // https://www.w3.org/TR/CSP3/#match-schemes. 62 const auto& scheme = m_scheme.isEmpty() ? m_policy.selfProtocol() : m_scheme; 63 auto urlScheme = url.protocol().convertToASCIILowercase(); 64 65 if (scheme == urlScheme) 66 return true; 67 68 // host-sources can do direct-upgrades. 69 if (scheme == "http" && urlScheme == "https") 70 return true; 71 if (scheme == "ws" && (urlScheme == "wss" || urlScheme == "https" || urlScheme == "http")) 72 return true; 73 if (scheme == "wss" && urlScheme == "https") 74 return true; 75 76 // self-sources can always upgrade to secure protocols and side-grade insecure protocols. 77 if ((m_isSelfSource 78 && ((urlScheme == "https" || urlScheme == "wss") || (scheme == "http" && urlScheme == "ws")))) 79 return true; 80 81 return false; 64 82 } 65 83 … … 104 122 return true; 105 123 106 if ((m_port && WTF::isDefaultPortForProtocol(m_port.value(), "http")) && ((!port && url.protocolIs("https")) || (port && WTF::isDefaultPortForProtocol(port.value(), "https")))) 124 // host-source and self-source allows upgrading to a more secure scheme which allows for different ports. 125 auto defaultSecurePort = WTF::defaultPortForProtocol("https").value_or(443); 126 auto defaultInsecurePort = WTF::defaultPortForProtocol("http").value_or(80); 127 bool isUpgradeSecure = (port == defaultSecurePort) || (!port && (url.protocol() == "https" || url.protocol() == "wss")); 128 bool isCurrentUpgradable = (m_port == defaultInsecurePort) || (m_scheme == "http" && (!m_port || m_port == defaultSecurePort)); 129 if (isUpgradeSecure && isCurrentUpgradable) 107 130 return true; 108 131 -
trunk/Source/WebCore/page/csp/ContentSecurityPolicySource.h
r278253 r292266 34 34 struct SecurityOriginData; 35 35 36 enum class IsSelfSource : bool { No, Yes }; 37 36 38 class ContentSecurityPolicySource { 37 39 WTF_MAKE_FAST_ALLOCATED; 38 40 public: 39 ContentSecurityPolicySource(const ContentSecurityPolicy&, const String& scheme, const String& host, std::optional<uint16_t> port, const String& path, bool hostHasWildcard, bool portHasWildcard );41 ContentSecurityPolicySource(const ContentSecurityPolicy&, const String& scheme, const String& host, std::optional<uint16_t> port, const String& path, bool hostHasWildcard, bool portHasWildcard, IsSelfSource); 40 42 41 43 bool matches(const URL&, bool didReceiveRedirectResponse = false) const; … … 58 60 bool m_hostHasWildcard; 59 61 bool m_portHasWildcard; 62 bool m_isSelfSource; 60 63 }; 61 64 -
trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp
r292151 r292266 121 121 return true; 122 122 123 // Although not allowed by the Content Security Policy Level 3 spec., we allow a data URL to match 123 // This is counter to the CSP3 spec which only allows HTTPS but Chromium also allows it. 124 bool isAllowed = url.protocolIsInHTTPFamily() || url.protocolIs("ws") || url.protocolIs("wss") || url.protocolIs(m_policy.selfProtocol()); 125 // Also not allowed by the Content Security Policy Level 3 spec., we allow a data URL to match 124 126 // "img-src *" and either a data URL or blob URL to match "media-src *" for web compatibility. 125 bool isAllowed = url.protocolIsInHTTPFamily() || url.protocolIs("ws") || url.protocolIs("wss") || m_policy.protocolMatchesSelf(url);126 127 if (equalIgnoringASCIICase(m_directiveName, ContentSecurityPolicyDirectiveNames::imgSrc)) 127 128 isAllowed |= url.protocolIsData(); … … 270 271 m_policy.reportDirectiveAsSourceExpression(m_directiveName, source->host.value); 271 272 if (isValidSourceForExtensionMode(source.value())) 272 m_list.append(ContentSecurityPolicySource(m_policy, source->scheme. toString(), source->host.value.toString(), source->port.value, source->path, source->host.hasWildcard, source->port.hasWildcard));273 m_list.append(ContentSecurityPolicySource(m_policy, source->scheme.convertToASCIILowercase(), source->host.value.toString(), source->port.value, source->path, source->host.hasWildcard, source->port.hasWildcard, IsSelfSource::No)); 273 274 } else 274 275 m_policy.reportInvalidSourceExpression(m_directiveName, String(beginSource, buffer.position() - beginSource));
Note: See TracChangeset
for help on using the changeset viewer.