From: Eric Covener Date: Thu, 21 Oct 2021 18:54:46 +0000 (+0000) Subject: add DirectorySlashNotFound to silence scanners X-Git-Tag: 2.5.0-alpha2-ci-test-only~725 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b125eddc6892786fbd87fccdad3cc8c059a1d925;p=thirdparty%2Fapache%2Fhttpd.git add DirectorySlashNotFound to silence scanners Almost as awkwardly named as IndexForbiddenReturn404 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1894456 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/changes-entries/DirectorySlashNotFound.txt b/changes-entries/DirectorySlashNotFound.txt new file mode 100644 index 00000000000..4f672644061 --- /dev/null +++ b/changes-entries/DirectorySlashNotFound.txt @@ -0,0 +1,2 @@ + *) mod_dir: Add "DirectorySlashNotFound" to return 404 instead of a + DirectorySlash redirect. [Eric Covener] diff --git a/docs/manual/mod/mod_dir.xml b/docs/manual/mod/mod_dir.xml index eed99c595d4..187d690a108 100644 --- a/docs/manual/mod/mod_dir.xml +++ b/docs/manual/mod/mod_dir.xml @@ -230,6 +230,22 @@ a directory +DirectorySlashNotFound +Toggle sending a HTTP 404 error in place of a trailing slash +DirectorySlashNotFound On|Off +DirectorySlashNotFound Off +server configvirtual host +directory.htaccess +Indexes +Added in 2.5.1 + + +

The DirectorySlashNotFound directive determines whether + mod_dir should return an HTTP 404 status code where it would + otherwise have redirected the request to include a trailing slash.

+
+
+ FallbackResource Define a default URL for requests that don't map to a file FallbackResource disabled | local-url diff --git a/modules/mappers/mod_dir.c b/modules/mappers/mod_dir.c index 3aebd9c0b4b..0bb6a274bbd 100644 --- a/modules/mappers/mod_dir.c +++ b/modules/mappers/mod_dir.c @@ -48,6 +48,7 @@ typedef struct dir_config_struct { moddir_cfg checkhandler; int redirect_index; const char *dflt; + moddir_cfg do_slash_notfound; } dir_config_rec; #define DIR_CMD_PERMS OR_INDEXES @@ -88,6 +89,13 @@ static const char *configure_slash(cmd_parms *cmd, void *d_, int arg) d->do_slash = arg ? MODDIR_ON : MODDIR_OFF; return NULL; } +static const char *configure_slash_notfound(cmd_parms *cmd, void *d_, int arg) +{ + dir_config_rec *d = d_; + + d->do_slash_notfound = arg ? MODDIR_ON : MODDIR_OFF; + return NULL; +} static const char *configure_checkhandler(cmd_parms *cmd, void *d_, int arg) { dir_config_rec *d = d_; @@ -132,6 +140,8 @@ static const command_rec dir_cmds[] = "a list of file names"), AP_INIT_FLAG("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS, "On or Off"), + AP_INIT_FLAG("DirectorySlashNotFound", configure_slash_notfound, NULL, DIR_CMD_PERMS, + "On or Off"), AP_INIT_FLAG("DirectoryCheckHandler", configure_checkhandler, NULL, DIR_CMD_PERMS, "On or Off"), AP_INIT_TAKE1("DirectoryIndexRedirect", configure_redirect, @@ -146,6 +156,7 @@ static void *create_dir_config(apr_pool_t *p, char *dummy) new->index_names = NULL; new->do_slash = MODDIR_UNSET; + new->do_slash_notfound = MODDIR_UNSET; new->checkhandler = MODDIR_UNSET; new->redirect_index = REDIRECT_UNSET; return (void *) new; @@ -160,6 +171,8 @@ static void *merge_dir_configs(apr_pool_t *p, void *basev, void *addv) new->index_names = add->index_names ? add->index_names : base->index_names; new->do_slash = (add->do_slash == MODDIR_UNSET) ? base->do_slash : add->do_slash; + new->do_slash_notfound = + (add->do_slash_notfound == MODDIR_UNSET) ? base->do_slash_notfound : add->do_slash_notfound; new->checkhandler = (add->checkhandler == MODDIR_UNSET) ? base->checkhandler : add->checkhandler; new->redirect_index= @@ -251,6 +264,10 @@ static int fixup_dir(request_rec *r) return DECLINED; } + if (d->do_slash_notfound == MODDIR_ON) { + return HTTP_NOT_FOUND; + } + /* Only redirect non-get requests if we have no note to warn * that this browser cannot handle redirs on non-GET requests * (such as Microsoft's WebFolders).