]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
add DirectorySlashNotFound to silence scanners
authorEric Covener <covener@apache.org>
Thu, 21 Oct 2021 18:54:46 +0000 (18:54 +0000)
committerEric Covener <covener@apache.org>
Thu, 21 Oct 2021 18:54:46 +0000 (18:54 +0000)
Almost as awkwardly named as IndexForbiddenReturn404

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1894456 13f79535-47bb-0310-9956-ffa450edef68

changes-entries/DirectorySlashNotFound.txt [new file with mode: 0644]
docs/manual/mod/mod_dir.xml
modules/mappers/mod_dir.c

diff --git a/changes-entries/DirectorySlashNotFound.txt b/changes-entries/DirectorySlashNotFound.txt
new file mode 100644 (file)
index 0000000..4f67264
--- /dev/null
@@ -0,0 +1,2 @@
+  *) mod_dir: Add "DirectorySlashNotFound" to return 404 instead of a 
+     DirectorySlash redirect. [Eric Covener]
index eed99c595d4ab42ffb904415f4dc2e9666e817df..187d690a1082950f88709b1e595b9060c4abc861 100644 (file)
@@ -230,6 +230,22 @@ a directory</description>
 </usage>
 </directivesynopsis>
 <directivesynopsis>
+<name>DirectorySlashNotFound</name>
+<description>Toggle sending a HTTP 404 error in place of a trailing slash</description>
+<syntax>DirectorySlashNotFound On|Off</syntax>
+<default>DirectorySlashNotFound  Off</default>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context></contextlist>
+<override>Indexes</override>
+<compatibility>Added in 2.5.1</compatibility>
+
+<usage>
+    <p>The <directive>DirectorySlashNotFound</directive> directive determines whether
+    <module>mod_dir</module> should return an HTTP 404 status code where it would 
+    otherwise have redirected the request to include a trailing slash.  </p>
+</usage>
+</directivesynopsis>
+<directivesynopsis>
 <name>FallbackResource</name>
 <description>Define a default URL for requests that don't map to a file</description>
 <syntax>FallbackResource disabled | <var>local-url</var></syntax>
index 3aebd9c0b4b120a3b59887a18ed2066175c9cec0..0bb6a274bbd6638889fb7ebf262e7070661d9e31 100644 (file)
@@ -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).