Skip to content

Commit

Permalink
Security: now "/../" are disabled in "Destination" request header line.
Browse files Browse the repository at this point in the history
Change: now $host variable value is always low case.

Feature: the $ssl_session_id variable.

Bugfix: socket leak; the bug had appeared in 0.8.11.
  • Loading branch information
Igor Sysoev authored and Git Mirror committed Sep 28, 2009
1 parent 15c8b06 commit d566590
Show file tree
Hide file tree
Showing 24 changed files with 258 additions and 147 deletions.
12 changes: 12 additions & 0 deletions CHANGES
@@ -1,4 +1,16 @@

Changes with nginx 0.8.17 28 Sep 2009

*) Security: now "/../" are disabled in "Destination" request header
line.

*) Change: now $host variable value is always low case.

*) Feature: the $ssl_session_id variable.

*) Bugfix: socket leak; the bug had appeared in 0.8.11.


Changes with nginx 0.8.16 22 Sep 2009

*) Feature: the "image_filter_transparency" directive.
Expand Down
12 changes: 12 additions & 0 deletions CHANGES.ru
@@ -1,4 +1,16 @@

Изменения в nginx 0.8.17 28.09.2009

*) Безопасность: теперь символы "/../" запрещены в строке "Destination"
в заголовке запроса.

*) Изменение: теперь значение переменной $host всегда в нижнем регистре.

*) Добавление: переменная $ssl_session_id.

*) Исправление: утечки сокетов; ошибка появилась в 0.8.11.


Изменения в nginx 0.8.16 22.09.2009

*) Добавление: директива image_filter_transparency.
Expand Down
8 changes: 4 additions & 4 deletions auto/lib/openssl/conf
Expand Up @@ -25,10 +25,10 @@ if [ $OPENSSL != NONE ]; then
have=NGX_OPENSSL . auto/have
have=NGX_SSL . auto/have

CORE_INCS="$CORE_INCS $OPENSSL/openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/openssl/lib/libcrypto.a"
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
;;
esac
Expand Down
6 changes: 3 additions & 3 deletions auto/lib/openssl/make
Expand Up @@ -46,13 +46,13 @@ END
esac

