Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IPv6 localhost detection in tracker script #1200

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

bz2
Copy link
Contributor

@bz2 bz2 commented Jul 21, 2021

Motivation

The tracker script has logic that disables itself for localhost addresses, and seems to want to handle literal IPv6 addresses but does not do so correctly.

This the default for a few development setups, see for instance: https://github.com/shellscape/webpack-plugin-serve#usage

Spec of literals in urls: https://datatracker.ietf.org/doc/html/rfc2732

Behaviour of literals in practice in javascript:

> new URL('http://[::]:55555').hostname
'[::]'
> new URL('http://[0:0:0:0:0:0:0:1]').hostname
'[::1]'
> new URL('http://[::0000:0000]').hostname
'[::]'

Tested with current LTS node and in Firefox and Chromium. The browsers also redirect when a url in typed in the location bar.

Changes

IPv6 literals in url hostnames follow RFC 2732 so are enclosed in brackets.

Browsers normalise so matching zeros is not required.

Allow :: unspecified address as well as ::1 loopback address.

Non-capturing groups not required when using /.../.test() method.

Tests

Ideally would have some, there don't seem to be any for the tracker script?

Changelog

Maybe needs an entry? You tell me.

Documentation

This change does not need a documentation update.

IPv6 literals in url hostnames follow RFC 2732 so are enclosed in
brackets.

Browsers normalise so matching zeros is not required.

Allow `::` unspecified address as well as `::1`  loopback address.

Non-capturing groups not required when using `/.../.test()` method.
@ukutaht
Copy link
Contributor

ukutaht commented Jul 22, 2021

Thanks for the detailed explanation, looks good to me!

@ukutaht ukutaht merged commit f5b412b into plausible:master Jul 22, 2021
@bz2 bz2 deleted the tracker_ipv6_localhost branch July 22, 2021 08:07
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.

2 participants