Skip to content

fix(webserver): stop the 403 explanation from disabling directory listing - #8821

Merged
rfay merged 7 commits into
mainfrom
20260913_stasadev_webserver_error_pages
Sep 23, 2026
Merged

rfay merged 7 commits into
mainfrom
20260913_stasadev_webserver_error_pages

Conversation

@stasadev

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

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.

The Issue

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.

How This PR Solves The Issue

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.

Manual Testing Instructions

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:

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:

printf 'Options +Indexes\n' >web/reports/.htaccess
curl -s https://listing.ddev.site/reports/ | grep -oE 'report.csv|403: Forbidden'
# v1.25.4: 403: Forbidden, whatever the project asked for
# now:     report.csv, the listing
curl -s -o /dev/null -w '%{http_code}\n' https://listing.ddev.site/ddev-webserver-404-error
# v1.25.4: 200, the explanation served as an ordinary URL of the project
# now:     403, reachable only as an error document

Ask nginx for the same, which takes a restart to load the config:

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'
# the same two outcomes as Apache

A directory that asked for nothing still gets the explanation, and the web server now says why:

mkdir web/empty
curl -sI https://listing.ddev.site/empty/ | grep -iE '^HTTP|x-ddev-403'
# 403 with x-ddev-403-source: ddev-webserver (nginx), unchanged from v1.25.4
ddev logs | grep -i 'directory index'
# v1.25.4: nothing, because nginx never decided the request was forbidden
# now:     directory index of "/var/www/html/web/empty/" is forbidden

Replace the page from the project, then clean up:

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/
# v1.25.4: the ddev-webserver page, because ours was included first and won
# now:     MY OWN 403
ddev delete -Oy listing && rm -rf ~/tmp/listing

Automated Testing Overview

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.

Release/Deployment Notes

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

@github-actions github-actions Bot added bugfix dependencies Pull requests that update a dependency file labels Sep 13, 2026
@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 8821

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:515b795495
  • ddev/ddev-webserver:515b795495

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

@rfay

rfay commented Sep 13, 2026

Copy link
Copy Markdown
Member

Build the binary with make, put .gotmp/bin/_ first on your PATH, then set up a project with one directory that has no index file:

I've been trying to encourage claude to do better manual testing instructions, especially getting it to start using ddev utility download-ddev instead of assuming go build capabilities. Maybe we need to be explicit about things like that in the CLAUDE.md?

@rfay

rfay commented Sep 14, 2026

Copy link
Copy Markdown
Member

I opened

to encourage claude about limiting slow pre-commit checks and using ddev utility download-ddev for manual testing examples.

@brezanac

Copy link
Copy Markdown

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.

403 Forbidden

This page comes from the `ddev-webserver` container and is **not** your project's 403 page. The request reached the webserver, but access to this location was not allowed. This can happen when a directory has no index file (`index.php`, `index.html`, …) and directory listing is disabled, or when a rule blocks access.

1. Run `ddev logs` to see why the webserver returned the 403.
2. Check that `docroot` in `.ddev/config.yaml` points to the directory where your project's `index.php` actually lives.
3. Make sure an `index.php` or `index.html` exists there, since the project may not be installed yet.
4. If you want to browse a directory without an index file, enable directory listing: use `Options +Indexes` in `.htaccess` (Apache) or `autoindex on;` in `.ddev/nginx/*.conf` (nginx).
404 Not Found

This page comes from the `ddev-webserver` container and is **not** your project's 404 page. The request reached the webserver, but the requested file could not be found under the project's `docroot`.

1. Check that `docroot` in `.ddev/config.yaml` points to the directory where your project's `index.php` actually lives.
2. Make sure the requested file exists at that path.
3. Run `ddev logs` to see the exact 404 the webserver logged for this request.

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 ddev-webserver 404 page only fires for 404 status codes Apache and nginx generate themselves. With ProxyErrorOverride and fastcgi_intercept_errors set to off, php-fpm and app 404s pass through untouched, so seeing this page already rules out php-fpm as the source, hence pointing at what the webserver logged rather than asking which one reported it.

Once again, thank you for the quick response to the issue and for taking the time to find a solution.

Peace and long life 🖖

@stasadev
stasadev force-pushed the 20260913_stasadev_webserver_error_pages branch from b5aa20c to ff7f906 Compare September 21, 2026 10:44
@stasadev

stasadev commented Sep 21, 2026 •

Copy link
Copy Markdown
Member Author

I would like to propose some small changes to the error messages.

Thanks @brezanac, I applied your suggestion and added you as a co-author in commit ff7f906 (this PR).

image image

@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:48147f1138
  • ddev/ddev-webserver:48147f1138

@stasadev

Copy link
Copy Markdown
Member Author

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)?

@rfay, yes, both are covered:

  • Directory listing is covered by TestWebserverMissingIndexExplanation in ddevapp_test.go, plus a couple of bats tests in php_webserver.bats that check listing still works with .htaccess and with a project nginx config.
  • It's not Apache-only, the fix and tests cover nginx too, same test runs for both webserver types.

@stasadev
stasadev marked this pull request as ready for review September 21, 2026 10:52
@stasadev
stasadev requested review from a team as code owners September 21, 2026 10:52
@brezanac

Copy link
Copy Markdown

@stasadev

Looks great!

Thank you!

@rfay rfay left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra config should probably be cleaned up with a teardown() or whatever so it doesn't pollute later things.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not correct. Also probably not very important.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rephrased it.

@rfay
rfay force-pushed the 20260913_stasadev_webserver_error_pages branch from ff7f906 to 7bd7e94 Compare September 22, 2026 16:06
@rfay

rfay commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Rebased just so I can PR the PR with tiny commit.

You can add

if you like it.

stasadev pushed a commit that referenced this pull request Sep 22, 2026
stasadev added a commit that referenced this pull request Sep 22, 2026
@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:71799c0f31
  • ddev/ddev-webserver:71799c0f31

rfay added a commit that referenced this pull request Sep 23, 2026
rfay pushed a commit that referenced this pull request Sep 23, 2026
@rfay
rfay force-pushed the 20260913_stasadev_webserver_error_pages branch from fc9d292 to ff5ba66 Compare September 23, 2026 02:00
…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]>
@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:18a87f2e74
  • ddev/ddev-webserver:18a87f2e74

stasadev and others added 3 commits September 22, 2026 20:09
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]>
@rfay
rfay force-pushed the 20260913_stasadev_webserver_error_pages branch from ff5ba66 to eabd3c8 Compare September 23, 2026 02:10
@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:1661069e8c
  • ddev/ddev-webserver:1661069e8c

@rfay
rfay merged commit 18ecfec into main Sep 23, 2026
60 of 61 checks passed
@rfay
rfay deleted the 20260913_stasadev_webserver_error_pages branch September 23, 2026 13:36
morvy added a commit to morvy/ddev-openlitespeed that referenced this pull request Oct 16, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ddev-webserver 403 should explain what's wrong

3 participants