From: Eric Covener Date: Fri, 22 Oct 2021 00:12:40 +0000 (+0000) Subject: followup to r1894456: use a DirectorySlash argument instead X-Git-Tag: 2.5.0-alpha2-ci-test-only~724 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98595201df31587375af9bb9486d6d9c3010f99f;p=thirdparty%2Fapache%2Fhttpd.git followup to r1894456: use a DirectorySlash argument instead git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1894460 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/changes-entries/DirectorySlashNotFound.txt b/changes-entries/DirectorySlashNotFound.txt index 4f672644061..87a8c7ee265 100644 --- a/changes-entries/DirectorySlashNotFound.txt +++ b/changes-entries/DirectorySlashNotFound.txt @@ -1,2 +1,2 @@ - *) mod_dir: Add "DirectorySlashNotFound" to return 404 instead of a - DirectorySlash redirect. [Eric Covener] + *) mod_dir: Add "NotFound" option to "DirectorySlash" directive 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 187d690a108..218d9f99eda 100644 --- a/docs/manual/mod/mod_dir.xml +++ b/docs/manual/mod/mod_dir.xml @@ -178,19 +178,20 @@ a directory DirectorySlash Toggle trailing slash redirects on or off -DirectorySlash On|Off +DirectorySlash On|Off|NotFound DirectorySlash On server configvirtual host directory.htaccess Indexes +Argument NotFound added in 2.5.1 -

The DirectorySlash directive determines whether +

The DirectorySlash directive determines how mod_dir should fixup URLs pointing to a directory or not.

Typically if a user requests a resource without a trailing slash, which - points to a directory, mod_dir redirects him to the same + points to a directory, mod_dir redirects them to the same resource, but with trailing slash for some good reasons:

    @@ -227,22 +228,12 @@ a directory

    Also note that some browsers may erroneously change POST requests into GET (thus discarding POST data) when a redirect is issued.

    - - - -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.

    +

    To avoid the risks of the "off" behavior above, or to avoid disclosing + that a directory is present via the behavior of "on", an argument of + "NotFound" can be used to tell mod_dir to return an HTTP + 404 status code redirected the request to include a trailing slash.

    +
    diff --git a/modules/mappers/mod_dir.c b/modules/mappers/mod_dir.c index 0bb6a274bbd..d13babf8185 100644 --- a/modules/mappers/mod_dir.c +++ b/modules/mappers/mod_dir.c @@ -39,16 +39,23 @@ typedef enum { MODDIR_UNSET } moddir_cfg; +typedef enum { + SLASH_OFF = 0, + SLASH_ON, + SLASH_NOTFOUND, + SLASH_UNSET +} moddir_doslash; + + #define REDIRECT_OFF 0 #define REDIRECT_UNSET 1 typedef struct dir_config_struct { apr_array_header_t *index_names; - moddir_cfg do_slash; + moddir_doslash do_slash; moddir_cfg checkhandler; int redirect_index; const char *dflt; - moddir_cfg do_slash_notfound; } dir_config_rec; #define DIR_CMD_PERMS OR_INDEXES @@ -82,18 +89,22 @@ static const char *add_index(cmd_parms *cmd, void *dummy, const char *arg) return NULL; } -static const char *configure_slash(cmd_parms *cmd, void *d_, int arg) -{ - dir_config_rec *d = d_; - - d->do_slash = arg ? MODDIR_ON : MODDIR_OFF; - return NULL; -} -static const char *configure_slash_notfound(cmd_parms *cmd, void *d_, int arg) +static const char *configure_slash(cmd_parms *cmd, void *d_, const char *arg1) { dir_config_rec *d = d_; - d->do_slash_notfound = arg ? MODDIR_ON : MODDIR_OFF; + if (!ap_cstr_casecmp(arg1, "on")) { + d->do_slash = SLASH_ON; + } + else if (!ap_cstr_casecmp(arg1, "off")) { + d->do_slash = SLASH_OFF; + } + else if (!ap_cstr_casecmp(arg1, "NotFound")) { + d->do_slash = SLASH_NOTFOUND; + } + else { + return "DirectorySlash only accepts ON, OFF, or 'NotFound'"; + } return NULL; } static const char *configure_checkhandler(cmd_parms *cmd, void *d_, int arg) @@ -138,9 +149,7 @@ static const command_rec dir_cmds[] = DIR_CMD_PERMS, "Set a default handler"), AP_INIT_RAW_ARGS("DirectoryIndex", add_index, NULL, DIR_CMD_PERMS, "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, + AP_INIT_TAKE1("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS, "On or Off"), AP_INIT_FLAG("DirectoryCheckHandler", configure_checkhandler, NULL, DIR_CMD_PERMS, "On or Off"), @@ -155,8 +164,7 @@ static void *create_dir_config(apr_pool_t *p, char *dummy) dir_config_rec *new = apr_pcalloc(p, sizeof(dir_config_rec)); new->index_names = NULL; - new->do_slash = MODDIR_UNSET; - new->do_slash_notfound = MODDIR_UNSET; + new->do_slash = SLASH_UNSET; new->checkhandler = MODDIR_UNSET; new->redirect_index = REDIRECT_UNSET; return (void *) new; @@ -170,9 +178,7 @@ 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; + (add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash; new->checkhandler = (add->checkhandler == MODDIR_UNSET) ? base->checkhandler : add->checkhandler; new->redirect_index= @@ -260,14 +266,14 @@ static int fixup_dir(request_rec *r) { char *ifile; - if (!d->do_slash) { + if (d->do_slash == SLASH_OFF) { return DECLINED; } - - if (d->do_slash_notfound == MODDIR_ON) { + if (d->do_slash == SLASH_NOTFOUND) { 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).