case $OPENSSL in
/*) ngx_prefix="$OPENSSL/openssl" ;;
*) ngx_prefix="$PWD/$OPENSSL/openssl" ;;
/*) ngx_prefix="$OPENSSL/.openssl" ;;
*) ngx_prefix="$PWD/$OPENSSL/.openssl" ;;
esac

cat << END >> $NGX_MAKEFILE

$OPENSSL/openssl/include/openssl/ssl.h: $NGX_MAKEFILE
$OPENSSL/.openssl/include/openssl/ssl.h: $NGX_MAKEFILE
cd $OPENSSL \\
&& \$(MAKE) clean \\
&& ./config --prefix=$ngx_prefix no-shared $OPENSSL_OPT \\
Expand Down
4 changes: 2 additions & 2 deletions src/core/nginx.h
Expand Up @@ -8,8 +8,8 @@
#define _NGINX_H_INCLUDED_


#define nginx_version 8016
#define NGINX_VERSION "0.8.16"
#define nginx_version 8017
#define NGINX_VERSION "0.8.17"
#define NGINX_VER "nginx/" NGINX_VERSION

#define NGINX_VAR "NGINX"
Expand Down
6 changes: 1 addition & 5 deletions src/core/ngx_connection.c
Expand Up @@ -917,12 +917,8 @@ ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
level = NGX_LOG_INFO;
break;

case NGX_ERROR_ERR:
level = NGX_LOG_ERR;
break;

default:
level = NGX_LOG_ALERT;
level = NGX_LOG_ERR;
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/core/ngx_open_file_cache.c
Expand Up @@ -525,7 +525,7 @@ ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log)
of->fd = fd;

if (of->directio <= ngx_file_size(&fi)) {
if (ngx_directio_on(fd) == -1) {
if (ngx_directio_on(fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
ngx_directio_on_n " \"%s\" failed", name);

Expand Down
4 changes: 2 additions & 2 deletions src/core/ngx_output_chain.c
Expand Up @@ -514,7 +514,7 @@ ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx)
#if (NGX_HAVE_ALIGNED_DIRECTIO)

if (ctx->unaligned) {
if (ngx_directio_off(src->file->fd) == -1) {
if (ngx_directio_off(src->file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
ngx_directio_off_n " \"%s\" failed",
src->file->name.data);
Expand Down Expand Up @@ -550,7 +550,7 @@ ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx)

err = ngx_errno;

if (ngx_directio_on(src->file->fd) == -1) {
if (ngx_directio_on(src->file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
ngx_directio_on_n " \"%s\" failed",
src->file->name.data);
Expand Down
40 changes: 37 additions & 3 deletions src/event/ngx_event_openssl.c
Expand Up @@ -1588,7 +1588,7 @@ ngx_ssl_new_session(ngx_ssl_conn_t *ssl_conn, ngx_ssl_session_t *sess)
hash = ngx_crc32_short(sess->session_id, sess->session_id_length);

ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
"http ssl new session: %08XD:%d:%d",
"ssl new session: %08XD:%d:%d",
hash, sess->session_id_length, len);

sess_id->node.key = hash;
Expand Down Expand Up @@ -1651,7 +1651,7 @@ ngx_ssl_get_cached_session(ngx_ssl_conn_t *ssl_conn, u_char *id, int len,
*copy = 0;

ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"http ssl get session: %08XD:%d", hash, len);
"ssl get session: %08XD:%d", hash, len);

shm_zone = SSL_CTX_get_ex_data(SSL_get_SSL_CTX(ssl_conn),
ngx_ssl_session_cache_index);
Expand Down Expand Up @@ -1765,7 +1765,7 @@ ngx_ssl_remove_session(SSL_CTX *ssl, ngx_ssl_session_t *sess)
hash = ngx_crc32_short(id, len);

ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
"http ssl remove session: %08XD:%uz", hash, len);
"ssl remove session: %08XD:%uz", hash, len);

shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;

Expand Down Expand Up @@ -1928,6 +1928,40 @@ ngx_ssl_get_cipher_name(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
}


ngx_int_t
ngx_ssl_get_session_id(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
{
int len;
u_char *p, *buf;
SSL_SESSION *sess;

sess = SSL_get0_session(c->ssl->connection);

len = i2d_SSL_SESSION(sess, NULL);

buf = ngx_alloc(len, c->log);
if (buf == NULL) {
return NGX_ERROR;
}

s->len = 2 * len;
s->data = ngx_pnalloc(pool, 2 * len);
if (s->data == NULL) {
ngx_free(buf);
return NGX_ERROR;
}

p = buf;
i2d_SSL_SESSION(sess, &p);

ngx_hex_dump(s->data, buf, len);

ngx_free(buf);

return NGX_OK;
}


ngx_int_t
ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
{
Expand Down
2 changes: 2 additions & 0 deletions src/event/ngx_event_openssl.h
Expand Up @@ -118,6 +118,8 @@ ngx_int_t ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_cipher_name(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_session_id(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_certificate(ngx_connection_t *c, ngx_pool_t *pool,
Expand Down
16 changes: 11 additions & 5 deletions src/http/modules/ngx_http_dav_module.c
Expand Up @@ -516,8 +516,8 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
size_t len, root;
ngx_err_t err;
ngx_int_t rc, depth;
ngx_uint_t overwrite, slash, dir;
ngx_str_t path, uri;
ngx_uint_t overwrite, slash, dir, flags;
ngx_str_t path, uri, duri, args;
ngx_tree_ctx_t tree;
ngx_copy_file_t cf;
ngx_file_info_t fi;
Expand Down Expand Up @@ -594,6 +594,14 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)

destination_done:

duri.len = last - p;
duri.data = p;
flags = 0;

if (ngx_http_parse_unsafe_uri(r, &duri, &args, &flags) != NGX_OK) {
goto invalid_destination;
}

if ((r->uri.data[r->uri.len - 1] == '/' && *(last - 1) != '/')
|| (r->uri.data[r->uri.len - 1] != '/' && *(last - 1) == '/'))
{
Expand Down Expand Up @@ -656,9 +664,7 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
"http copy from: \"%s\"", path.data);

uri = r->uri;

r->uri.len = last - p;
r->uri.data = p;
r->uri = duri;

ngx_http_map_uri_to_path(r, &copy.path, &root, 0);

Expand Down
5 changes: 4 additions & 1 deletion src/http/modules/ngx_http_index_module.c
Expand Up @@ -222,7 +222,10 @@ ngx_http_index_handler(ngx_http_request_t *r)
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

if (of.err == NGX_ENOTDIR || of.err == NGX_EACCES) {
if (of.err == NGX_ENOTDIR
|| of.err == NGX_ENAMETOOLONG
|| of.err == NGX_EACCES)
{
return ngx_http_index_error(r, clcf, path.data, of.err);
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/modules/ngx_http_ssi_filter_module.c
Expand Up @@ -1908,7 +1908,7 @@ ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,

args.len = 0;
args.data = NULL;
flags = 0;
flags = NGX_HTTP_LOG_UNSAFE;

if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) {
return NGX_HTTP_SSI_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/http/modules/ngx_http_ssl_module.c
Expand Up @@ -184,6 +184,9 @@ static ngx_http_variable_t ngx_http_ssl_vars[] = {
{ ngx_string("ssl_cipher"), NULL, ngx_http_ssl_static_variable,
(uintptr_t) ngx_ssl_get_cipher_name, NGX_HTTP_VAR_CHANGEABLE, 0 },

{ ngx_string("ssl_session_id"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_session_id, NGX_HTTP_VAR_CHANGEABLE, 0 },

{ ngx_string("ssl_client_cert"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_certificate, NGX_HTTP_VAR_CHANGEABLE, 0 },

Expand Down
2 changes: 1 addition & 1 deletion src/http/modules/perl/nginx.pm
Expand Up @@ -47,7 +47,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);

our $VERSION = '0.8.16';
our $VERSION = '0.8.17';

require XSLoader;
XSLoader::load('nginx', $VERSION);
Expand Down
6 changes: 4 additions & 2 deletions src/http/ngx_http_core_module.c
Expand Up @@ -994,7 +994,6 @@ ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
"rewrite or internal redirection cycle "
"while processing \"%V\"", &r->uri);

r->main->count++;
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_OK;
}
Expand Down Expand Up @@ -1233,7 +1232,10 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
!= NGX_OK)
{
if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
if (of.err != NGX_ENOENT
&& of.err != NGX_ENOTDIR
&& of.err != NGX_ENAMETOOLONG)
{
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
"%s \"%s\" failed", of.failed, path.data);
}
Expand Down
6 changes: 4 additions & 2 deletions src/http/ngx_http_parse.c
Expand Up @@ -1322,8 +1322,10 @@ ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,

unsafe:

ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"unsafe URI \"%V\" was detected", uri);
if (*flags & NGX_HTTP_LOG_UNSAFE) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"unsafe URI \"%V\" was detected", uri);
}

return NGX_ERROR;
}
Expand Down

0 comments on commit d566590

Please sign in to comment.