Repository navigation
fix(docker): do not serve dotfiles from the default Caddyfile - #2804
shinsenter wants to merge 6 commits into
Conversation
93ae669 to
332040a
Compare
332040a to
a407fbe
Compare
|
I wonder is this doesn't belong in the Caddy file server directly |
|
@dunglas good question, I checked that first. I don't think Caddy will take it: in caddyserver/caddy#2286 the maintainers said no to hiding dotfiles by default, mostly because of So the image's default Caddyfile seemed like the simplest place. People who serve dotfiles on purpose can still use their own Caddyfile or CADDY_SERVER_EXTRA_DIRECTIVES. If you'd rather have it in Go, I can try making php_server accept |
|
I'm not really sure of what to do here? On one hand, I prefer to be in sync with Caddy's defaults. On the other hand, I would prefer hide dotfiles by defaults... |
The default Caddyfile used by the Docker image serves dotfiles.
php_serverincludesfile_server, and Caddy serves hidden files unless told not to. A.envor.git/configin the document root can be downloaded.To reproduce:
This returns 200 with
secret./.git/configdoes the same.The fix adds a matcher to the site block that returns 404 when any path segment starts with a dot, except under
/.well-known/.respondruns beforephp_server, so PHP files and the front controller still work. I usedpath_regexpplus anot pathcondition because Caddy's regexp engine (RE2) has no lookahead.I mounted the changed Caddyfile into
dunglas/frankenphp:latest(v1.13.4, Caddy v2.11.7) with apublic/folder that has.env,.git/config,sub/.env,.well-known/security.txtandindex.php:/.env/.git/config/sub/.env/.well-known/security.txt/index.phpNo Go code changes, so I did not run
go test.I left
package/Caddyfilealone. It only serves the default page from/usr/share/frankenphp/.The default changes for anyone who serves a dotfile on purpose. They can still do it with their own Caddyfile or
CADDY_SERVER_EXTRA_DIRECTIVES. I'm sending this as a hardening change to the default config, not as a vulnerability in FrankenPHP, sinceSECURITY.mdasks for those to be reported privately.