caddy: Regression: Caddy 2.9.0 returns 411 Length Required for some sites

After upgrading from Caddy 2.8.4 to 2.9.0, Joomla sites started returning HTTP 411 (“Length Required”) errors for certain requests. Downgrading to Caddy 2.8.4 resolves the issue, indicating a regression or stricter enforcement of request header handling in 2.9.0.

The problem seems related to:

  1. Handling of requests without a Content-Length header.

. Requests that were previously allowed in Caddy 2.8.4 now fail in 2.9.0.

  1. Interaction with Joomla’s rewrites.

. Joomla relies on rewrites for dynamic routing (e.g., /index.php?{query}). The rewrites still work, but certain requests (possibly POST or other non-GET methods) fail with 411.

Steps to Reproduce:

Configure a Joomla site with the following minimal Caddyfile:

example.com {
    root * /var/www/samplesite
    php_fastcgi unix//run/php/php7.4-fpm.sock
    file_server

    @joomlaNotFound {
        not file {path}
        not file {path}/index.php
    }
    rewrite @joomlaNotFound /index.php?{query}
}

Make a POST request without a Content-Length header:

curl -X POST https://dev.apcwo.org/path -d '' -v

Observe a 411 response in Caddy 2.9.0. The same configuration works in Caddy 2.8.4.

Expected Behavior: Caddy should handle requests without a Content-Length header the same way as in version 2.8.4 or provide clear guidance on how to adapt the configuration.

Observed Behavior: Caddy 2.9.0 returns 411 errors for requests that worked in 2.8.4, breaking Joomla functionality.

Additional Details:

Joomla uses rewrites heavily, and the issue seems tied to how Caddy processes requests during rewrites. The problem was tested with PHP-FPM and occurs even with minimal configurations. Caddy logs show no additional details besides the 411 response. Downgrading to Caddy 2.8.4 immediately resolves the issue.

Environment:

Caddy Version: 2.9.0 PHP Version: 7.4 (PHP-FPM) Joomla Version: (3.10) OS: (Ubuntu 20.04)

Suggestions for Debugging:

Review changes in Caddy 2.9.0 related to request handling or HTTP compliance. Investigate interactions between the rewrite directive and PHP-FPM.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 30 (6 by maintainers)

Most upvoted comments

Add request_buffers to your reverse proxy configuration and see if the problem is fixed.

@teddysun 6638 is not the cause, that actually fixes the buffering problem. Revert 6661 and see if it will happen.

These two patches are implemented to solve the ddos attacks reported. However, request buffering will be needed if content length is not specified.

Any access logs will be appreciated to see if any alternative approaches without enabling explicit request buffering can be done.

How to correctly downgrade to 2.8.4? Thanks

On Debian based systems it should be as easy as sudo apt-get install caddy=2.8.4

@WeidiDeng

Yes, revert #6661 and problem was solved.

Building using xcaddy fastcgi_buffer did not solve my issue. Still getting 411 responses on http3.

Try building the master branch. And make sure your restart caddy after moving the binary

If you installed with apt, then yes, the command above works. If you built with xcaddy then it’s as simple as xcaddy build v2.8.4 and moving the binary to /usr/bin.

If you’re on Debian you will need go. You can easily install the latest version from snap with the following

sudo apt install snapd -y
sudo snap install --classic go
ln -s /snap/bin/go /usr/bin/go 

Then install xcaddy (commands pulled from official documentation)

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-xcaddy-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-xcaddy.list
sudo apt update
sudo apt install xcaddy

Then run xcaddy build v2.8.4 and then mv caddy /usr/bin. Or, you can build the master branch which has the fix: xcaddy build master then mv caddy /usr/bin.

You should already have a caddy user and group but if you don’t, then:

sudo groupadd --system caddy
sudo useradd --system \
    --gid caddy \
    --create-home \
    --home-dir /var/lib/caddy \
    --shell /usr/sbin/nologin \
    --comment "Caddy web server" \
    caddy

If you don’t already have a caddy service then: In /etc/systemd/system make a new file caddy.service and paste https://github.com/caddyserver/dist/blob/master/init/caddy.service in

Then you can finally run

sudo systemctl daemon-reload
sudo systemctl enable --now caddy

and now you have Caddy custom built with xcaddy from scratch! Since I deploy it to so many servers at once, you can make a script to SCP it over automatically to all of your servers.

Happy to report that fastcgi_buffer fixes HTTP/3 error 411 problems from nextcloud via HTTP/3 for me.

@teddysun @Telesphoreo @dzervelce @Brawl345 @spurgeonbj We know that downgrading fixes the issue; it’s already an established regression – but please notice @WeidiDeng is asking if others can verify whether #6759 fixes it without having to revert and downgrade. If no one experiencing the issue can verify this then we cannot release a patch. Weidi has even provided instructions multiple times now for an easy way to compile Caddy with the proposed patch: xcaddy build fastcgi_buffer – we would greatly appreciate that you try it so we can release a proper patch. 🙂 Thank you!

After https://github.com/caddyserver/caddy/pull/6759 commit https://github.com/caddyserver/caddy/commit/3ba88fe13d43615830020ff2b09f8779f1267935 I tested again. All the issues I found were resolved. LGTM. I hope there will be more tests and merge into the master as soon as possible.

I have the same problem. After upgrading from Caddy 2.8.4 -> 2.9.0 the site was broken/unresponsive. I can confirm that after adding request_buffers 4k to the php_fastcgi directive everything is fine. Sorry, I couldn’t do the build.

zwerimex.com {
    root * /var/www/zw_test01
    encode zstd gzip
    try_files {path} {path}.php {path}.html

    file_server

    php_fastcgi unix//run/php/php8.3-fpm.sock {
        request_buffers 4k
    }

    header {
        Permissions-Policy "accelerometer=(), autoplay=(), camera=(), geolocation=(self), gyroscope=(), magnetometer=(), microphone=(), payment=(), serial=(), usb=()"
        Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
        X-Frame-Options "deny"
        X-Content-Type-Options "nosniff"
        Referrer-Policy "no-referrer-when-downgrade"
    }
}

@teddysun @Telesphoreo @dzervelce @Brawl345 @spurgeonbj We know that downgrading fixes the issue; it’s already an established regression – but please notice @WeidiDeng is asking if others can verify whether #6759 fixes it without having to revert and downgrade. If no one experiencing the issue can verify this then we cannot release a patch. Weidi has even provided instructions multiple times now for an easy way to compile Caddy with the proposed patch: xcaddy build fastcgi_buffer – we would greatly appreciate that you try it so we can release a proper patch. 🙂 Thank you!

Same thing happening to my WordPress site. I have only observed this in Firefox though. Downgrading fixed it.