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

RedirectRegex broken since update to v3.0 #10690

Open
2 tasks done
lazka opened this issue May 4, 2024 · 8 comments
Open
2 tasks done

RedirectRegex broken since update to v3.0 #10690

lazka opened this issue May 4, 2024 · 8 comments
Labels
area/middleware contributor/waiting-for-feedback kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed.

Comments

@lazka
Copy link

lazka commented May 4, 2024

Welcome!

  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've searched similar issues on the Traefik community forum and didn't find any.

What did you do?

I have the following RedirectRegex config: https://github.com/msys2/msys2-main-server/blob/8330fd44f4fdf76d27200e995fb8494a4006e6c3/docker-compose.yml#L153-L154

This resulted in "https://mingw-w64.org" being redirected to "https://www.mingw-w64.org", among other cases.

Since the update to v3.0 from v2.11.2 this no longer works and requests using "https://mingw-w64.org" no longer get redirected. I've confirmed that downgrading to 2.11 makes things work again.

I couldn't find anything in the migration guide regarding any changes for RedirectRegex, so I'm filing this here.

What did you see instead?

No redirect happening.

What version of Traefik are you using?

3.0.0

What is your environment & configuration?

See the linked docker-compose.yml above

If applicable, please paste the log output in DEBUG level

No response

@pbek
Copy link
Contributor

pbek commented May 4, 2024

I have the same issue after migrating from Traefik v2 to Traefik 3.0, e.g. also with a simple redirect from www.mydomain to mydomain.

Config:

      - traefik.http.middlewares.bekerle-web-2022-www.redirectregex.regex=^(https?://)www.(.*)$$
      - traefik.http.middlewares.bekerle-web-2022-www.redirectregex.replacement=$${1}$${2}
      - traefik.http.middlewares.bekerle-web-2022-www.redirectregex.permanent=true

There was no redirect, the webpage could not be accessed anymore.

There were no docker logs for the traefik container.

@pbek
Copy link
Contributor

pbek commented May 4, 2024

But what did work on Traefik v3 was:

      - traefik.http.middlewares.nextcloud-redirectregex.redirectregex.permanent=true
      - traefik.http.middlewares.nextcloud-redirectregex.redirectregex.regex=^https://(.*)/.well-known/(card|cal)dav
      - traefik.http.middlewares.nextcloud-redirectregex.redirectregex.replacement=https://$${1}/remote.php/dav/

@sdelicata sdelicata added kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. area/middleware and removed status/0-needs-triage labels May 6, 2024
@mmatur
Copy link
Member

mmatur commented May 28, 2024

Hello @lazka and @pbek,

Sorry for the late answer.

I tried to reproduce the issue with the following docker-compose:

version: '3.8'

services:
  hub:
    image: traefik:v3.0
    command:
      - --providers.docker
      - --log.level=DEBUG
      - --api.insecure
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:8080:8080"
  whoami:
    image: traefik/whoami
    labels:
      traefik.http.routers.whoami.rule: Host(`mingw-w64.org`) || Host(`mingw-w64.net`) || Host(`www.mingw-w64.net`)
      traefik.http.routers.whoami.middlewares: redir
      traefik.http.middlewares.redir.redirectregex.regex: ^http(s?)://(?:www[.])?mingw-w64[.](?:org|net)/(.*)$$
      traefik.http.middlewares.redir.redirectregex.replacement: http$${1}://www.mingw-w64.org/$${2}
$ curl -Iv http://127.0.0.1 -H "Host: mingw-w64.org"
*   Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80
> HEAD / HTTP/1.1
> Host: mingw-w64.org
> User-Agent: curl/8.6.0
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
HTTP/1.1 307 Temporary Redirect
< Location: http://www.mingw-w64.org/
Location: http://www.mingw-w64.org/
< Date: Tue, 28 May 2024 08:24:08 GMT
Date: Tue, 28 May 2024 08:24:08 GMT
< Content-Length: 18
Content-Length: 18

<
* Connection #0 to host 127.0.0.1 left intact

And it seems is working as expected could you please provide a complete reproductible use case

@mmatur mmatur removed their assignment May 28, 2024
@pbek
Copy link
Contributor

pbek commented May 28, 2024

Thank you for your answer, @mmatur. Was the above general www redirect also not reproducible?

#10690 (comment)

@mmatur
Copy link
Member

mmatur commented May 28, 2024

@pbek with the following docker-compose

version: '3.8'

services:
  hub:
    image: traefik:v3.0
    command:
      - --providers.docker
      - --log.level=DEBUG
      - --api.insecure
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:8080:8080"
  whoami:
    image: traefik/whoami
    labels:
      traefik.http.routers.whoami.rule: Host(`www.whoami.localhost`)
      traefik.http.routers.whoami.middlewares: bekerle-web-2022-www
      traefik.http.middlewares.bekerle-web-2022-www.redirectregex.regex: ^(https?://)www.(.*)$$
      traefik.http.middlewares.bekerle-web-2022-www.redirectregex.replacement: $${1}$${2}
$ curl -Iv http://127.0.0.1 -H "Host: www.whoami.localhost"
*   Trying 127.0.0.1:80...
* Connected to 127.0.0.1 (127.0.0.1) port 80
> HEAD / HTTP/1.1
> Host: www.whoami.localhost
> User-Agent: curl/8.6.0
> Accept: */*
>
< HTTP/1.1 307 Temporary Redirect
HTTP/1.1 307 Temporary Redirect
< Location: http://whoami.localhost/
Location: http://whoami.localhost/
< Date: Tue, 28 May 2024 09:11:00 GMT
Date: Tue, 28 May 2024 09:11:00 GMT
< Content-Length: 18
Content-Length: 18

<
* Connection #0 to host 127.0.0.1 left intact

I'm not able to reproduce either.

@pbek
Copy link
Contributor

pbek commented May 28, 2024

Oh, I tried again on my server and I can confirm that the traefik v3.0.1 docker image solved the issues! 🥳
@lazka?

@lazka
Copy link
Author

lazka commented May 28, 2024

It still fails here with v3.0.1:

$ curl -Iv http://mingw-w64.org
* Host mingw-w64.org:80 was resolved.
* IPv6: (none)
* IPv4: 178.63.98.68
*   Trying 178.63.98.68:80...
* Connected to mingw-w64.org (178.63.98.68) port 80
> HEAD / HTTP/1.1
> Host: mingw-w64.org
> User-Agent: curl/8.8.0
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
< Date: Tue, 28 May 2024 12:33:42 GMT
Date: Tue, 28 May 2024 12:33:42 GMT
< Content-Length: 19
Content-Length: 19
<

* Connection #0 to host mingw-w64.org left intact

@mmatur
Copy link
Member

mmatur commented May 28, 2024

@lazka you got a 404 answer probably due to the change on Host rule: https://doc.traefik.io/traefik/migration/v2-to-v3/#new-v3-syntax-notable-changes

All matchers now take a single value (except Header, HeaderRegexp, Query, and QueryRegexp which take two) and should be explicitly combined using logical operators to mimic previous behavior.

I saw in your labels

# https
      - "traefik.http.routers.mingw-w64-secure.rule=Host(`mingw-w64.org`, `mingw-w64.net`, `www.mingw-w64.net`)"

It needs to be replace by

# https
      - "traefik.http.routers.mingw-w64-secure.rule=Host(`mingw-w64.org`) || Host(`mingw-w64.net`) || Host(`www.mingw-w64.net`)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/middleware contributor/waiting-for-feedback kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed.
Projects
None yet
Development

No branches or pull requests

5 participants