diff --git a/src/mod_alias.c b/src/mod_alias.c index 18569943..eec14f24 100644 --- a/src/mod_alias.c +++ b/src/mod_alias.c @@ -181,6 +181,21 @@ PHYSICALPATH_FUNC(mod_alias_physical_handler) { strncmp(uri_ptr, ds->key->ptr, alias_len))) { /* matched */ + /* check for path traversal in url-path following alias if key + * does not end in slash, but replacement value ends in slash */ + if (uri_ptr[alias_len] == '.') { + char *s = uri_ptr + alias_len + 1; + if (*s == '.') ++s; + if (*s == '/' || *s == '\0') { + size_t vlen = buffer_string_length(ds->value); + if (0 != alias_len && ds->key->ptr[alias_len-1] != '/' + && 0 != vlen && ds->value->ptr[vlen-1] == '/') { + con->http_status = 403; + return HANDLER_FINISHED; + } + } + } + buffer_copy_buffer(con->physical.basedir, ds->value); buffer_copy_buffer(srv->tmp_buf, ds->value); buffer_append_string(srv->tmp_buf, uri_ptr + alias_len);