Skip to content

Commit

Permalink
http: improve buffer reuse for heeaders, and discard unused bodies
Browse files Browse the repository at this point in the history
The body content not being consumed was leading to misparses, where
we consumed body data as if it were a request. When mixed with proxies
this could lead to a security problem where the following request
content submitted from a different client winds up as stolen request
body content.

This also ensures we actually deliver errors to clients without
prematurely closing the connection.  (There are still problems
where the connection may be closed prematurely for an overlarge
header.)
  • Loading branch information
gdamore committed Jan 11, 2025
1 parent 588611e commit b16e6eb
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 215 deletions.
5 changes: 1 addition & 4 deletions src/supplemental/http/http_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ typedef struct nng_http_chunks nni_http_chunks;

extern void nni_http_req_init(nni_http_req *);
extern void nni_http_req_reset(nni_http_req *);
extern int nni_http_req_get_buf(nni_http_req *, void **, size_t *);
extern int nni_http_req_parse(nng_http *, void *, size_t, size_t *);

extern void nni_http_res_init(nni_http_res *);
extern void nni_http_res_reset(nni_http_res *);
extern int nni_http_res_get_buf(nni_http_conn *, void **, size_t *);
extern int nni_http_res_parse(nng_http *, void *, size_t, size_t *);

// Chunked transfer encoding. For the moment this is not part of our public
Expand Down Expand Up @@ -115,10 +113,9 @@ extern void nni_http_write_req(nni_http_conn *, nni_aio *);
extern void nni_http_read_res(nni_http_conn *, nni_aio *);
extern void nni_http_read_req(nni_http_conn *, nni_aio *);
extern void nni_http_write_res(nni_http_conn *, nni_aio *);
extern void nni_http_read_discard(nni_http_conn *, size_t, nni_aio *);

extern int nni_http_req_add_header(nni_http_req *, const char *, const char *);
extern int nni_http_req_del_header(nni_http_req *, const char *);
extern int nni_http_res_del_header(nni_http_res *, const char *);
extern int nni_http_req_alloc_data(nni_http_req *, size_t);
extern int nni_http_res_alloc_data(nni_http_res *, size_t);

Expand Down
2 changes: 0 additions & 2 deletions src/supplemental/http/http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ typedef struct http_txn {
nni_list aios; // upper level aio(s) -- maximum one
nni_http_client *client;
nni_http_conn *conn;
nni_http_req *req;
nni_http_res *res;
nni_http_chunks *chunks;
http_txn_state state;
Expand Down Expand Up @@ -398,7 +397,6 @@ nni_http_transact_conn(nni_http_conn *conn, nni_aio *aio)
nni_aio_list_init(&txn->aios);
txn->client = NULL;
txn->conn = conn;
txn->req = nni_http_conn_req(conn);
txn->res = nni_http_conn_res(conn);
txn->state = HTTP_SENDING;

Expand Down
Loading

0 comments on commit b16e6eb

Please sign in to comment.