Repository navigation
fix(webserver): stop the 403 explanation from disabling directory listing - #8821
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 8821Or download the artifact for your OS and architecture directly:
See Testing a PR. |
|
Pushed updated container image(s) for this PR:
|
rfay
left a comment
There was a problem hiding this comment.
Wow, amazing. Lots of churn here, thanks for the good work.
- It's not clear to me on a casual that there's test coverage for directory listing
- Does this cover similar issues in nginx (if they exist)?
I've been trying to encourage claude to do better manual testing instructions, especially getting it to start using |
|
I opened to encourage claude about limiting slow pre-commit checks and using |
|
I've tested the PR build extensively on several projects, including a sandbox created specifically for it. There were no issues or unexpected behavior that I could detect. The addition of status guards in 403.conf and 404.conf is a really nice touch 👍 I would like to propose some small changes to the error messages. These changes tighten the wording, remove ambiguity and repetition, and, in my opinion, make the messages more consistent and easier to understand. As a side note, the last bullet for 404 reflects that the Once again, thank you for the quick response to the issue and for taking the time to find a solution. Peace and long life 🖖 |
b5aa20c to
ff7f906
Compare
Thanks @brezanac, I applied your suggestion and added you as a co-author in commit
|
|
Pushed updated container image(s) for this PR:
|
@rfay, yes, both are covered:
|
|
Looks great! Thank you! |
There was a problem hiding this comment.
Codex points out an obscure friction with apache-fpm, probably not worth addressing: If you hit the direct web container, for example https://127.0.0.1:33135/ddev-webserver-404-error (with or without an index file), it redirects to the ddev-webserver 403 page.
Claude points out that people with custom .ddev/nginx_full/nginx-site.conf will have trouble again on next release.
Claude points out that the nginx 403 handler doesn't return the 403 it probably should. This would likely only affect people with custom config that didn't update to current:
location = /ddev-webserver-403-error {
internal;
+ # An aliased static file answers 200 on its own; force 403 so a legacy
+ # project config that still reaches this path via its `index` list (not
+ # error_page) also reports the right status.
+ return 403;
+ error_page 403 /ddev-webserver-403-error-body;
+}
+
+location = /ddev-webserver-403-error-body {
+ internal;
default_type text/html;
add_header X-Ddev-403-Source "ddev-webserver (nginx)" always;
alias /usr/local/share/ddev-webserver-403-error.html;
}
I think it's fine, path forward is up to you.
| if [ "${WEBSERVER_TYPE}" != "nginx-fpm" ]; then | ||
| skip "project nginx config does not apply to ${WEBSERVER_TYPE}" | ||
| fi | ||
| run docker exec -u root ${CONTAINER_NAME} bash -c 'mkdir -p /mnt/ddev_config/nginx && printf "location /test/listing/ {\n autoindex on;\n}\nerror_page 403 /test/app-403.php;\n" >/mnt/ddev_config/nginx/error-pages.conf && nginx -s reload' |
There was a problem hiding this comment.
This extra config should probably be cleaned up with a teardown() or whatever so it doesn't pollute later things.
There was a problem hiding this comment.
I added a teardown function.
| @@ -0,0 +1,3 @@ | |||
| # Apache directory listing, which conf-enabled/403.conf must not take over. | |||
| # nginx ignores .htaccess; its equivalent is tested from testdata/nginx. | |||
There was a problem hiding this comment.
Probably not correct. Also probably not very important.
ff7f906 to
7bd7e94
Compare
|
Rebased just so I can PR the PR with tiny commit. You can add if you like it. |
|
Pushed updated container image(s) for this PR:
|
fc9d292 to
ff5ba66
Compare
…ting The 403 explanation added in v1.25.4 worked by appending a fake entry to Apache's `DirectoryIndex` and nginx's `index` lists, which turned directory listing off for every project. It now replaces only the page body, through `ErrorDocument 403` and `error_page 403`, the way the 404 explanation always did. An entry at the end of the index list is always "found", so `Options +Indexes` on Apache and `autoindex on` on nginx could never produce a listing, wherever a project set them. The same trick meant neither web server ever decided "403", so the reason was missing from the error log, and a PHP wrapper was needed to send a 403 rather than the 200 a static page would have sent. The explanation came from #8641, which fixed #8595 and #7345. A user reported the broken listing against v1.25.4 in Discord, with no issue filed: https://discord.com/channels/664580571770388500/1548286862362157096 Apache gets `ErrorDocument 403` and nginx gets `error_page 403`, so both web servers keep their own logic for deciding what a 403 is, and only the page they send changes. Both directives keep the original status when the target is a static file, so the PHP wrapper is deleted, and the `index` lines in the site templates go back to what they were before v1.25.4. Two flaws in the 404 explanation are fixed at the same time, because 403 would otherwise inherit both. Its page answered as a URL of its own on Apache, so `GET /ddev-webserver-404-error` returned a 200 page in every project, and a `Require expr` guard now limits both pages to internal ErrorDocument redirects. A project also could not replace either page from `.ddev/nginx/*.conf`, since nginx serves the first matching `error_page` and `common.d` was included first, so site configs now include the project's directory ahead of ours. The 403 page itself is reworded, because a deny rule now reaches it too, where it used to produce the stock web server page. Build the binary with `make`, put `.gotmp/bin/<os>_<arch>` first on your `PATH`, then set up a project with one directory that has no index file: ```bash mkdir -p ~/tmp/listing/web/reports && cd ~/tmp/listing printf '<?php echo "home\n";' >web/index.php printf 'a,b,c\n' >web/reports/report.csv ddev config --project-name=listing --project-type=php --docroot=web --webserver-type=apache-fpm ddev start ``` Ask Apache for a listing of that directory: ```bash printf 'Options +Indexes\n' >web/reports/.htaccess curl -s https://listing.ddev.site/reports/ | grep -oE 'report.csv|403: Forbidden' curl -s -o /dev/null -w '%{http_code}\n' https://listing.ddev.site/ddev-webserver-404-error ``` Ask nginx for the same, which takes a restart to load the config: ```bash mkdir -p .ddev/nginx printf 'location /reports/ {\n autoindex on;\n}\n' >.ddev/nginx/autoindex.conf ddev config --webserver-type=nginx-fpm && ddev restart curl -s https://listing.ddev.site/reports/ | grep -oE 'report.csv|403: Forbidden' ``` A directory that asked for nothing still gets the explanation, and the web server now says why: ```bash mkdir web/empty curl -sI https://listing.ddev.site/empty/ | grep -iE '^HTTP|x-ddev-403' ddev logs | grep -i 'directory index' ``` Replace the page from the project, then clean up: ```bash printf 'MY OWN 403\n' >web/my-403.html printf 'error_page 403 /my-403.html;\n' >>.ddev/nginx/autoindex.conf ddev restart curl -s https://listing.ddev.site/empty/ ddev delete -Oy listing && rm -rf ~/tmp/listing ``` `php_webserver.bats` gains a denied path that reaches the explanation, an Apache listing through `.htaccess`, an nginx listing and error_page override through `/mnt/ddev_config/nginx`, and a check that neither page answers a direct request. `TestWebserverMissingIndexExplanation` now also requires a listing on both web servers, which exercises the generated site templates. Projects pick this up on `ddev start`, which rewrites `nginx-site.conf`. A project that took ownership of `nginx_full/nginx-site.conf` by removing `#ddev-generated` keeps its own copy, so directory listing stays broken there until `/ddev-webserver-403-error` is removed from its `index` line. 403s from deny rules now show DDEV's explanation instead of the stock web server page. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Pushed updated container image(s) for this PR:
|
Reword the callout and step lists on both pages per PR review feedback: state up front that the page is not the project's own error page, and point the last 404 step at the webserver's own log line instead of php-fpm, since ProxyErrorOverride/fastcgi_intercept_errors being off means an app-level 404 never reaches this page in the first place. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: brezanac <[email protected]>
ff5ba66 to
eabd3c8
Compare
|
Pushed updated container image(s) for this PR:
|
DDEV after v1.25.4 removes ddev-webserver-403-error.php and serves the 403 page as static HTML for every server-generated 403 (ddev/ddev#8821). Send index-less directories to a deny-all autoIndexURI context and map errorPage 403 to the HTML page, which works with both DDEV versions.


Short Summary (TL;DR)
The 403 explanation added in v1.25.4 worked by appending a fake entry to Apache's
DirectoryIndexand nginx'sindexlists, which turned directory listing off for every project. It now replaces only the page body, throughErrorDocument 403anderror_page 403, the way the 404 explanation always did.The Issue
An entry at the end of the index list is always "found", so
Options +Indexeson Apache andautoindex onon nginx could never produce a listing, wherever a project set them. The same trick meant neither web server ever decided "403", so the reason was missing from the error log, and a PHP wrapper was needed to send a 403 rather than the 200 a static page would have sent.ddev startdocroot index.* check #7345. A user reported the broken listing against v1.25.4 in Discord, with no issue filed: https://discord.com/channels/664580571770388500/1548286862362157096How This PR Solves The Issue
Apache gets
ErrorDocument 403and nginx getserror_page 403, so both web servers keep their own logic for deciding what a 403 is, and only the page they send changes. Both directives keep the original status when the target is a static file, so the PHP wrapper is deleted, and theindexlines in the site templates go back to what they were before v1.25.4.Two flaws in the 404 explanation are fixed at the same time, because 403 would otherwise inherit both. Its page answered as a URL of its own on Apache, so
GET /ddev-webserver-404-errorreturned a 200 page in every project, and aRequire exprguard now limits both pages to internal ErrorDocument redirects. A project also could not replace either page from.ddev/nginx/*.conf, since nginx serves the first matchingerror_pageandcommon.dwas included first, so site configs now include the project's directory ahead of ours.The 403 page itself is reworded, because a deny rule now reaches it too, where it used to produce the stock web server page.
Manual Testing Instructions
Build the binary with
make, put.gotmp/bin/<os>_<arch>first on yourPATH, then set up a project with one directory that has no index file:Ask Apache for a listing of that directory:
Ask nginx for the same, which takes a restart to load the config:
A directory that asked for nothing still gets the explanation, and the web server now says why:
Replace the page from the project, then clean up:
Automated Testing Overview
php_webserver.batsgains a denied path that reaches the explanation, an Apache listing through.htaccess, an nginx listing and error_page override through/mnt/ddev_config/nginx, and a check that neither page answers a direct request.TestWebserverMissingIndexExplanationnow also requires a listing on both web servers, which exercises the generated site templates.Release/Deployment Notes
Projects pick this up on
ddev start, which rewritesnginx-site.conf. A project that took ownership ofnginx_full/nginx-site.confby removing#ddev-generatedkeeps its own copy, so directory listing stays broken there until/ddev-webserver-403-erroris removed from itsindexline. 403s from deny rules now show DDEV's explanation instead of the stock web server page.🤖 Developed with assistance from Claude Code