Bug 201591 - CSP "connect-src" 'self' does not match web socket scheme as per spec
Summary: CSP "connect-src" 'self' does not match web socket scheme as per spec
Status: RESOLVED DUPLICATE of bug 235873
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-09-08 12:01 PDT by TJ
Modified: 2022-03-15 13:37 PDT (History)
17 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description TJ 2019-09-08 12:01:19 PDT
As per CSP spec paragraph 6.6.2.6, point 4. `self` match, 2nd match condition (https://w3c.github.io/webappsec-csp/#match-url-to-source-expression):

> "'self'", return "Matches" if one or more of the following conditions is met:
> ...
> 2. origin’s host is the same as url’s host, origin’s port and url’s port are either the same or the default ports for their respective schemes, and one or more of the following conditions is met:
>   - url’s scheme is "https" or "wss"
>   - origin’s scheme is "http" and url’s scheme is "http" or "ws"

This appears to not be working correctly in Safari, where I have a CSP of "connect-src 'self'" for a service worker, but the service worker refuses to connect to a web socket on the same host and port, logging error

> Refused to connect to wss://SOMEHOST/ws because it does not appear in the connect-src directive of the Content Security Policy.

Chromium had the same issue, fixed about a year ago: https://bugs.chromium.org/p/chromium/issues/detail?id=815142

Related W3C CSP Issue: https://github.com/w3c/webappsec-csp/issues/7
Comment 1 Radar WebKit Bug Importer 2019-09-10 10:29:17 PDT
<rdar://problem/55227268>
Comment 2 Moritz Mahringer 2019-12-08 18:13:47 PST
I encountered this bug today and verified that it exists in Safari but works as intended (by the specification) in Chrome and Firefox. Luckily we catched this with a report-only directive.
Comment 3 Michael 2021-02-12 05:20:25 PST
Still not fixed in Safari 14.
Comment 4 cheshire137 2022-03-15 08:18:02 PDT
Still present in Safari 15.3.
Comment 5 Patrick Griffis 2022-03-15 12:31:55 PDT
bug 235873 probably does fix this.
Comment 6 Brent Fulgham 2022-03-15 13:37:53 PDT

*** This bug has been marked as a duplicate of bug 235873 ***