Unexpected 308 in 2.4.2

1. Caddy version (caddy version):

2.4.2

2. How I run Caddy:

Docker

a. System environment:

Docker on Ubuntu

b. Command:

default command in docker

Details

Hi all, this morning I upgraded from 2.4.0 to 2.4.2 (2.4.3 is not available on docker hub yet)

I started to get 308 when trying to access /project/login?token=..., getting redirected to /project/login, notice the query string being dropped.

I do have some rewrite setup, but it doesn’t seem to match what I’m seeing.

@spa {
  path /project/* /other/* /more/*
  not file
}

rewrite @spa /{http.request.uri.path.0}/

If this somehow triggered the 308, it should be redirecting to /project not /project/login

Reverting back to 2.4.0 fixes it. As I mentioned before I haven’t got to try 2.4.3. Wondering if it’s a known issue and fixed in 2.4.3?

1 Like

Yes, 2.4.3 should have the fix for this. See the release notes:

You can keep an eye on this PR for when it gets merged for the docker official image, then wait an hour or two for the build to happen:

Or you can use the builder image variant and build from source to get it faster if you want. See the section “Adding custom Caddy modules” on Docker Hub, but omit the --with if you don’t have plugins, and use xcaddy build v2.4.3 to build the latest release. The Dockerfile would look like this:

FROM caddy:2.4.2-builder AS builder

RUN xcaddy build v2.4.3

FROM caddy:2.4.2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
1 Like

Thanks for the quick response again Francis! I was staring at the release log and wasn’t sure if the problem described was the same as mine. Thanks for the clarification. :+1:

To be honest, I’m not certain if it is, because you didn’t provide your full config, but it’s the most likely thing because we know something broke regarding redirects in file_server in v2.4.2.

my.domain

log

root * /var/www

file_server

@spa {
  path /project/* /names/* /masked/*
  not file
}

rewrite @spa /{http.request.uri.path.0}/

@backend {
  path /api/* /html/* /socket/* /dash /dash/* /live/* /healthcheck
}

reverse_proxy @backend app:4000

reverse_proxy /logs app:4000 {
  flush_interval -1
}

encode gzip

My config is rather simple - thanks Caddy - :slight_smile:

I just remembered there’s a shortcut for this, you can do {path.0} instead. See Caddyfile Concepts — Caddy Documentation

But yeah – I think the issue is that if your original request didn’t have the / then file_server would only consider the original request path and redirect to add the / even though the path was rewritten to not need it. I’m not sure if your case is the same as the ones that were tested for when implementing the fix, but I think it should be covered.

If you have the time to try building Caddy with the builder docker variant, we’ll know for sure. Should only take a minute or two to try, just use a Dockerfile like this:

FROM caddy:2.4.2-builder AS builder

RUN xcaddy build v2.4.3

FROM caddy:2.4.2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
1 Like

If it redirects /project to /project/ I’m totally OK with it.

The main use case for the rewrite is when accessing /project/frontend/route (hence the @spa) I want /project/index.html to be returned.

My local is kinda hard to do this test, it’s quite different how the assets are served. I’ll make sure to report back when I get 2.4.3 up in production. (Yep test in production, I love it)

This topic was automatically closed after 30 days. New replies are no longer allowed.