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

Fixing 404s on subdomains with dashes on it #692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

filter182
Copy link
Contributor

@filter182 filter182 commented May 28, 2024

Fixed the regex to allow dashes on subdomains, previous regex didn't march them. This was reported on issue #265

@@ -327,7 +327,7 @@ protected function get_service_nginx() : array {
'traefik.port=8080',
'traefik.protocol=https',
'traefik.docker.network=proxy',
"traefik.frontend.rule=HostRegexp:{$this->hostname},{subdomain:[a-z.-_]+}.{$this->hostname}{$domains}",
"traefik.frontend.rule=HostRegexp:{$this->hostname},{subdomain:[A-Za-z0-9-_]+}.{$this->hostname}{$domains}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fix has some unintended consequences.

The original regex [a-z.-_] is quite confusing, but it is two groups: a through z and . through _. If you look at the ASCII table between . and _ (positions 46-95) you'll see all numbers, uppercase latin letters and a bunch of symbols as well, including the . and _, but excluding the - symbol, which is at position 45.

I'm not sure why the original regex is so permissive in the first place:

php > var_dump( preg_match( '#^[a-z.-_]+$#', 'what/a.weird_sub^domain' ) );
int(1)

And yet fails to match:

php > var_dump( preg_match( '#^[a-z.-_]+$#', 'perfectly-legit' ) );
int(0)

While much more restrictive, the proposed newer version fails to match the dot symbol:

php > var_dump( preg_match( '#^[A-Za-z0-9-_]+$#', 'foo.bar' ) );
int(0)

This might be useful for deeper-level subdomains (language subdomains on a Multisite install for example). It also still matches the underscore symbol, which is not valid for hostnames/subdomains. It also looks like case sensitivity is handled by the HostRegexp implementation itself traefik/traefik#3930

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original regex is accidental, and it should have been [a-z.\-_]+, but the escaping was missed.

Copy link
Contributor Author

@filter182 filter182 Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch with the case sensitive implementation and I totally forgot to include the dot, this one [a-z.\-]+ works but it doesn't match numbers, do you guys think I should use [a-z0-9.\-] (removing the underscore) instead? It's common to see some people that add numbers on testing sites like test-site-1.domain.com, etc. @rmccue @kovshenin

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.

3 participants