Skip to content

[pre-flight] Compare effective ports, and each scheme's own default, for 'self' - #1

Closed
jonathanKingston wants to merge 1 commit into
cifrom
self-default-ports
Closed

jonathanKingston wants to merge 1 commit into
cifrom
self-default-ports

Conversation

@jonathanKingston

Copy link
Copy Markdown

Pre-flight only — do not merge. This PR exists to run the fork's own CI
against the branch before it goes to rust-ammonia/rust-content-security-policy.
Merging it would put the commit on this fork's master and make future rebases
onto upstream messier.

The base is ci, which is upstream master plus the fork-only workflow. The diff
above is just the patch: the workflow file is on the base side only, so it never
reaches the branch we send upstream.

"Does url match expression in origin with redirect count?" lets 'self'
match when the origin's and the URL's ports "are either the same or the
default ports for their respective schemes", so that a document on
http://example.com matches https://example.com and wss://example.com.

Neither half of that worked on default ports. rust-url reports
`Url::port()` as None whenever the port is the scheme's default, so
comparing it against `default_port(..)` - which returns Some(80) for
http, Some(443) for https - could not be true; `ports_are_default` was
dead code. The same comparison also judged the URL's default port by the
protected resource's scheme rather than the URL's own, so an http origin
was asking whether the URL's port was 80 while looking at an https URL.

Net effect: 'self' matched an upgraded scheme only on explicit
non-default ports. A page on https://example.com with connect-src 'self'
could not open a WebSocket to wss://example.com/socket, and one on
http://example.com did not match https://example.com. Compare
`port_or_known_default()` against each scheme's own default instead.

The existing WPT for this (connect-src-websocket-self.sub.html) exercises
exactly that pair, but over the test server's non-default ports, where
the broken comparison happens to give the right answer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant