Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminated for status 101 (like websocket) #276

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ngx_http_modsecurity_body_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return ngx_http_next_body_filter(r, in);
}

if (ctx->modsec_transaction == NULL) {
// we have freed the modsec_transaction
return ngx_http_next_body_filter(r, in);
}

if (ctx->intervention_triggered) {
return ngx_http_next_body_filter(r, in);
}
Expand Down Expand Up @@ -179,6 +184,14 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
dd("buffer was not fully loaded! ctx: %p", ctx);
}

if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
dd("it's switching protocols, clean transaction for %p", ctx);
// I don't think there are any response body
ngx_http_modsecurity_log_handler(r);

ngx_http_modsecurity_cleanup(ctx);
}

/* XXX: xflt_filter() -- return NGX_OK here */
return ngx_http_next_body_filter(r, in);
}
1 change: 1 addition & 0 deletions src/ngx_http_modsecurity_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ ngx_http_modsecurity_ctx_t *ngx_http_modsecurity_create_ctx(ngx_http_request_t *
char *ngx_str_to_char(ngx_str_t a, ngx_pool_t *p);
ngx_pool_t *ngx_http_modsecurity_pcre_malloc_init(ngx_pool_t *pool);
void ngx_http_modsecurity_pcre_malloc_done(ngx_pool_t *old_pool);
void ngx_http_modsecurity_cleanup(void *data);

/* ngx_http_modsecurity_body_filter.c */
ngx_int_t ngx_http_modsecurity_body_filter_init(void);
Expand Down
5 changes: 5 additions & 0 deletions src/ngx_http_modsecurity_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ ngx_http_modsecurity_log_handler(ngx_http_request_t *r)
return NGX_OK;
}

if (!ctx->modsec_transaction) {
// it's already clean and logged in 101
return NGX_OK;
}

dd("calling msc_process_logging for %p", ctx);
old_pool = ngx_http_modsecurity_pcre_malloc_init(r->pool);
msc_process_logging(ctx->modsec_transaction);
Expand Down
5 changes: 5 additions & 0 deletions src/ngx_http_modsecurity_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ ngx_http_modsecurity_cleanup(void *data)

ctx = (ngx_http_modsecurity_ctx_t *) data;

if (!ctx->modsec_transaction) {
// it's already clean in 101
return;
}
msc_transaction_cleanup(ctx->modsec_transaction);
ctx->modsec_transaction = NULL;

#if defined(MODSECURITY_SANITY_CHECKS) && (MODSECURITY_SANITY_CHECKS)
/*
Expand Down