-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Improve ErrorDocument config in .htaccess #33048
Description
The current ErrorDocument configuration that is written to the .htaccess causes problems in some environments:
ErrorDocument 403 /
ErrorDocument 404 /
When the Apache Webserver is configured with ProxyErrorOverride the HTTP error handling for 403 and 404 errors is broken. Users no longer get the correct error codes and error messages. Instead they are redirected to the dashboard.
When you are running Nextcloud on your own server the solution is simple: do not use ProxyErrorOverride On. But there are also hosters that use this setting and provide no possibility to disable it.
In most cases this is probably only a minor issue / nitpick but there is (at least) one concrete case where this leads to real problems: the contact images. The contacts apps makes a request for each contact visible in the list:
/remote.php/dav/addressbooks/users/<user>/<Addressbook>/<contact-uid>.vcf?photo=
When the user is now redirected to the dashboard for each requests where no image is found instead of just getting a 404 error the server can get overloaded.
Possible solutions
Here are some suggestions to solve the issue:
Remove ErrorDocument directives
I'm not sure what the rationale behind the current ErrorDocument directives is. From my point of view they could just be removed without loosing anything.
Add config options to customize ErrorDocument directives
If removing the the directives is not possible, allowing the configuration of custom error documents would be a good alternative, e.g in:
occ config:system:set htaccess.ErrorDocument.403 "/my/custom/error/403.php"
occ config:system:set htaccess.ErrorDocument.404 "/my/custom/error/404.php"
Bring back error actions
There are templates left over at /core/templates/403.php and /core/templates/404.php. These templates could be made available again in controller actions that output the correct HTTP-Headers. Those actions could the be uses in the .htaccess file, e.g.
ErrorDocument 403 /index.php/errors/403
ErrorDocument 404 /index.php/errors/404
I would be happy to help out with a pull request.