[2422] | 1 | From 0c2aac95f8df4e7c243ea00d54d4050e32f7868b Mon Sep 17 00:00:00 2001 |
---|
| 2 | From: Alexander Chernyakhovsky <achernya@mit.edu> |
---|
| 3 | Date: Fri, 3 May 2013 21:39:17 -0400 |
---|
| 4 | Subject: [PATCH 2/4] Prevent mod_status from taking effect in .htaccess files |
---|
| 5 | |
---|
| 6 | Introduce a directive to the Apache configuration that is only |
---|
| 7 | permitted in a directory context, called "PermitStatusHandler", to |
---|
| 8 | prevent users from enabling mod_status from their .htaccess files. |
---|
| 9 | |
---|
| 10 | Signed-off-by: Quentin Smith <quentin@mit.edu> |
---|
| 11 | Signed-off-by: Geoffrey Thomas <geofft@mit.edu> |
---|
| 12 | --- |
---|
| 13 | modules/generators/mod_status.c | 60 +++++++++++++++++++++++++++++++++++++-- |
---|
| 14 | 1 file changed, 57 insertions(+), 3 deletions(-) |
---|
| 15 | |
---|
| 16 | diff --git a/modules/generators/mod_status.c b/modules/generators/mod_status.c |
---|
| 17 | index 0237f1d..c7fd0e0 100644 |
---|
| 18 | --- a/modules/generators/mod_status.c |
---|
| 19 | +++ b/modules/generators/mod_status.c |
---|
| 20 | @@ -103,6 +103,56 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap, STATUS, int, status_hook, |
---|
| 21 | static pid_t child_pid; |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | +typedef struct { |
---|
| 25 | + int permit_status_handler; |
---|
| 26 | +} status_config_rec; |
---|
| 27 | + |
---|
| 28 | +/* |
---|
| 29 | + * command-related code. This is here to prevent use of ExtendedStatus |
---|
| 30 | + * without status_module included. |
---|
| 31 | + */ |
---|
| 32 | +static const char *set_extended_status(cmd_parms *cmd, void *dummy, int arg) |
---|
| 33 | +{ |
---|
| 34 | + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
---|
| 35 | + if (err != NULL) { |
---|
| 36 | + return err; |
---|
| 37 | + } |
---|
| 38 | + ap_extended_status = arg; |
---|
| 39 | + return NULL; |
---|
| 40 | +} |
---|
| 41 | + |
---|
| 42 | +static const char *set_reqtail(cmd_parms *cmd, void *dummy, int arg) |
---|
| 43 | +{ |
---|
| 44 | + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); |
---|
| 45 | + if (err != NULL) { |
---|
| 46 | + return err; |
---|
| 47 | + } |
---|
| 48 | + ap_mod_status_reqtail = arg; |
---|
| 49 | + return NULL; |
---|
| 50 | +} |
---|
| 51 | + |
---|
| 52 | +static void *create_status_dir_config(apr_pool_t *p, char *d) |
---|
| 53 | +{ |
---|
| 54 | + status_config_rec *conf = apr_pcalloc(p, sizeof(*conf)); |
---|
| 55 | + conf->permit_status_handler = 0; |
---|
| 56 | + return conf; |
---|
| 57 | +} |
---|
| 58 | + |
---|
| 59 | +static const command_rec status_module_cmds[] = |
---|
| 60 | +{ |
---|
| 61 | + AP_INIT_FLAG("ExtendedStatus", set_extended_status, NULL, RSRC_CONF, |
---|
| 62 | + "\"On\" to enable extended status information, \"Off\" to disable"), |
---|
| 63 | + AP_INIT_FLAG("SeeRequestTail", set_reqtail, NULL, RSRC_CONF, |
---|
| 64 | + "For verbose requests, \"On\" to see the last 63 chars of the request, " |
---|
| 65 | + "\"Off\" (default) to see the first 63 in extended status display"), |
---|
| 66 | + AP_INIT_FLAG("PermitStatusHandler", ap_set_flag_slot, |
---|
| 67 | + (void *)APR_OFFSETOF(status_config_rec, permit_status_handler), |
---|
| 68 | + ACCESS_CONF, |
---|
| 69 | + "As a security measure, only permit status handlers where this flag " |
---|
| 70 | + "is set. Only legal in directory context, not .htaccess."), |
---|
| 71 | + {NULL} |
---|
| 72 | +}; |
---|
| 73 | + |
---|
| 74 | /* Format the number of bytes nicely */ |
---|
| 75 | static void format_byte_out(request_rec *r, apr_off_t bytes) |
---|
| 76 | { |
---|
| 77 | @@ -207,8 +257,12 @@ static int status_handler(request_rec *r) |
---|
| 78 | int times_per_thread; |
---|
| 79 | #endif |
---|
| 80 | |
---|
| 81 | - if (strcmp(r->handler, STATUS_MAGIC_TYPE) && strcmp(r->handler, |
---|
| 82 | - "server-status")) { |
---|
| 83 | + status_config_rec *conf = ap_get_module_config(r->per_dir_config, |
---|
| 84 | + &status_module); |
---|
| 85 | + |
---|
| 86 | + if ((strcmp(r->handler, STATUS_MAGIC_TYPE) && |
---|
| 87 | + strcmp(r->handler, "server-status")) || |
---|
| 88 | + !conf->permit_status_handler) { |
---|
| 89 | return DECLINED; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | @@ -974,7 +1028,7 @@ static void register_hooks(apr_pool_t *p) |
---|
| 93 | AP_DECLARE_MODULE(status) = |
---|
| 94 | { |
---|
| 95 | STANDARD20_MODULE_STUFF, |
---|
| 96 | - NULL, /* dir config creater */ |
---|
| 97 | + create_status_dir_config, /* dir config creater */ |
---|
| 98 | NULL, /* dir merger --- default is to override */ |
---|
| 99 | NULL, /* server config */ |
---|
| 100 | NULL, /* merge server config */ |
---|
| 101 | -- |
---|
| 102 | 1.7.9.6 (Apple Git-31.1) |
---|
| 103 | |
---|